From aae9c45b4ab85470f21c79e269cf4b76e45c54e7 Mon Sep 17 00:00:00 2001 From: hendoxc Date: Mon, 23 Dec 2024 10:42:27 -0700 Subject: [PATCH] INFOPLAT-1562 Reconfigure loop configs to use AuthHeaderProvider --- pkg/loop/config.go | 13 ++----------- pkg/loop/config_test.go | 12 ------------ pkg/loop/server.go | 3 +-- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/pkg/loop/config.go b/pkg/loop/config.go index ea68cfa4a..88b1c3cdc 100644 --- a/pkg/loop/config.go +++ b/pkg/loop/config.go @@ -9,6 +9,7 @@ import ( "time" "github.com/hashicorp/go-plugin" + "github.com/smartcontractkit/chainlink-common/pkg/beholder" ) const ( @@ -27,8 +28,6 @@ const ( envTelemetryCACertFile = "CL_TELEMETRY_CA_CERT_FILE" envTelemetryAttribute = "CL_TELEMETRY_ATTRIBUTE_" envTelemetryTraceSampleRatio = "CL_TELEMETRY_TRACE_SAMPLE_RATIO" - envTelemetryAuthHeader = "CL_TELEMETRY_AUTH_HEADER" - envTelemetryAuthPubKeyHex = "CL_TELEMETRY_AUTH_PUB_KEY_HEX" envTelemetryEmitterBatchProcessor = "CL_TELEMETRY_EMITTER_BATCH_PROCESSOR" envTelemetryEmitterExportTimeout = "CL_TELEMETRY_EMITTER_EXPORT_TIMEOUT" envTelemetryEmitterExportInterval = "CL_TELEMETRY_EMITTER_EXPORT_INTERVAL" @@ -55,8 +54,7 @@ type EnvConfig struct { TelemetryCACertFile string TelemetryAttributes OtelAttributes TelemetryTraceSampleRatio float64 - TelemetryAuthHeaders map[string]string - TelemetryAuthPubKeyHex string + TelemetryAuthHeaderProvider beholder.AuthHeaderProvider TelemetryEmitterBatchProcessor bool TelemetryEmitterExportTimeout time.Duration TelemetryEmitterExportInterval time.Duration @@ -92,11 +90,6 @@ func (e *EnvConfig) AsCmdEnv() (env []string) { for k, v := range e.TelemetryAttributes { add(envTelemetryAttribute+k, v) } - - for k, v := range e.TelemetryAuthHeaders { - add(envTelemetryAuthHeader+k, v) - } - add(envTelemetryAuthPubKeyHex, e.TelemetryAuthPubKeyHex) add(envTelemetryEmitterBatchProcessor, strconv.FormatBool(e.TelemetryEmitterBatchProcessor)) add(envTelemetryEmitterExportTimeout, e.TelemetryEmitterExportTimeout.String()) add(envTelemetryEmitterExportInterval, e.TelemetryEmitterExportInterval.String()) @@ -148,8 +141,6 @@ func (e *EnvConfig) parse() error { e.TelemetryCACertFile = os.Getenv(envTelemetryCACertFile) e.TelemetryAttributes = getMap(envTelemetryAttribute) e.TelemetryTraceSampleRatio = getFloat64OrZero(envTelemetryTraceSampleRatio) - e.TelemetryAuthHeaders = getMap(envTelemetryAuthHeader) - e.TelemetryAuthPubKeyHex = os.Getenv(envTelemetryAuthPubKeyHex) e.TelemetryEmitterBatchProcessor, err = getBool(envTelemetryEmitterBatchProcessor) if err != nil { return fmt.Errorf("failed to parse %s: %w", envTelemetryEmitterBatchProcessor, err) diff --git a/pkg/loop/config_test.go b/pkg/loop/config_test.go index f57eff666..623307dfa 100644 --- a/pkg/loop/config_test.go +++ b/pkg/loop/config_test.go @@ -59,8 +59,6 @@ func TestEnvConfig_parse(t *testing.T) { envTelemetryAttribute + "foo": "bar", envTelemetryAttribute + "baz": "42", envTelemetryTraceSampleRatio: "0.42", - envTelemetryAuthHeader + "header-key": "header-value", - envTelemetryAuthPubKeyHex: "pub-key-hex", envTelemetryEmitterBatchProcessor: "true", envTelemetryEmitterExportTimeout: "1s", envTelemetryEmitterExportInterval: "2s", @@ -165,12 +163,6 @@ func TestEnvConfig_parse(t *testing.T) { if config.TelemetryTraceSampleRatio != tc.expectedTelemetryTraceSampleRatio { t.Errorf("Expected telemetryTraceSampleRatio %f, got %f", tc.expectedTelemetryTraceSampleRatio, config.TelemetryTraceSampleRatio) } - if !maps.Equal(config.TelemetryAuthHeaders, tc.expectedTelemetryAuthHeaders) { - t.Errorf("Expected telemetryAuthHeaders %v, got %v", tc.expectedTelemetryAuthHeaders, config.TelemetryAuthHeaders) - } - if config.TelemetryAuthPubKeyHex != tc.expectedTelemetryAuthPubKeyHex { - t.Errorf("Expected telemetryAuthPubKeyHex %s, got %s", tc.expectedTelemetryAuthPubKeyHex, config.TelemetryAuthPubKeyHex) - } if config.TelemetryEmitterBatchProcessor != tc.expectedTelemetryEmitterBatchProcessor { t.Errorf("Expected telemetryEmitterBatchProcessor %v, got %v", tc.expectedTelemetryEmitterBatchProcessor, config.TelemetryEmitterBatchProcessor) } @@ -233,8 +225,6 @@ func TestEnvConfig_AsCmdEnv(t *testing.T) { TelemetryCACertFile: "foo/bar", TelemetryAttributes: OtelAttributes{"foo": "bar", "baz": "42"}, TelemetryTraceSampleRatio: 0.42, - TelemetryAuthHeaders: map[string]string{"header-key": "header-value"}, - TelemetryAuthPubKeyHex: "pub-key-hex", TelemetryEmitterBatchProcessor: true, TelemetryEmitterExportTimeout: 1 * time.Second, TelemetryEmitterExportInterval: 2 * time.Second, @@ -264,8 +254,6 @@ func TestEnvConfig_AsCmdEnv(t *testing.T) { assert.Equal(t, "0.42", got[envTelemetryTraceSampleRatio]) assert.Equal(t, "bar", got[envTelemetryAttribute+"foo"]) assert.Equal(t, "42", got[envTelemetryAttribute+"baz"]) - assert.Equal(t, "header-value", got[envTelemetryAuthHeader+"header-key"]) - assert.Equal(t, "pub-key-hex", got[envTelemetryAuthPubKeyHex]) assert.Equal(t, "true", got[envTelemetryEmitterBatchProcessor]) assert.Equal(t, "1s", got[envTelemetryEmitterExportTimeout]) assert.Equal(t, "2s", got[envTelemetryEmitterExportInterval]) diff --git a/pkg/loop/server.go b/pkg/loop/server.go index 6cf4f0c5b..4efbd1ec8 100644 --- a/pkg/loop/server.go +++ b/pkg/loop/server.go @@ -96,9 +96,8 @@ func (s *Server) start() error { CACertFile: envCfg.TelemetryCACertFile, OtelExporterGRPCEndpoint: envCfg.TelemetryEndpoint, ResourceAttributes: append(attributes, envCfg.TelemetryAttributes.AsStringAttributes()...), + AuthHeaderProvider: envCfg.TelemetryAuthHeaderProvider, TraceSampleRatio: envCfg.TelemetryTraceSampleRatio, - AuthHeaders: envCfg.TelemetryAuthHeaders, - AuthPublicKeyHex: envCfg.TelemetryAuthPubKeyHex, EmitterBatchProcessor: envCfg.TelemetryEmitterBatchProcessor, EmitterExportTimeout: envCfg.TelemetryEmitterExportTimeout, EmitterExportInterval: envCfg.TelemetryEmitterExportInterval,