Skip to content

Commit d4b24f3

Browse files
authored
Change nginx instrumentation into command line (open-telemetry#2777)
* feat: change nginx instrumentation to cli flag * set nginx instrumentation to default false * update config/manager * enable nginx in config/manager * update chloggen
1 parent 60d37e1 commit d4b24f3

File tree

13 files changed

+51
-37
lines changed

13 files changed

+51
-37
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: 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:

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-11T13:32:19Z"
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:

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

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func main() {
113113
enableApacheHttpdInstrumentation bool
114114
enableDotNetInstrumentation bool
115115
enablePythonInstrumentation bool
116+
enableNginxInstrumentation bool
116117
collectorImage string
117118
targetAllocatorImage string
118119
operatorOpAMPBridgeImage string
@@ -140,6 +141,7 @@ func main() {
140141
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation")
141142
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
142143
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
144+
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
143145
stringFlagOrEnv(&collectorImage, "collector-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:%s", v.OpenTelemetryCollector), "The default OpenTelemetry collector image. This image is used when no image is specified in the CustomResource.")
144146
stringFlagOrEnv(&targetAllocatorImage, "target-allocator-image", "RELATED_IMAGE_TARGET_ALLOCATOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:%s", v.TargetAllocator), "The default OpenTelemetry target allocator image. This image is used when no image is specified in the CustomResource.")
145147
stringFlagOrEnv(&operatorOpAMPBridgeImage, "operator-opamp-bridge-image", "RELATED_IMAGE_OPERATOR_OPAMP_BRIDGE", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:%s", v.OperatorOpAMPBridge), "The default OpenTelemetry Operator OpAMP Bridge image. This image is used when no image is specified in the CustomResource.")
@@ -183,6 +185,7 @@ func main() {
183185
"enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation,
184186
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
185187
"enable-python-instrumentation", enablePythonInstrumentation,
188+
"enable-nginx-instrumentation", enableNginxInstrumentation,
186189
)
187190

188191
restConfig := ctrl.GetConfigOrDie()
@@ -202,6 +205,7 @@ func main() {
202205
config.WithEnableMultiInstrumentation(enableMultiInstrumentation),
203206
config.WithEnableApacheHttpdInstrumentation(enableApacheHttpdInstrumentation),
204207
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
208+
config.WithEnableNginxInstrumentation(enableNginxInstrumentation),
205209
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
206210
config.WithTargetAllocatorImage(targetAllocatorImage),
207211
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ const (
3838
FlagApacheHttpd = "enable-apache-httpd-instrumentation"
3939
FlagDotNet = "enable-dotnet-instrumentation"
4040
FlagPython = "enable-python-instrumentation"
41+
FlagNginx = "enable-nginx-instrumentation"
4142
)

pkg/featuregate/featuregate.go

-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ var (
4343
featuregate.WithRegisterDescription("controls whether the operator supports Golang auto-instrumentation"),
4444
featuregate.WithRegisterFromVersion("v0.77.0"),
4545
)
46-
EnableNginxAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
47-
"operator.autoinstrumentation.nginx",
48-
featuregate.StageAlpha,
49-
featuregate.WithRegisterDescription("controls whether the operator supports Nginx auto-instrumentation"),
50-
featuregate.WithRegisterFromVersion("v0.86.0"),
51-
)
5246
// EnableTargetAllocatorRewrite is the feature gate that controls whether the collector's configuration should
5347
// automatically be rewritten when the target allocator is enabled.
5448
EnableTargetAllocatorRewrite = featuregate.GlobalRegistry().MustRegister(

pkg/instrumentation/podmutator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
302302
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
303303
return pod, err
304304
}
305-
if featuregate.EnableNginxAutoInstrumentationSupport.IsEnabled() || inst == nil {
305+
if pm.config.EnableNginxAutoInstrumentation() || inst == nil {
306306
insts.Nginx.Instrumentation = inst
307307
} else {
308308
logger.Error(nil, "support for Nginx auto instrumentation is not enabled")

pkg/instrumentation/podmutator_test.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -2972,13 +2972,7 @@ func TestMutatePod(t *testing.T) {
29722972
},
29732973
},
29742974
},
2975-
setFeatureGates: func(t *testing.T) {
2976-
originalVal := featuregate.EnableNginxAutoInstrumentationSupport.IsEnabled()
2977-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), true))
2978-
t.Cleanup(func() {
2979-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), originalVal))
2980-
})
2981-
},
2975+
config: config.New(config.WithEnableNginxInstrumentation(true)),
29822976
},
29832977
{
29842978
name: "nginx injection feature gate disabled",
@@ -3059,13 +3053,7 @@ func TestMutatePod(t *testing.T) {
30593053
},
30603054
},
30613055
},
3062-
setFeatureGates: func(t *testing.T) {
3063-
originalVal := featuregate.EnableNginxAutoInstrumentationSupport.IsEnabled()
3064-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), false))
3065-
t.Cleanup(func() {
3066-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), originalVal))
3067-
})
3068-
},
3056+
config: config.New(config.WithEnableDotNetInstrumentation(false)),
30693057
},
30703058

