Skip to content

Commit d9e1d16

Browse files
authored
Change multi instrumentation feature gate into command line flag (#2635)
* add multiIntrumentation to command line * add multiinstrumentation to config and add test * change github workflow for multi-instrumentation * rename command * remove unwanted comments * add chlog * modify chlog * add missing description in config for multi-instrumentation
1 parent 52383fc commit d9e1d16

File tree

11 files changed

+83
-81
lines changed

11 files changed

+83
-81
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 multi instrumentation feature gate into command line flag --enable-multi-instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [2582]
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- group: e2e-prometheuscr
3737
setup: "prepare-e2e-with-featuregates FEATUREGATES=+operator.observability.prometheus"
3838
- group: e2e-multi-instrumentation
39-
setup: "prepare-e2e-with-featuregates FEATUREGATES=+operator.autoinstrumentation.multi-instrumentation"
39+
setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e"
4040

4141
steps:
4242
- name: Check out code into the Go module directory

internal/config/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Config struct {
4343
collectorImage string
4444
collectorConfigMapEntry string
4545
createRBACPermissions bool
46+
enableMultiInstrumentation bool
4647
autoInstrumentationDotNetImage string
4748
autoInstrumentationGoImage string
4849
autoInstrumentationApacheHttpdImage string
@@ -75,6 +76,7 @@ func New(opts ...Option) Config {
7576
collectorImage: o.collectorImage,
7677
collectorConfigMapEntry: o.collectorConfigMapEntry,
7778
createRBACPermissions: o.createRBACPermissions,
79+
enableMultiInstrumentation: o.enableMultiInstrumentation,
7880
targetAllocatorImage: o.targetAllocatorImage,
7981
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
8082
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -109,6 +111,11 @@ func (c *Config) CollectorImage() string {
109111
return c.collectorImage
110112
}
111113

114+
// EnableMultiInstrumentation is true when the operator supports multi instrumentation.
115+
func (c *Config) EnableMultiInstrumentation() bool {
116+
return c.enableMultiInstrumentation
117+
}
118+
112119
// CollectorConfigMapEntry represents the configuration file name for the collector. Immutable.
113120
func (c *Config) CollectorConfigMapEntry() string {
114121
return c.collectorConfigMapEntry

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type options struct {
4242
collectorImage string
4343
collectorConfigMapEntry string
4444
createRBACPermissions bool
45+
enableMultiInstrumentation bool
4546
targetAllocatorConfigMapEntry string
4647
operatorOpAMPBridgeConfigMapEntry string
4748
targetAllocatorImage string
@@ -80,6 +81,11 @@ func WithCreateRBACPermissions(s bool) Option {
8081
o.createRBACPermissions = s
8182
}
8283
}
84+
func WithEnableMultiInstrumentation(s bool) Option {
85+
return func(o *options) {
86+
o.enableMultiInstrumentation = s
87+
}
88+
}
8389
func WithTargetAllocatorConfigMapEntry(s string) Option {
8490
return func(o *options) {
8591
o.targetAllocatorConfigMapEntry = s

main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func main() {
104104
pprofAddr string
105105
enableLeaderElection bool
106106
createRBACPermissions bool
107+
enableMultiInstrumentation bool
107108
collectorImage string
108109
targetAllocatorImage string
109110
operatorOpAMPBridgeImage string
@@ -126,6 +127,7 @@ func main() {
126127
"Enable leader election for controller manager. "+
127128
"Enabling this will ensure there is only one active controller manager.")
128129
pflag.BoolVar(&createRBACPermissions, "create-rbac-permissions", false, "Automatically create RBAC permissions needed by the processors")
130+
pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation")
129131
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.")
130132
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.")
131133
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.")
@@ -163,6 +165,7 @@ func main() {
163165
"go-arch", runtime.GOARCH,
164166
"go-os", runtime.GOOS,
165167
"labels-filter", labelsFilter,
168+
"enable-multi-instrumentation", enableMultiInstrumentation,
166169
)
167170

168171
restConfig := ctrl.GetConfigOrDie()
@@ -179,6 +182,7 @@ func main() {
179182
config.WithVersion(v),
180183
config.WithCollectorImage(collectorImage),
181184
config.WithCreateRBACPermissions(createRBACPermissions),
185+
config.WithEnableMultiInstrumentation(enableMultiInstrumentation),
182186
config.WithTargetAllocatorImage(targetAllocatorImage),
183187
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),
184188
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),
@@ -292,7 +296,7 @@ func main() {
292296
Handler: podmutation.NewWebhookHandler(cfg, ctrl.Log.WithName("pod-webhook"), decoder, mgr.GetClient(),
293297
[]podmutation.PodMutator{
294298
sidecar.NewMutator(logger, cfg, mgr.GetClient()),
295-
instrumentation.NewMutator(logger, mgr.GetClient(), mgr.GetEventRecorderFor("opentelemetry-operator")),
299+
instrumentation.NewMutator(logger, mgr.GetClient(), mgr.GetEventRecorderFor("opentelemetry-operator"), cfg),
296300
}),
297301
})
298302

pkg/instrumentation/golang.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
corev1 "k8s.io/api/core/v1"
2222

2323
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
24-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
24+
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2525
)
2626

2727
const (
@@ -31,7 +31,7 @@ const (
3131
kernelDebugVolumePath = "/sys/kernel/debug"
3232
)
3333

34-
func injectGoSDK(goSpec v1alpha1.Go, pod corev1.Pod) (corev1.Pod, error) {
34+
func injectGoSDK(goSpec v1alpha1.Go, pod corev1.Pod, cfg config.Config) (corev1.Pod, error) {
3535
// skip instrumentation if share process namespaces is explicitly disabled
3636
if pod.Spec.ShareProcessNamespace != nil && !*pod.Spec.ShareProcessNamespace {
3737
return pod, fmt.Errorf("shared process namespace has been explicitly disabled")
@@ -40,7 +40,7 @@ func injectGoSDK(goSpec v1alpha1.Go, pod corev1.Pod) (corev1.Pod, error) {
4040
// skip instrumentation when more than one containers provided
4141
containerNames := ""
4242
ok := false
43-
if featuregate.EnableMultiInstrumentationSupport.IsEnabled() {
43+
if cfg.EnableMultiInstrumentation() {
4444
containerNames, ok = pod.Annotations[annotationInjectGoContainersName]
4545
} else {
4646
containerNames, ok = pod.Annotations[annotationInjectContainerName]

pkg/instrumentation/golang_test.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import (
1919
"testing"
2020

2121
"github.com/stretchr/testify/assert"
22-
"github.com/stretchr/testify/require"
23-
colfeaturegate "go.opentelemetry.io/collector/featuregate"
2422
corev1 "k8s.io/api/core/v1"
2523
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2624

2725
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
28-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
26+
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2927
)
3028

3129
func TestInjectGoSDK(t *testing.T) {
@@ -36,10 +34,10 @@ func TestInjectGoSDK(t *testing.T) {
3634
tests := []struct {
3735
name string
3836
v1alpha1.Go
39-
pod corev1.Pod
40-
expected corev1.Pod
41-
err error
42-
setFeatureGates func(t *testing.T)
37+
pod corev1.Pod
38+
expected corev1.Pod
39+
err error
40+
config config.Config
4341
}{
4442
{
4543
name: "shared process namespace disabled",
@@ -73,14 +71,8 @@ func TestInjectGoSDK(t *testing.T) {
7371
},
7472
},
7573
},
76-
err: fmt.Errorf("go instrumentation cannot be injected into a pod, multiple containers configured"),
77-
setFeatureGates: func(t *testing.T) {
78-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
79-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
80-
t.Cleanup(func() {
81-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
82-
})
83-
},
74+
err: fmt.Errorf("go instrumentation cannot be injected into a pod, multiple containers configured"),
75+
config: config.New(config.WithEnableMultiInstrumentation(true)),
8476
},
8577
{
8678
name: "using container-names",
@@ -287,10 +279,7 @@ func TestInjectGoSDK(t *testing.T) {
287279

288280
for _, test := range tests {
289281
t.Run(test.name, func(t *testing.T) {
290-
if test.setFeatureGates != nil {
291-
test.setFeatureGates(t)
292-
}
293-
pod, err := injectGoSDK(test.Go, test.pod)
282+
pod, err := injectGoSDK(test.Go, test.pod, test.config)
294283
assert.Equal(t, test.expected, pod)
295284
assert.Equal(t, test.err, err)
296285
})

pkg/instrumentation/podmutator.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

2929
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
30+
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3031
"github.com/open-telemetry/opentelemetry-operator/internal/webhook/podmutation"
3132
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3233
)
@@ -41,6 +42,7 @@ type instPodMutator struct {
4142
sdkInjector *sdkInjector
4243
Logger logr.Logger
4344
Recorder record.EventRecorder
45+
config config.Config
4446
}
4547

4648
type instrumentationWithContainers struct {
@@ -193,7 +195,7 @@ func (langInsts *languageInstrumentations) setInstrumentationLanguageContainers(
193195

194196
var _ podmutation.PodMutator = (*instPodMutator)(nil)
195197

196-
func NewMutator(logger logr.Logger, client client.Client, recorder record.EventRecorder) *instPodMutator {
198+
func NewMutator(logger logr.Logger, client client.Client, recorder record.EventRecorder, cfg config.Config) *instPodMutator {
197199
return &instPodMutator{
198200
Logger: logger,
199201
Client: client,
@@ -202,6 +204,7 @@ func NewMutator(logger logr.Logger, client client.Client, recorder record.EventR
202204
client: client,
203205
},
204206
Recorder: recorder,
207+
config: cfg,
205208
}
206209
}
207210

@@ -323,7 +326,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
323326
}
324327

325328
// We retrieve the annotation for podname
326-
if featuregate.EnableMultiInstrumentationSupport.IsEnabled() {
329+
if pm.config.EnableMultiInstrumentation() {
327330
// We use annotations specific for instrumentation language
328331
insts.Java.Containers = annotationValue(ns.ObjectMeta, pod.ObjectMeta, annotationInjectJavaContainersName)
329332
insts.NodeJS.Containers = annotationValue(ns.ObjectMeta, pod.ObjectMeta, annotationInjectNodeJSContainersName)
@@ -357,7 +360,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
357360
// once it's been determined that instrumentation is desired, none exists yet, and we know which instance it should talk to,
358361
// we should inject the instrumentation.
359362
modifiedPod := pod
360-
modifiedPod = pm.sdkInjector.inject(ctx, insts, ns, modifiedPod)
363+
modifiedPod = pm.sdkInjector.inject(ctx, insts, ns, modifiedPod, pm.config)
361364

362365
return modifiedPod, nil
363366
}

pkg/instrumentation/podmutator_test.go

+11-44
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ import (
2828
"k8s.io/client-go/tools/record"
2929

3030
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
31+
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3132
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3233
)
3334

3435
func TestMutatePod(t *testing.T) {
35-
mutator := NewMutator(logr.Discard(), k8sClient, record.NewFakeRecorder(100))
36-
require.NotNil(t, mutator)
3736

3837
true := true
3938
zero := int64(0)
@@ -46,6 +45,7 @@ func TestMutatePod(t *testing.T) {
4645
inst v1alpha1.Instrumentation
4746
ns corev1.Namespace
4847
setFeatureGates func(t *testing.T)
48+
config config.Config
4949
}{
5050
{
5151
name: "javaagent injection, true",
@@ -2509,16 +2509,13 @@ func TestMutatePod(t *testing.T) {
25092509
},
25102510
},
25112511
},
2512+
config: config.New(config.WithEnableMultiInstrumentation(true)),
25122513
setFeatureGates: func(t *testing.T) {
25132514
originalVal := featuregate.EnableGoAutoInstrumentationSupport.IsEnabled()
2514-
mtVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
2515-
2516-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
25172515

25182516
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), true))
25192517
t.Cleanup(func() {
25202518
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal))
2521-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), mtVal))
25222519

25232520
})
25242521
},
@@ -3860,13 +3857,7 @@ func TestMutatePod(t *testing.T) {
38603857
},
38613858
},
38623859
},
3863-
setFeatureGates: func(t *testing.T) {
3864-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
3865-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
3866-
t.Cleanup(func() {
3867-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
3868-
})
3869-
},
3860+
config: config.New(config.WithEnableMultiInstrumentation(true)),
38703861
},
38713862
{
38723863
name: "multi instrumentation for multiple containers feature gate enabled, container-names not used",
@@ -4524,13 +4515,7 @@ func TestMutatePod(t *testing.T) {
45244515
},
45254516
},
45264517
},
4527-
setFeatureGates: func(t *testing.T) {
4528-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
4529-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
4530-
t.Cleanup(func() {
4531-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
4532-
})
4533-
},
4518+
config: config.New(config.WithEnableMultiInstrumentation(true)),
45344519
},
45354520
{
45364521
name: "multi instrumentation for multiple containers feature gate disabled, multiple instrumentation annotations set",
@@ -4684,13 +4669,7 @@ func TestMutatePod(t *testing.T) {
46844669
},
46854670
},
46864671
},
4687-
setFeatureGates: func(t *testing.T) {
4688-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
4689-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), false))
4690-
t.Cleanup(func() {
4691-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
4692-
})
4693-
},
4672+
config: config.New(config.WithEnableMultiInstrumentation(false)),
46944673
},
46954674
{
46964675
name: "multi instrumentation feature gate enabled, multiple instrumentation annotations set, no containers",
@@ -4834,13 +4813,7 @@ func TestMutatePod(t *testing.T) {
48344813
},
48354814
},
48364815
},
4837-
setFeatureGates: func(t *testing.T) {
4838-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
4839-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
4840-
t.Cleanup(func() {
4841-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
4842-
})
4843-
},
4816+
config: config.New(config.WithEnableMultiInstrumentation(true)),
48444817
},
48454818
{
48464819
name: "multi instrumentation feature gate enabled, single instrumentation annotation set, no containers",
@@ -5019,13 +4992,7 @@ func TestMutatePod(t *testing.T) {
50194992
},
50204993
},
50214994
},
5022-
setFeatureGates: func(t *testing.T) {
5023-
originalVal := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
5024-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
5025-
t.Cleanup(func() {
5026-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalVal))
5027-
})
5028-
},
4995+
config: config.New(config.WithEnableMultiInstrumentation(true)),
50294996
},
50304997
{
50314998
name: "multi instrumentation feature gate disabled, instrumentation feature gate disabled and annotation set, multiple specific containers set",
@@ -5125,13 +5092,11 @@ func TestMutatePod(t *testing.T) {
51255092
},
51265093
},
51275094
},
5095+
config: config.New(config.WithEnableMultiInstrumentation(true)),
51285096
setFeatureGates: func(t *testing.T) {
5129-
originalValMultiInstr := featuregate.EnableMultiInstrumentationSupport.IsEnabled()
5130-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), true))
51315097
originalValDotNetInstr := featuregate.EnableDotnetAutoInstrumentationSupport.IsEnabled()
51325098
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), false))
51335099
t.Cleanup(func() {
5134-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableMultiInstrumentationSupport.ID(), originalValMultiInstr))
51355100
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), originalValDotNetInstr))
51365101
})
51375102
},
@@ -5141,6 +5106,8 @@ func TestMutatePod(t *testing.T) {
51415106
for _, test := range tests {
51425107
test := test
51435108
t.Run(test.name, func(t *testing.T) {
5109+
mutator := NewMutator(logr.Discard(), k8sClient, record.NewFakeRecorder(100), test.config)
5110+
require.NotNil(t, mutator)
51445111
if test.setFeatureGates != nil {
51455112
test.setFeatureGates(t)
51465113
}

0 commit comments

Comments
 (0)