From 0fd17e4944453cf60d93a59e2f9046c5ddc72fa8 Mon Sep 17 00:00:00 2001 From: matst80 Date: Fri, 3 Apr 2026 18:12:40 +0200 Subject: [PATCH] before refactor --- cmd/server/main.go | 59 ++++++++++++++++++++++++++------------------- k8s/deployment.yaml | 2 ++ k8s/service.yaml | 4 +++ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 5855a4c..aeb344d 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -179,37 +179,46 @@ func main() { } }() - // OTLP HTTP endpoints - http.HandleFunc("/v1/traces", handleTraces(coll)) - http.HandleFunc("/v1/metrics", handleMetrics(coll)) - http.HandleFunc("/v1/logs", handleLogs(coll)) + // OTLP HTTP mux (standard OTel port 4318) + otelMux := http.NewServeMux() + otelMux.HandleFunc("/v1/traces", handleTraces(coll)) + otelMux.HandleFunc("/v1/metrics", handleMetrics(coll)) + otelMux.HandleFunc("/v1/logs", handleLogs(coll)) - // History API endpoints - http.HandleFunc("/api/history", handleHistory(coll)) - http.HandleFunc("/api/history/traces", handleHistoryByType(coll, "traces")) - http.HandleFunc("/api/history/metrics", handleHistoryByType(coll, "metrics")) - http.HandleFunc("/api/history/logs", handleHistoryByType(coll, "logs")) - http.HandleFunc("/api/history/search", handleSearch(coll)) - http.HandleFunc("/api/history/wait", handleWait(coll)) + // UI and API mux (port 8080) + uiMux := http.NewServeMux() + // Also register OTLP endpoints on 8080 for backwards compatibility + uiMux.HandleFunc("/v1/traces", handleTraces(coll)) + uiMux.HandleFunc("/v1/metrics", handleMetrics(coll)) + uiMux.HandleFunc("/v1/logs", handleLogs(coll)) - // WebSocket server for visualization - http.HandleFunc("/ws", wsServer.HandleConnections) + uiMux.HandleFunc("/api/history", handleHistory(coll)) + uiMux.HandleFunc("/api/history/traces", handleHistoryByType(coll, "traces")) + uiMux.HandleFunc("/api/history/metrics", handleHistoryByType(coll, "metrics")) + uiMux.HandleFunc("/api/history/logs", handleHistoryByType(coll, "logs")) + uiMux.HandleFunc("/api/history/search", handleSearch(coll)) + uiMux.HandleFunc("/api/history/wait", handleWait(coll)) + uiMux.HandleFunc("/ws", wsServer.HandleConnections) + uiMux.Handle("/", spaHandler(http.Dir("./dist"))) - // Serve static files with SPA fallback - http.Handle("/", spaHandler(http.Dir("./dist"))) - - log.Printf("Starting HTTP server on port 8080") - log.Printf("OTLP HTTP endpoints:") - log.Printf(" Traces: http://localhost:8080/v1/traces") + log.Printf("Starting HTTP server on port 8080 (UI/API)") + log.Printf("OTLP HTTP endpoints (also on port 8080):") + log.Printf(" Traces: http://localhost:8080/v1/traces") log.Printf(" Metrics: http://localhost:8080/v1/metrics") - log.Printf(" Logs: http://localhost:8080/v1/logs") - log.Printf("OTLP gRPC endpoints:") - log.Printf(" Traces: localhost:4317") - log.Printf(" Metrics: localhost:4317") - log.Printf(" Logs: localhost:4317") + log.Printf(" Logs: http://localhost:8080/v1/logs") + log.Printf("OTLP gRPC endpoint:") + log.Printf(" Traces/Metrics/Logs: localhost:4317") log.Printf("WebSocket: ws://localhost:8080/ws") - if err := http.ListenAndServe(":8080", nil); err != nil { + // Start OTLP HTTP server on port 4318 + go func() { + log.Printf("Starting OTLP HTTP server on port 4318") + if err := http.ListenAndServe(":4318", otelMux); err != nil { + log.Printf("failed to start OTLP HTTP server: %v", err) + } + }() + + if err := http.ListenAndServe(":8080", uiMux); err != nil { log.Fatalf("failed to start HTTP server: %v", err) } } diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index f708bae..8c08c8b 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -20,6 +20,8 @@ spec: name: http - containerPort: 4317 name: grpc + - containerPort: 4318 + name: otlp-http env: - name: GRPC_GO_LOG_SEVERITY_LEVEL value: "info" diff --git a/k8s/service.yaml b/k8s/service.yaml index a9ad91f..bc9bd58 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -14,4 +14,8 @@ spec: port: 4317 targetPort: 4317 protocol: TCP + - name: otlp-http + port: 4318 + targetPort: 4318 + protocol: TCP type: ClusterIP \ No newline at end of file