Skip to content

Commit 50ab7a2

Browse files
committed
Merge branch 'main' into instrumentation-support-label
# Conflicts: # bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
2 parents 4025131 + d4b24f3 commit 50ab7a2

27 files changed

+224
-263
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Fix the RBAC resources creation when the processor was only enabled"
9+
10+
# One or more tracking issues related to the change
11+
issues: [2788]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: breaking
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: change nginx instrumentation feature gate operator.autoinstrumentation.nginx into command line flag --enable-nginx-instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [2582, 2676]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: breaking
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: target allocator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Promote `operator.collector.rewritetargetallocator` feature flag to stable
9+
10+
# One or more tracking issues related to the change
11+
issues: [2796]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

autoinstrumentation/java/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.2.0

bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2024-03-25T15:02:49Z"
102+
createdAt: "2024-03-25T08:38:05Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
@@ -487,7 +487,8 @@ spec:
487487
- --enable-leader-election
488488
- --zap-log-level=info
489489
- --zap-time-encoding=rfc3339nano
490-
- --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx
490+
- --feature-gates=+operator.autoinstrumentation.go
491+
- --enable-nginx-instrumentation=true
491492
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0
492493
livenessProbe:
493494
httpGet:

config/manager/manager.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ spec:
3232
- "--enable-leader-election"
3333
- "--zap-log-level=info"
3434
- "--zap-time-encoding=rfc3339nano"
35-
- "--feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx"
35+
- "--feature-gates=+operator.autoinstrumentation.go"
36+
- "--enable-nginx-instrumentation=true"
3637
image: controller
3738
name: manager
3839
livenessProbe:

controllers/suite_test.go

+7-20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/apimachinery/pkg/runtime"
3737
"k8s.io/apimachinery/pkg/types"
3838
"k8s.io/apimachinery/pkg/util/intstr"
39+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3940
"k8s.io/apimachinery/pkg/util/uuid"
4041
"k8s.io/apimachinery/pkg/util/wait"
4142
"k8s.io/client-go/kubernetes"
@@ -109,26 +110,12 @@ func TestMain(m *testing.M) {
109110
fmt.Printf("failed to start testEnv: %v", err)
110111
os.Exit(1)
111112
}
112-
if err = monitoringv1.AddToScheme(testScheme); err != nil {
113-
fmt.Printf("failed to register scheme: %v", err)
114-
os.Exit(1)
115-
}
116-
if err = networkingv1.AddToScheme(testScheme); err != nil {
117-
fmt.Printf("failed to register scheme: %v", err)
118-
os.Exit(1)
119-
}
120-
if err = routev1.AddToScheme(testScheme); err != nil {
121-
fmt.Printf("failed to register scheme: %v", err)
122-
os.Exit(1)
123-
}
124-
if err = v1alpha1.AddToScheme(testScheme); err != nil {
125-
fmt.Printf("failed to register scheme: %v", err)
126-
os.Exit(1)
127-
}
128-
if err = v1beta1.AddToScheme(testScheme); err != nil {
129-
fmt.Printf("failed to register scheme: %v", err)
130-
os.Exit(1)
131-
}
113+
114+
utilruntime.Must(monitoringv1.AddToScheme(testScheme))
115+
utilruntime.Must(networkingv1.AddToScheme(testScheme))
116+
utilruntime.Must(routev1.AddToScheme(testScheme))
117+
utilruntime.Must(v1alpha1.AddToScheme(testScheme))
118+
utilruntime.Must(v1beta1.AddToScheme(testScheme))
132119

133120
testEnv = &envtest.Environment{
134121
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},

