fix
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package collector implements an OpenTelemetry consumer that stores telemetry in history
|
||||
// and broadcasts it to connected clients.
|
||||
package collector
|
||||
|
||||
import (
|
||||
@@ -16,6 +18,7 @@ import (
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
|
||||
// HandleTraces handles OTLP trace requests.
|
||||
func (c *Collector) HandleTraces(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received traces request: method=%s, content-type=%s", r.Method, r.Header.Get("Content-Type"))
|
||||
if r.Method != http.MethodPost {
|
||||
@@ -61,6 +64,7 @@ func (c *Collector) HandleTraces(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
// HandleMetrics handles OTLP metric requests.
|
||||
func (c *Collector) HandleMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -101,6 +105,7 @@ func (c *Collector) HandleMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
// HandleLogs handles OTLP log requests.
|
||||
func (c *Collector) HandleLogs(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -141,6 +146,7 @@ func (c *Collector) HandleLogs(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
// HandleHistory returns the telemetry history as JSON.
|
||||
func (c *Collector) HandleHistory(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -165,6 +171,7 @@ func (c *Collector) HandleHistory(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleSearch searches the telemetry history.
|
||||
func (c *Collector) HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -195,6 +202,7 @@ func (c *Collector) HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleWait waits for a specific telemetry signal.
|
||||
func (c *Collector) HandleWait(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -216,7 +224,9 @@ func (c *Collector) HandleWait(w http.ResponseWriter, r *http.Request) {
|
||||
matches, err := c.SearchHistory(ctx, query, 1)
|
||||
if err == nil && len(matches) > 0 {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(matches[0])
|
||||
if err := json.NewEncoder(w).Encode(matches[0]); err != nil {
|
||||
log.Printf("failed to encode match: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -242,6 +252,7 @@ func (c *Collector) HandleWait(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleHistoryByType returns telemetry history filtered by type.
|
||||
func (c *Collector) HandleHistoryByType(dataType string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
@@ -283,8 +294,11 @@ func (c *Collector) HandleHistoryByType(dataType string) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleHealth returns the health status of the collector.
|
||||
func (c *Collector) HandleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
||||
if err := json.NewEncoder(w).Encode(map[string]string{"status": "ok"}); err != nil {
|
||||
log.Printf("failed to encode health check: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user