From d9078cd029363080aaf02b2739b77792e283b9f0 Mon Sep 17 00:00:00 2001 From: Mario Macias Date: Thu, 16 Nov 2023 15:40:24 +0100 Subject: [PATCH 1/2] Fix Basic auth key encoding --- pkg/internal/export/otel/grafana.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pkg/internal/export/otel/grafana.go b/pkg/internal/export/otel/grafana.go index 5038a4782..4bb03f588 100644 --- a/pkg/internal/export/otel/grafana.go +++ b/pkg/internal/export/otel/grafana.go @@ -1,7 +1,6 @@ package otel import ( - "bytes" "encoding/base64" "fmt" "log/slog" @@ -80,16 +79,7 @@ func (cfg *GrafanaOTLP) Endpoint() string { } func (cfg *GrafanaOTLP) AuthHeader() string { - encodedKey := bytes.Buffer{} - encodedKey.WriteString("Basic ") - encoder := base64.NewEncoder(base64.StdEncoding, &encodedKey) - _, err := encoder.Write([]byte(cfg.InstanceID + ":" + cfg.APIKey)) - if err != nil { - // This should never happen, as the bytes.Buffer reader will never return error on Write - gclog().Error("can't encode Grafana OTLP Authorization header. Leaving empty", "error", err) - return "" - } - return encodedKey.String() + return "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.InstanceID+":"+cfg.APIKey)) } func (cfg *GrafanaOTLP) setupOptions(opt *otlpOptions) { From 39da7d5bbfc956d25e8af1dbe36d88d0e7fc4c23 Mon Sep 17 00:00:00 2001 From: Mario Macias Date: Thu, 16 Nov 2023 15:51:01 +0100 Subject: [PATCH 2/2] Fix linting --- pkg/internal/export/otel/grafana.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/internal/export/otel/grafana.go b/pkg/internal/export/otel/grafana.go index 4bb03f588..9d4e600ad 100644 --- a/pkg/internal/export/otel/grafana.go +++ b/pkg/internal/export/otel/grafana.go @@ -3,14 +3,9 @@ package otel import ( "encoding/base64" "fmt" - "log/slog" "strings" ) -func gclog() *slog.Logger { - return slog.With("component", "otel.GrafanaConfig") -} - const ( submitMetrics = "metrics" submitTraces = "traces"