internal/config/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Config struct {
4646
enableMultiInstrumentation bool
4747
enableApacheHttpdInstrumentation bool
4848
enableDotNetInstrumentation bool
49+
enableNginxInstrumentation bool
4950
enablePythonInstrumentation bool
5051
autoInstrumentationDotNetImage string
5152
autoInstrumentationGoImage string
@@ -83,6 +84,7 @@ func New(opts ...Option) Config {
8384
enableMultiInstrumentation: o.enableMultiInstrumentation,
8485
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
8586
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
87+
enableNginxInstrumentation: o.enableNginxInstrumentation,
8688
enablePythonInstrumentation: o.enablePythonInstrumentation,
8789
targetAllocatorImage: o.targetAllocatorImage,
8890
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
@@ -134,6 +136,11 @@ func (c *Config) EnableDotNetAutoInstrumentation() bool {
134136
return c.enableDotNetInstrumentation
135137
}
136138

139+
// EnableNginxAutoInstrumentation is true when the operator supports nginx auto instrumentation.
140+
func (c *Config) EnableNginxAutoInstrumentation() bool {
141+
return c.enableNginxInstrumentation
142+
}
143+
137144
// EnablePythonAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
138145
func (c *Config) EnablePythonAutoInstrumentation() bool {
139146
return c.enablePythonInstrumentation

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type options struct {
4545
enableMultiInstrumentation bool
4646
enableApacheHttpdInstrumentation bool
4747
enableDotNetInstrumentation bool
48+
enableNginxInstrumentation bool
4849
enablePythonInstrumentation bool
4950
targetAllocatorConfigMapEntry string
5051
operatorOpAMPBridgeConfigMapEntry string
@@ -100,6 +101,11 @@ func WithEnableDotNetInstrumentation(s bool) Option {
100101
o.enableDotNetInstrumentation = s
101102
}
102103
}
104+
func WithEnableNginxInstrumentation(s bool) Option {
105+
return func(o *options) {
106+
o.enableNginxInstrumentation = s
107+
}
108+
}
103109
func WithEnablePythonInstrumentation(s bool) Option {
104110
return func(o *options) {
105111
o.enablePythonInstrumentation = s

internal/manifests/collector/adapters/config_to_ports.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[
100100
}
101101

102102
if err != nil {
103-
logger.V(2).Info("no parser found for '%s'", cmptName)
103+
logger.V(2).Info("no parser found for", "component", cmptName)
104104
continue
105105
}
106106

internal/manifests/collector/adapters/config_to_rbac.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ConfigToRBAC(logger logr.Logger, config map[interface{}]interface{}) []rbac
5252
processorName := key.(string)
5353
processorParser, err := processor.For(logger, processorName, processorCfg)
5454
if err != nil {
55-
logger.V(2).Info("no parser found for '%s'", processorName)
55+
logger.V(2).Info("no parser found for", "processor", processorName)
5656
continue
5757
}
5858

internal/manifests/collector/config_replace_test.go

+1-60
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,17 @@ import (
1818
"os"
1919
"testing"
2020

21-
"github.com/prometheus/prometheus/discovery/http"
2221
"github.com/stretchr/testify/assert"
2322
"github.com/stretchr/testify/require"
24-
colfeaturegate "go.opentelemetry.io/collector/featuregate"
2523
"gopkg.in/yaml.v2"
2624

2725
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
28-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2926
)
3027

3128
func TestPrometheusParser(t *testing.T) {
3229
param, err := newParams("test/test-img", "testdata/http_sd_config_test.yaml")
3330
assert.NoError(t, err)
3431

35-
t.Run("should update config with http_sd_config", func(t *testing.T) {
36-
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
37-
require.NoError(t, err)
38-
t.Cleanup(func() {
39-
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
40-
})
41-
actualConfig, err := ReplaceConfig(param.OtelCol)
42-
assert.NoError(t, err)
43-
44-
// prepare
45-
var cfg Config
46-
promCfgMap, err := ta.ConfigToPromConfig(actualConfig)
47-
assert.NoError(t, err)
48-
49-
promCfg, err := yaml.Marshal(promCfgMap)
50-
assert.NoError(t, err)
51-
52-
err = yaml.UnmarshalStrict(promCfg, &cfg)
53-
assert.NoError(t, err)
54-
55-
// test
56-
expectedMap := map[string]bool{
57-
"prometheus": false,
58-
"service-x": false,
59-
}
60-
for _, scrapeConfig := range cfg.PromConfig.ScrapeConfigs {
61-
assert.Len(t, scrapeConfig.ServiceDiscoveryConfigs, 1)
62-
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].Name(), "http")
63-
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].(*http.SDConfig).URL, "http://test-targetallocator:80/jobs/"+scrapeConfig.JobName+"/targets?collector_id=$POD_NAME")
64-
expectedMap[scrapeConfig.JobName] = true
65-
}
66-
for k := range expectedMap {
67-
assert.True(t, expectedMap[k], k)
68-
}
69-
assert.True(t, cfg.TargetAllocConfig == nil)
70-
})
71-
7232
t.Run("should update config with targetAllocator block if block not present", func(t *testing.T) {
7333
// Set up the test scenario
7434
param.OtelCol.Spec.TargetAllocator.Enabled = true
@@ -171,26 +131,7 @@ func TestReplaceConfig(t *testing.T) {
171131
assert.YAMLEq(t, expectedConfig, actualConfig)
172132
})
173133

174-
t.Run("should rewrite scrape configs with SD config when TargetAllocator is enabled and feature flag is not set", func(t *testing.T) {
175-
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
176-
require.NoError(t, err)
177-
t.Cleanup(func() {
178-
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
179-
})
180-
181-
param.OtelCol.Spec.TargetAllocator.Enabled = true
182-
183-
expectedConfigBytes, err := os.ReadFile("testdata/relabel_config_expected_with_sd_config.yaml")
184-
assert.NoError(t, err)
185-
expectedConfig := string(expectedConfigBytes)
186-
187-
actualConfig, err := ReplaceConfig(param.OtelCol)
188-
assert.NoError(t, err)
189-
190-
assert.YAMLEq(t, expectedConfig, actualConfig)
191-
})
192-
193-
t.Run("should remove scrape configs if TargetAllocator is enabled and feature flag is set", func(t *testing.T) {
134+
t.Run("should remove scrape configs if TargetAllocator is enabled", func(t *testing.T) {
194135
param.OtelCol.Spec.TargetAllocator.Enabled = true
195136

196137
expectedConfigBytes, err := os.ReadFile("testdata/config_expected_targetallocator.yaml")

internal/manifests/collector/configmap_test.go

-109
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ package collector
1717
import (
1818
"testing"
1919

20-
colfeaturegate "go.opentelemetry.io/collector/featuregate"
21-
2220
"github.com/stretchr/testify/assert"
23-
24-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2521
)
2622

2723
func TestDesiredConfigMap(t *testing.T) {
@@ -73,111 +69,6 @@ service:
7369
}
7470
})
7571

76-
t.Run("should return expected collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) {
77-
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
78-
assert.NoError(t, err)
79-
t.Cleanup(func() {
80-
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
81-
})
82-
expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
83-
expectedLables["app.kubernetes.io/name"] = "test-collector"
84-
85-
expectedData := map[string]string{
86-
"collector.yaml": `exporters:
87-
debug:
88-
receivers:
89-
jaeger:
90-
protocols:
91-
grpc: null
92-
prometheus:
93-
config:
94-
scrape_configs:
95-
- http_sd_configs:
96-
- url: http://test-targetallocator:80/jobs/otel-collector/targets?collector_id=$POD_NAME
97-
job_name: otel-collector
98-
scrape_interval: 10s
99-
service:
100-
pipelines:
101-
metrics:
102-
exporters:
103-
- debug
104-
processors: []
105-
receivers:
106-
- prometheus
107-
- jaeger
108-
`,
109-
}
110-
111-
param := deploymentParams()
112-
param.OtelCol.Spec.TargetAllocator.Enabled = true
113-
actual, err := ConfigMap(param)
114-
115-
assert.NoError(t, err)
116-
assert.Equal(t, "test-collector", actual.GetName())
117-
assert.Equal(t, expectedLables, actual.GetLabels())
118-
assert.Equal(t, len(expectedData), len(actual.Data))
119-
for k, expected := range expectedData {
120-
assert.YAMLEq(t, expected, actual.Data[k])
121-
}
122-
123-
})
124-
125-
t.Run("should return expected escaped collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) {
126-
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
127-
assert.NoError(t, err)
128-
t.Cleanup(func() {
129-
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
130-
})
131-
132-
expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
133-
expectedLables["app.kubernetes.io/name"] = "test-collector"
134-
expectedLables["app.kubernetes.io/version"] = "latest"
135-
136-
expectedData := map[string]string{
137-
"collector.yaml": `exporters:
138-
debug:
139-
receivers:
140-
prometheus:
141-
config:
142-
scrape_configs:
143-
- http_sd_configs:
144-
- url: http://test-targetallocator:80/jobs/serviceMonitor%2Ftest%2Ftest%2F0/targets?collector_id=$POD_NAME
145-
job_name: serviceMonitor/test/test/0
146-
target_allocator:
147-
collector_id: ${POD_NAME}
148-
endpoint: http://test-targetallocator:80
149-
http_sd_config:
150-
refresh_interval: 60s
151-
interval: 30s
152-
service:
153-
pipelines:
154-
metrics:
155-
exporters:
156-
- debug
157-
processors: []
158-
receivers:
159-
- prometheus
160-
`,
161-
}
162-
163-
param, err := newParams("test/test-img", "testdata/http_sd_config_servicemonitor_test_ta_set.yaml")
164-
assert.NoError(t, err)
165-
param.OtelCol.Spec.TargetAllocator.Enabled = true
166-
actual, err := ConfigMap(param)
167-
168-
assert.NoError(t, err)
169-
assert.Equal(t, "test-collector", actual.Name)
170-
assert.Equal(t, expectedLables, actual.Labels)
171-
assert.Equal(t, len(expectedData), len(actual.Data))
172-
for k, expected := range expectedData {
173-
assert.YAMLEq(t, expected, actual.Data[k])
174-
}
175-
176-
// Reset the value
177-
expectedLables["app.kubernetes.io/version"] = "0.47.0"
178-
179-
})
180-
18172
t.Run("should return expected escaped collector config map with target_allocator config block", func(t *testing.T) {
18273
expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
18374
expectedLables["app.kubernetes.io/name"] = "test-collector"

0 commit comments

Comments
 (0)