Skip to content

Commit 48bc207

Browse files
authored
NodeJS instrumentation featuregates into cli (#2834)
* NodeJS instrumentation featuregates into cli Signed-off-by: Yuri Sa <[email protected]> * Added complement to featuregate Signed-off-by: Yuri Sa <[email protected]> * Fixed Linters Signed-off-by: Yuri Sa <[email protected]> * Fixed Linters Signed-off-by: Yuri Sa <[email protected]> * Added e2e parameters Signed-off-by: Yuri Sa <[email protected]> * Fixed e2e test Signed-off-by: Yuri Sa <[email protected]> * Fixed e2e test Signed-off-by: Yuri Sa <[email protected]> * Fixed e2e test Signed-off-by: Yuri Sa <[email protected]> * Fixed e2e test Signed-off-by: Yuri Sa <[email protected]> * Removed feature flags Signed-off-by: Yuri Sa <[email protected]> * Removed feature flags Signed-off-by: Yuri Sa <[email protected]> --------- Signed-off-by: Yuri Sa <[email protected]>
1 parent 69e84a8 commit 48bc207

File tree

15 files changed

+61
-71
lines changed

15 files changed

+61
-71
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. collector, target allocator, auto-instrumentation, opamp, 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: remove featuregate `operator.autoinstrumentation.nodejs`. Use command line flag `--enable-nodejs-instrumentation` instead
9+
10+
# One or more tracking issues related to the change
11+
issues: [2674]
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:

.github/workflows/e2e.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
- e2e-metadata-filters
3636
include:
3737
- group: e2e-instrumentation
38-
setup: "add-operator-arg OPERATOR_ARG=--enable-go-instrumentation prepare-e2e"
38+
setup: "add-instrumentation-params prepare-e2e"
3939
- group: e2e-multi-instrumentation
40-
setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e"
40+
setup: "add-multi-instrumentation-params prepare-e2e"
4141
- group: e2e-metadata-filters
4242
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=*filter.out --labels=*filter.out' prepare-e2e"
4343

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ add-operator-arg: manifests kustomize
145145
add-image-targetallocator:
146146
@$(MAKE) add-operator-arg OPERATOR_ARG=--target-allocator-image=$(TARGETALLOCATOR_IMG)
147147

148+
.PHONY: add-instrumentation-params
149+
add-instrumentation-params:
150+
@$(MAKE) add-operator-arg OPERATOR_ARG=--enable-go-instrumentation=true
151+
152+
.PHONY: add-multi-instrumentation-params
153+
add-multi-instrumentation-params:
154+
@$(MAKE) add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation
155+
148156
.PHONY: add-image-opampbridge
149157
add-image-opampbridge:
150158
@$(MAKE) add-operator-arg OPERATOR_ARG=--operator-opamp-bridge-image=$(OPERATOROPAMPBRIDGE_IMG)

bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ spec:
498498
- --enable-leader-election
499499
- --zap-log-level=info
500500
- --zap-time-encoding=rfc3339nano
501-
- --feature-gates=+operator.autoinstrumentation.go
502501
- --enable-nginx-instrumentation=true
503502
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.98.0
504503
livenessProbe:

config/manager/manager.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ spec:
3232
- "--enable-leader-election"
3333
- "--zap-log-level=info"
3434
- "--zap-time-encoding=rfc3339nano"
35-
- "--feature-gates=+operator.autoinstrumentation.go"
3635
- "--enable-nginx-instrumentation=true"
3736
image: controller
3837
name: manager

internal/config/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Config struct {
5050
enableGoInstrumentation bool
5151
enableNginxInstrumentation bool
5252
enablePythonInstrumentation bool
53+
enableNodeJSInstrumentation bool
5354
enableJavaInstrumentation bool
5455
autoInstrumentationDotNetImage string
5556
autoInstrumentationGoImage string
@@ -94,6 +95,7 @@ func New(opts ...Option) Config {
9495
enableGoInstrumentation: o.enableGoInstrumentation,
9596
enableNginxInstrumentation: o.enableNginxInstrumentation,
9697
enablePythonInstrumentation: o.enablePythonInstrumentation,
98+
enableNodeJSInstrumentation: o.enableNodeJSInstrumentation,
9799
enableJavaInstrumentation: o.enableJavaInstrumentation,
98100
targetAllocatorImage: o.targetAllocatorImage,
99101
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
@@ -172,6 +174,11 @@ func (c *Config) EnablePythonAutoInstrumentation() bool {
172174
return c.enablePythonInstrumentation
173175
}
174176

177+
// EnableNodeJSAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
178+
func (c *Config) EnableNodeJSAutoInstrumentation() bool {
179+
return c.enableNodeJSInstrumentation
180+
}
181+
175182
// CollectorConfigMapEntry represents the configuration file name for the collector. Immutable.
176183
func (c *Config) CollectorConfigMapEntry() string {
177184
return c.collectorConfigMapEntry

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type options struct {
4949
enableGoInstrumentation bool
5050
enableNginxInstrumentation bool
5151
enablePythonInstrumentation bool
52+
enableNodeJSInstrumentation bool
5253
enableJavaInstrumentation bool
5354
targetAllocatorConfigMapEntry string
5455
operatorOpAMPBridgeConfigMapEntry string
@@ -125,6 +126,11 @@ func WithEnablePythonInstrumentation(s bool) Option {
125126
o.enablePythonInstrumentation = s
126127
}
127128
}
129+
func WithEnableNodeJSInstrumentation(s bool) Option {
130+
return func(o *options) {
131+
o.enableNodeJSInstrumentation = s
132+
}
133+
}
128134
func WithTargetAllocatorConfigMapEntry(s string) Option {
129135
return func(o *options) {
130136
o.targetAllocatorConfigMapEntry = s

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func main() {
115115
enableGoInstrumentation bool
116116
enablePythonInstrumentation bool
117117
enableNginxInstrumentation bool
118+
enableNodeJSInstrumentation bool
118119
enableJavaInstrumentation bool
119120
collectorImage string
120121
targetAllocatorImage string
@@ -145,6 +146,7 @@ func main() {
145146
pflag.BoolVar(&enableGoInstrumentation, constants.FlagGo, false, "Controls whether the operator supports Go auto-instrumentation")
146147
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
147148
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
149+
pflag.BoolVar(&enableNodeJSInstrumentation, constants.FlagNodeJS, true, "Controls whether the operator supports nodejs auto-instrumentation")
148150
pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation")
149151
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.")
150152
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.")
@@ -191,6 +193,7 @@ func main() {
191193
"enable-go-instrumentation", enableGoInstrumentation,
192194
"enable-python-instrumentation", enablePythonInstrumentation,
193195
"enable-nginx-instrumentation", enableNginxInstrumentation,
196+
"enable-nodejs-instrumentation", enableNodeJSInstrumentation,
194197
"enable-java-instrumentation", enableJavaInstrumentation,
195198
)
196199

@@ -214,6 +217,7 @@ func main() {
214217
config.WithEnableGoInstrumentation(enableGoInstrumentation),
215218
config.WithEnableNginxInstrumentation(enableNginxInstrumentation),
216219
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
220+
config.WithEnableNodeJSInstrumentation(enableNodeJSInstrumentation),
217221
config.WithEnableJavaInstrumentation(enableJavaInstrumentation),
218222
config.WithTargetAllocatorImage(targetAllocatorImage),
219223
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ const (
4242
FlagGo = "enable-go-instrumentation"
4343
FlagPython = "enable-python-instrumentation"
4444
FlagNginx = "enable-nginx-instrumentation"
45+
FlagNodeJS = "enable-nodejs-instrumentation"
4546
FlagJava = "enable-java-instrumentation"
4647
)

pkg/featuregate/featuregate.go

-19
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,6 @@ const (
2525
)
2626

2727
var (
28-
EnableNodeJSAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
29-
"operator.autoinstrumentation.nodejs",
30-
featuregate.StageBeta,
31-
featuregate.WithRegisterDescription("controls whether the operator supports NodeJS auto-instrumentation"),
32-
featuregate.WithRegisterFromVersion("v0.76.1"),
33-
)
34-
EnableNginxAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
35-
"operator.autoinstrumentation.nginx",
36-
featuregate.StageAlpha,
37-
featuregate.WithRegisterDescription("controls whether the operator supports Nginx auto-instrumentation"),
38-
featuregate.WithRegisterFromVersion("v0.86.0"),
39-
)
40-
EnableGoAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
41-
"operator.autoinstrumentation.go",
42-
featuregate.StageAlpha,
43-
featuregate.WithRegisterDescription("controls whether the operator supports Golang auto-instrumentation"),
44-
featuregate.WithRegisterFromVersion("v0.77.0"),
45-
)
46-
4728
// PrometheusOperatorIsAvailable is the feature gate that enables features associated to the Prometheus Operator.
4829
PrometheusOperatorIsAvailable = featuregate.GlobalRegistry().MustRegister(
4930
"operator.observability.prometheus",

pkg/instrumentation/podmutator.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
3030
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3131
"github.com/open-telemetry/opentelemetry-operator/internal/webhook/podmutation"
32-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3332
)
3433

3534
var (
@@ -241,7 +240,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
241240
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
242241
return pod, err
243242
}
244-
if featuregate.EnableNodeJSAutoInstrumentationSupport.IsEnabled() || inst == nil {
243+
if pm.config.EnableNodeJSAutoInstrumentation() || inst == nil {
245244
insts.NodeJS.Instrumentation = inst
246245
} else {
247246
logger.Error(nil, "support for NodeJS auto instrumentation is not enabled")

pkg/instrumentation/podmutator_test.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import (
2222
"github.com/go-logr/logr"
2323
"github.com/stretchr/testify/assert"
2424
"github.com/stretchr/testify/require"
25-
colfeaturegate "go.opentelemetry.io/collector/featuregate"
2625
corev1 "k8s.io/api/core/v1"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
"k8s.io/client-go/tools/record"
2928

3029
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
3130
"github.com/open-telemetry/opentelemetry-operator/internal/config"
32-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3331
)
3432

3533
func TestMutatePod(t *testing.T) {
@@ -815,6 +813,7 @@ func TestMutatePod(t *testing.T) {
815813
},
816814
},
817815
},
816+
config: config.New(config.WithEnableNodeJSInstrumentation(true)),
818817
},
819818
{
820819
name: "nodejs injection multiple containers, true",
@@ -1086,6 +1085,7 @@ func TestMutatePod(t *testing.T) {
10861085
},
10871086
},
10881087
},
1088+
config: config.New(config.WithEnableNodeJSInstrumentation(true)),
10891089
},
10901090
{
10911091
name: "nodejs injection feature gate disabled",
@@ -1168,13 +1168,6 @@ func TestMutatePod(t *testing.T) {
11681168
},
11691169
},
11701170
},
1171-
setFeatureGates: func(t *testing.T) {
1172-
originalVal := featuregate.EnableNodeJSAutoInstrumentationSupport.IsEnabled()
1173-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNodeJSAutoInstrumentationSupport.ID(), false))
1174-
t.Cleanup(func() {
1175-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNodeJSAutoInstrumentationSupport.ID(), originalVal))
1176-
})
1177-
},
11781171
},
11791172
{
11801173
name: "python injection, true",
@@ -4201,6 +4194,7 @@ func TestMutatePod(t *testing.T) {
42014194
config.WithEnableMultiInstrumentation(true),
42024195
config.WithEnablePythonInstrumentation(true),
42034196
config.WithEnableDotNetInstrumentation(true),
4197+
config.WithEnableNodeJSInstrumentation(true),
42044198
),
42054199
},
42064200
{
@@ -4991,6 +4985,7 @@ func TestMutatePod(t *testing.T) {
49914985
config.WithEnableMultiInstrumentation(true),
49924986
config.WithEnableDotNetInstrumentation(true),
49934987
config.WithEnablePythonInstrumentation(true),
4988+
config.WithEnableNodeJSInstrumentation(true),
49944989
),
49954990
},
49964991
{
@@ -5145,7 +5140,7 @@ func TestMutatePod(t *testing.T) {
51455140
},
51465141
},
51475142
},
5148-
config: config.New(config.WithEnableMultiInstrumentation(false)),
5143+
config: config.New(config.WithEnableMultiInstrumentation(false), config.WithEnableJavaInstrumentation(false)),
51495144
},
51505145
{
51515146
name: "multi instrumentation feature gate enabled, multiple instrumentation annotations set, no containers",
@@ -5289,7 +5284,7 @@ func TestMutatePod(t *testing.T) {
52895284
},
52905285
},
52915286
},
5292-
config: config.New(config.WithEnableMultiInstrumentation(true)),
5287+
config: config.New(config.WithEnableMultiInstrumentation(true), config.WithEnableJavaInstrumentation(false)),
52935288
},
52945289
{
52955290
name: "multi instrumentation feature gate enabled, single instrumentation annotation set, no containers",
@@ -5590,6 +5585,7 @@ func TestMutatePod(t *testing.T) {
55905585
config: config.New(
55915586
config.WithEnableMultiInstrumentation(true),
55925587
config.WithEnableDotNetInstrumentation(false),
5588+
config.WithEnableNodeJSInstrumentation(false),
55935589
),
55945590
},
55955591
}

