diff --git a/.chloggen/promote-rewrite-featuregate.yaml b/.chloggen/promote-rewrite-featuregate.yaml new file mode 100755 index 0000000000..de8462d35e --- /dev/null +++ b/.chloggen/promote-rewrite-featuregate.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: target allocator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Promote `operator.collector.rewritetargetallocator` feature flag to stable + +# One or more tracking issues related to the change +issues: [2796] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/internal/manifests/collector/config_replace_test.go b/internal/manifests/collector/config_replace_test.go index 8f31af3107..2a97f8a008 100644 --- a/internal/manifests/collector/config_replace_test.go +++ b/internal/manifests/collector/config_replace_test.go @@ -18,57 +18,17 @@ import ( "os" "testing" - "github.com/prometheus/prometheus/discovery/http" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - colfeaturegate "go.opentelemetry.io/collector/featuregate" "gopkg.in/yaml.v2" ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters" - "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) func TestPrometheusParser(t *testing.T) { param, err := newParams("test/test-img", "testdata/http_sd_config_test.yaml") assert.NoError(t, err) - t.Run("should update config with http_sd_config", func(t *testing.T) { - err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false) - require.NoError(t, err) - t.Cleanup(func() { - _ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true) - }) - actualConfig, err := ReplaceConfig(param.OtelCol) - assert.NoError(t, err) - - // prepare - var cfg Config - promCfgMap, err := ta.ConfigToPromConfig(actualConfig) - assert.NoError(t, err) - - promCfg, err := yaml.Marshal(promCfgMap) - assert.NoError(t, err) - - err = yaml.UnmarshalStrict(promCfg, &cfg) - assert.NoError(t, err) - - // test - expectedMap := map[string]bool{ - "prometheus": false, - "service-x": false, - } - for _, scrapeConfig := range cfg.PromConfig.ScrapeConfigs { - assert.Len(t, scrapeConfig.ServiceDiscoveryConfigs, 1) - assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].Name(), "http") - assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].(*http.SDConfig).URL, "http://test-targetallocator:80/jobs/"+scrapeConfig.JobName+"/targets?collector_id=$POD_NAME") - expectedMap[scrapeConfig.JobName] = true - } - for k := range expectedMap { - assert.True(t, expectedMap[k], k) - } - assert.True(t, cfg.TargetAllocConfig == nil) - }) - t.Run("should update config with targetAllocator block if block not present", func(t *testing.T) { // Set up the test scenario param.OtelCol.Spec.TargetAllocator.Enabled = true @@ -171,26 +131,7 @@ func TestReplaceConfig(t *testing.T) { assert.YAMLEq(t, expectedConfig, actualConfig) }) - t.Run("should rewrite scrape configs with SD config when TargetAllocator is enabled and feature flag is not set", func(t *testing.T) { - err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false) - require.NoError(t, err) - t.Cleanup(func() { - _ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true) - }) - - param.OtelCol.Spec.TargetAllocator.Enabled = true - - expectedConfigBytes, err := os.ReadFile("testdata/relabel_config_expected_with_sd_config.yaml") - assert.NoError(t, err) - expectedConfig := string(expectedConfigBytes) - - actualConfig, err := ReplaceConfig(param.OtelCol) - assert.NoError(t, err) - - assert.YAMLEq(t, expectedConfig, actualConfig) - }) - - t.Run("should remove scrape configs if TargetAllocator is enabled and feature flag is set", func(t *testing.T) { + t.Run("should remove scrape configs if TargetAllocator is enabled", func(t *testing.T) { param.OtelCol.Spec.TargetAllocator.Enabled = true expectedConfigBytes, err := os.ReadFile("testdata/config_expected_targetallocator.yaml") diff --git a/internal/manifests/collector/configmap_test.go b/internal/manifests/collector/configmap_test.go index 525a5e80be..b850084c53 100644 --- a/internal/manifests/collector/configmap_test.go +++ b/internal/manifests/collector/configmap_test.go @@ -17,11 +17,7 @@ package collector import ( "testing" - colfeaturegate "go.opentelemetry.io/collector/featuregate" - "github.com/stretchr/testify/assert" - - "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) func TestDesiredConfigMap(t *testing.T) { @@ -73,111 +69,6 @@ service: } }) - t.Run("should return expected collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) { - err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false) - assert.NoError(t, err) - t.Cleanup(func() { - _ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true) - }) - expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = "test-collector" - - expectedData := map[string]string{ - "collector.yaml": `exporters: - debug: -receivers: - jaeger: - protocols: - grpc: null - prometheus: - config: - scrape_configs: - - http_sd_configs: - - url: http://test-targetallocator:80/jobs/otel-collector/targets?collector_id=$POD_NAME - job_name: otel-collector - scrape_interval: 10s -service: - pipelines: - metrics: - exporters: - - debug - processors: [] - receivers: - - prometheus - - jaeger -`, - } - - param := deploymentParams() - param.OtelCol.Spec.TargetAllocator.Enabled = true - actual, err := ConfigMap(param) - - assert.NoError(t, err) - assert.Equal(t, "test-collector", actual.GetName()) - assert.Equal(t, expectedLables, actual.GetLabels()) - assert.Equal(t, len(expectedData), len(actual.Data)) - for k, expected := range expectedData { - assert.YAMLEq(t, expected, actual.Data[k]) - } - - }) - - t.Run("should return expected escaped collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) { - err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false) - assert.NoError(t, err) - t.Cleanup(func() { - _ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true) - }) - - expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = "test-collector" - expectedLables["app.kubernetes.io/version"] = "latest" - - expectedData := map[string]string{ - "collector.yaml": `exporters: - debug: -receivers: - prometheus: - config: - scrape_configs: - - http_sd_configs: - - url: http://test-targetallocator:80/jobs/serviceMonitor%2Ftest%2Ftest%2F0/targets?collector_id=$POD_NAME - job_name: serviceMonitor/test/test/0 - target_allocator: - collector_id: ${POD_NAME} - endpoint: http://test-targetallocator:80 - http_sd_config: - refresh_interval: 60s - interval: 30s -service: - pipelines: - metrics: - exporters: - - debug - processors: [] - receivers: - - prometheus -`, - } - - param, err := newParams("test/test-img", "testdata/http_sd_config_servicemonitor_test_ta_set.yaml") - assert.NoError(t, err) - param.OtelCol.Spec.TargetAllocator.Enabled = true - actual, err := ConfigMap(param) - - assert.NoError(t, err) - assert.Equal(t, "test-collector", actual.Name) - assert.Equal(t, expectedLables, actual.Labels) - assert.Equal(t, len(expectedData), len(actual.Data)) - for k, expected := range expectedData { - assert.YAMLEq(t, expected, actual.Data[k]) - } - - // Reset the value - expectedLables["app.kubernetes.io/version"] = "0.47.0" - - }) - t.Run("should return expected escaped collector config map with target_allocator config block", func(t *testing.T) { expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" expectedLables["app.kubernetes.io/name"] = "test-collector" diff --git a/pkg/featuregate/featuregate.go b/pkg/featuregate/featuregate.go index 793c19ab1e..ca3ecde484 100644 --- a/pkg/featuregate/featuregate.go +++ b/pkg/featuregate/featuregate.go @@ -53,9 +53,10 @@ var ( // automatically be rewritten when the target allocator is enabled. EnableTargetAllocatorRewrite = featuregate.GlobalRegistry().MustRegister( "operator.collector.rewritetargetallocator", - featuregate.StageBeta, + featuregate.StageStable, featuregate.WithRegisterDescription("controls whether the operator should configure the collector's targetAllocator configuration"), featuregate.WithRegisterFromVersion("v0.76.1"), + featuregate.WithRegisterToVersion("v0.98.0"), ) // PrometheusOperatorIsAvailable is the feature gate that enables features associated to the Prometheus Operator.