30713059
{

pkg/instrumentation/upgrade/upgrade.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var (
3535
constants.AnnotationDefaultAutoInstrumentationJava: featuregate.EnableJavaAutoInstrumentationSupport,
3636
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
3737
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
38-
constants.AnnotationDefaultAutoInstrumentationNginx: featuregate.EnableNginxAutoInstrumentationSupport,
3938
}
4039
)
4140

@@ -62,6 +61,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
6261
defaultAnnotationToConfig := map[string]autoInstConfig{
6362
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: {constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()},
6463
constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()},
64+
constants.AnnotationDefaultAutoInstrumentationNginx: {constants.FlagNginx, cfg.EnableNginxAutoInstrumentation()},
6565
constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()},
6666
}
6767

@@ -132,6 +132,11 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
132132
upgraded.Spec.DotNet.Image = u.DefaultAutoInstDotNet
133133
upgraded.Annotations[annotation] = u.DefaultAutoInstDotNet
134134
}
135+
case constants.AnnotationDefaultAutoInstrumentationNginx:
136+
if inst.Spec.Nginx.Image == autoInst {
137+
upgraded.Spec.Nginx.Image = u.DefaultAutoInstNginx
138+
upgraded.Annotations[annotation] = u.DefaultAutoInstNginx
139+
}
135140
case constants.AnnotationDefaultAutoInstrumentationPython:
136141
if inst.Spec.Python.Image == autoInst {
137142
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
@@ -170,11 +175,6 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
170175
upgraded.Spec.Go.Image = u.DefaultAutoInstGo
171176
upgraded.Annotations[annotation] = u.DefaultAutoInstGo
172177
}
173-
case constants.AnnotationDefaultAutoInstrumentationNginx:
174-
if inst.Spec.Nginx.Image == autoInst {
175-
upgraded.Spec.Nginx.Image = u.DefaultAutoInstNginx
176-
upgraded.Annotations[annotation] = u.DefaultAutoInstNginx
177-
}
178178
}
179179
} else {
180180
u.Logger.Error(nil, "autoinstrumentation not enabled for this language", "flag", gate.ID())

pkg/instrumentation/upgrade/upgrade_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ func TestUpgrade(t *testing.T) {
4242
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal))
4343
})
4444

45-
originalVal = featuregate.EnableNginxAutoInstrumentationSupport.IsEnabled()
46-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), true))
47-
t.Cleanup(func() {
48-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNginxAutoInstrumentationSupport.ID(), originalVal))
49-
})
50-
5145
nsName := strings.ToLower(t.Name())
5246
err := k8sClient.Create(context.Background(), &corev1.Namespace{
5347
ObjectMeta: metav1.ObjectMeta{
@@ -80,6 +74,7 @@ func TestUpgrade(t *testing.T) {
8074
config.WithAutoInstrumentationNginxImage("nginx:1"),
8175
config.WithEnableApacheHttpdInstrumentation(true),
8276
config.WithEnableDotNetInstrumentation(true),
77+
config.WithEnableNginxInstrumentation(true),
8378
config.WithEnablePythonInstrumentation(true),
8479
),
8580
).Default(context.Background(), inst)
@@ -104,6 +99,7 @@ func TestUpgrade(t *testing.T) {
10499
config.WithAutoInstrumentationNginxImage("nginx:2"),
105100
config.WithEnableApacheHttpdInstrumentation(true),
106101
config.WithEnableDotNetInstrumentation(true),
102+
config.WithEnableNginxInstrumentation(true),
107103
config.WithEnablePythonInstrumentation(true),
108104
)
109105
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)

tests/e2e-upgrade/upgrade-test/opentelemetry-operator-v0.86.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8317,7 +8317,7 @@ spec:
83178317
- --enable-leader-election
83188318
- --zap-log-level=info
83198319
- --zap-time-encoding=rfc3339nano
8320-
- --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx
8320+
- --feature-gates=+operator.autoinstrumentation.go
83218321
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.86.0
83228322
livenessProbe:
83238323
httpGet:

0 commit comments

Comments
 (0)