pkg/instrumentation/upgrade/upgrade.go

+7-34
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,12 @@ import (
2020
"reflect"
2121

2222
"github.com/go-logr/logr"
23-
featuregate2 "go.opentelemetry.io/collector/featuregate"
2423
"k8s.io/client-go/tools/record"
2524
"sigs.k8s.io/controller-runtime/pkg/client"
2625

2726
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
2827
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2928
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
30-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
31-
)
32-
33-
var (
34-
defaultAnnotationToGate = map[string]*featuregate2.Gate{
35-
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
36-
}
3729
)
3830

3931
type autoInstConfig struct {
@@ -62,6 +54,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
6254
constants.AnnotationDefaultAutoInstrumentationGo: {constants.FlagGo, cfg.EnableGoAutoInstrumentation()},
6355
constants.AnnotationDefaultAutoInstrumentationNginx: {constants.FlagNginx, cfg.EnableNginxAutoInstrumentation()},
6456
constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()},
57+
constants.AnnotationDefaultAutoInstrumentationNodeJS: {constants.FlagNodeJS, cfg.EnableNodeJSAutoInstrumentation()},
6558
constants.AnnotationDefaultAutoInstrumentationJava: {constants.FlagJava, cfg.EnableJavaAutoInstrumentation()},
6659
}
6760

