Skip to content

Commit

Permalink
Add unit test for fallbackstrategy feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
lhp-nemlig committed Nov 22, 2024
1 parent a5b8dca commit d6435e3
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions internal/manifests/targetallocator/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,63 @@ prometheus_cr:
assert.Equal(t, expectedLabels, actual.Labels)
assert.Equal(t, expectedData, actual.Data)
})

t.Run("should return expected target allocator config map allocation fallback strategy", func(t *testing.T) {
expectedLabels["app.kubernetes.io/component"] = "opentelemetry-targetallocator"
expectedLabels["app.kubernetes.io/name"] = "my-instance-targetallocator"

cfg := config.New(config.WithCertManagerAvailability(certmanager.Available))

flgs := featuregate.Flags(colfg.GlobalRegistry())
err := flgs.Parse([]string{"--feature-gates=operator.targetallocator.fallbackstrategy"})
require.NoError(t, err)

testParams := Params{
Collector: collector,
TargetAllocator: targetAllocator,
Config: cfg,
}

expectedData := map[string]string{
targetAllocatorFilename: `allocation_fallback_strategy: consistent-hashing
allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: default.my-instance
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
matchexpressions: []
config:
scrape_configs:
- job_name: otel-collector
scrape_interval: 10s
static_configs:
- targets:
- 0.0.0.0:8888
- 0.0.0.0:9999
filter_strategy: relabel-config
https:
ca_file_path: /tls/ca.crt
enabled: true
listen_addr: :8443
tls_cert_file_path: /tls/tls.crt
tls_key_file_path: /tls/tls.key
prometheus_cr:
enabled: true
pod_monitor_selector: null
scrape_interval: 30s
service_monitor_selector: null
`,
}

actual, err := ConfigMap(testParams)
assert.NoError(t, err)

assert.Equal(t, "my-instance-targetallocator", actual.Name)
assert.Equal(t, expectedLabels, actual.Labels)
assert.Equal(t, expectedData, actual.Data)
})
}

func TestGetScrapeConfigsFromOtelConfig(t *testing.T) {
Expand Down

0 comments on commit d6435e3

Please sign in to comment.