Skip to content

Commit

Permalink
INFOPLAT-1562 Reconfigure loop configs to use AuthHeaderProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
hendoxc committed Dec 23, 2024
1 parent 5803b51 commit aae9c45
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
13 changes: 2 additions & 11 deletions pkg/loop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/hashicorp/go-plugin"
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
)

const (
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions pkg/loop/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down
3 changes: 1 addition & 2 deletions pkg/loop/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aae9c45

Please sign in to comment.