@@ -147,43 +140,23 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
147140
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
148141
upgraded.Annotations[annotation] = u.DefaultAutoInstPython
149142
}
143+
case constants.AnnotationDefaultAutoInstrumentationNodeJS:
144+
if inst.Spec.NodeJS.Image == autoInst {
145+
upgraded.Spec.NodeJS.Image = u.DefaultAutoInstNodeJS
146+
upgraded.Annotations[annotation] = u.DefaultAutoInstNodeJS
147+
}
150148
case constants.AnnotationDefaultAutoInstrumentationJava:
151149
if inst.Spec.Java.Image == autoInst {
152150
upgraded.Spec.Java.Image = u.DefaultAutoInstJava
153151
upgraded.Annotations[annotation] = u.DefaultAutoInstJava
154152
}
155153
}
154+
156155
} else {
157156
u.Logger.V(4).Info("autoinstrumentation not enabled for this language", "flag", instCfg.id)
158157
}
159158
}
160159
}
161160

162-
for annotation, gate := range defaultAnnotationToGate {
163-
autoInst := upgraded.Annotations[annotation]
164-
if autoInst != "" {
165-
if gate.IsEnabled() {
166-
switch annotation {
167-
case constants.AnnotationDefaultAutoInstrumentationNodeJS:
168-
if inst.Spec.NodeJS.Image == autoInst {
169-
upgraded.Spec.NodeJS.Image = u.DefaultAutoInstNodeJS
170-
upgraded.Annotations[annotation] = u.DefaultAutoInstNodeJS
171-
}
172-
case constants.AnnotationDefaultAutoInstrumentationPython:
173-
if inst.Spec.Python.Image == autoInst {
174-
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
175-
upgraded.Annotations[annotation] = u.DefaultAutoInstPython
176-
}
177-
case constants.AnnotationDefaultAutoInstrumentationGo:
178-
if inst.Spec.Go.Image == autoInst {
179-
upgraded.Spec.Go.Image = u.DefaultAutoInstGo
180-
upgraded.Annotations[annotation] = u.DefaultAutoInstGo
181-
}
182-
}
183-
} else {
184-
u.Logger.V(4).Info("autoinstrumentation not enabled for this language", "flag", gate.ID())
185-
}
186-
}
187-
}
188161
return upgraded
189162
}

pkg/instrumentation/upgrade/upgrade_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestUpgrade(t *testing.T) {
6969
config.WithEnableGoInstrumentation(true),
7070
config.WithEnableNginxInstrumentation(true),
7171
config.WithEnablePythonInstrumentation(true),
72+
config.WithEnableNodeJSInstrumentation(true),
7273
config.WithEnableJavaInstrumentation(true),
7374
),
7475
).Default(context.Background(), inst)
@@ -96,6 +97,7 @@ func TestUpgrade(t *testing.T) {
9697
config.WithEnableGoInstrumentation(true),
9798
config.WithEnableNginxInstrumentation(true),
9899
config.WithEnablePythonInstrumentation(true),
100+
config.WithEnableNodeJSInstrumentation(true),
99101
config.WithEnableJavaInstrumentation(true),
100102
)
101103
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)

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

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

0 commit comments

Comments
 (0)