Skip to content

Commit 830a0f7

Browse files
authored
chore: update dotnet instr. to command-line (open-telemetry#2690)
* chore: update `dotnet` instr. to command-line * fix: `.NET` pkg instrumentation upgrade * fix: remove `debug` logs * fix: pod mutator tests for `.NET` instrumentations * fix: using capital N for `DotNet`
1 parent 82b4585 commit 830a0f7

File tree

10 files changed

+66
-33
lines changed

10 files changed

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

internal/config/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Config struct {
4545
createRBACPermissions bool
4646
enableMultiInstrumentation bool
4747
enableApacheHttpdInstrumentation bool
48+
enableDotNetInstrumentation bool
4849
autoInstrumentationDotNetImage string
4950
autoInstrumentationGoImage string
5051
autoInstrumentationApacheHttpdImage string
@@ -79,6 +80,7 @@ func New(opts ...Option) Config {
7980
createRBACPermissions: o.createRBACPermissions,
8081
enableMultiInstrumentation: o.enableMultiInstrumentation,
8182
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
83+
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
8284
targetAllocatorImage: o.targetAllocatorImage,
8385
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
8486
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -118,10 +120,16 @@ func (c *Config) EnableMultiInstrumentation() bool {
118120
return c.enableMultiInstrumentation
119121
}
120122

123+
// EnableApacheHttpdAutoInstrumentation is true when the operator supports ApacheHttpd auto instrumentation.
121124
func (c *Config) EnableApacheHttpdAutoInstrumentation() bool {
122125
return c.enableApacheHttpdInstrumentation
123126
}
124127

128+
// EnableDotNetAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
129+
func (c *Config) EnableDotNetAutoInstrumentation() bool {
130+
return c.enableDotNetInstrumentation
131+
}
132+
125133
// CollectorConfigMapEntry represents the configuration file name for the collector. Immutable.
126134
func (c *Config) CollectorConfigMapEntry() string {
127135
return c.collectorConfigMapEntry

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type options struct {
4444
createRBACPermissions bool
4545
enableMultiInstrumentation bool
4646
enableApacheHttpdInstrumentation bool
47+
enableDotNetInstrumentation bool
4748
targetAllocatorConfigMapEntry string
4849
operatorOpAMPBridgeConfigMapEntry string
4950
targetAllocatorImage string
@@ -92,6 +93,11 @@ func WithEnableApacheHttpdInstrumentation(s bool) Option {
9293
o.enableApacheHttpdInstrumentation = s
9394
}
9495
}
96+
func WithEnableDotNetInstrumentation(s bool) Option {
97+
return func(o *options) {
98+
o.enableDotNetInstrumentation = s
99+
}
100+
}
95101
func WithTargetAllocatorConfigMapEntry(s string) Option {
96102
return func(o *options) {
97103
o.targetAllocatorConfigMapEntry = s

main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func main() {
109109
createRBACPermissions bool
110110
enableMultiInstrumentation bool
111111
enableApacheHttpdInstrumentation bool
112+
enableDotNetInstrumentation bool
112113
collectorImage string
113114
targetAllocatorImage string
114115
operatorOpAMPBridgeImage string
@@ -132,7 +133,8 @@ func main() {
132133
"Enabling this will ensure there is only one active controller manager.")
133134
pflag.BoolVar(&createRBACPermissions, "create-rbac-permissions", false, "Automatically create RBAC permissions needed by the processors")
134135
pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation")
135-
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "controls whether the operator supports Apache HTTPD auto-instrumentation")
136+
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation")
137+
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
136138
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.")
137139
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.")
138140
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.")
@@ -172,6 +174,7 @@ func main() {
172174
"labels-filter", labelsFilter,
173175
"enable-multi-instrumentation", enableMultiInstrumentation,
174176
"enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation,
177+
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
175178
)
176179

177180
restConfig := ctrl.GetConfigOrDie()
@@ -190,6 +193,7 @@ func main() {
190193
config.WithCreateRBACPermissions(createRBACPermissions),
191194
config.WithEnableMultiInstrumentation(enableMultiInstrumentation),
192195
config.WithEnableApacheHttpdInstrumentation(enableApacheHttpdInstrumentation),
196+
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
193197
config.WithTargetAllocatorImage(targetAllocatorImage),
194198
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),
195199
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ const (
3636
EnvNodeName = "OTEL_RESOURCE_ATTRIBUTES_NODE_NAME"
3737

3838
FlagApacheHttpd = "enable-apache-httpd-instrumentation"
39+
FlagDotNet = "enable-dotnet-instrumentation"
3940
)

pkg/featuregate/featuregate.go

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

2727
var (
28-
EnableDotnetAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
29-
"operator.autoinstrumentation.dotnet",
30-
featuregate.StageBeta,
31-
featuregate.WithRegisterDescription("controls whether the operator supports .NET auto-instrumentation"),
32-
featuregate.WithRegisterFromVersion("v0.76.1"),
33-
)
3428
EnablePythonAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
3529
"operator.autoinstrumentation.python",
3630
featuregate.StageBeta,

pkg/instrumentation/podmutator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
265265
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
266266
return pod, err
267267
}
268-
if featuregate.EnableDotnetAutoInstrumentationSupport.IsEnabled() || inst == nil {
268+
if pm.config.EnableDotNetAutoInstrumentation() || inst == nil {
269269
insts.DotNet.Instrumentation = inst
270270
insts.DotNet.AdditionalAnnotations = map[string]string{annotationDotNetRuntime: annotationValue(ns.ObjectMeta, pod.ObjectMeta, annotationDotNetRuntime)}
271271
} else {

pkg/instrumentation/podmutator_test.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,7 @@ func TestMutatePod(t *testing.T) {
18111811
},
18121812
},
18131813
},
1814+
config: config.New(config.WithEnableDotNetInstrumentation(true)),
18141815
},
18151816
{
18161817
name: "dotnet injection, by namespace annotations",
@@ -1990,6 +1991,7 @@ func TestMutatePod(t *testing.T) {
19901991
},
19911992
},
19921993
},
1994+
config: config.New(config.WithEnableDotNetInstrumentation(true)),
19931995
},
19941996
{
19951997
name: "dotnet injection multiple containers, true",
@@ -2265,6 +2267,7 @@ func TestMutatePod(t *testing.T) {
22652267
},
22662268
},
22672269
},
2270+
config: config.New(config.WithEnableDotNetInstrumentation(true)),
22682271
},
22692272
{
22702273
name: "dotnet injection feature gate disabled",
@@ -2343,13 +2346,7 @@ func TestMutatePod(t *testing.T) {
23432346
},
23442347
},
23452348
},
2346-
setFeatureGates: func(t *testing.T) {
2347-
originalVal := featuregate.EnableDotnetAutoInstrumentationSupport.IsEnabled()
2348-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), false))
2349-
t.Cleanup(func() {
2350-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), originalVal))
2351-
})
2352-
},
2349+
config: config.New(config.WithEnableDotNetInstrumentation(false)),
23532350
},
23542351
{
23552352
name: "go injection, true",
@@ -3845,7 +3842,10 @@ func TestMutatePod(t *testing.T) {
38453842
},
38463843
},
38473844
},
3848-
config: config.New(config.WithEnableMultiInstrumentation(true)),
3845+
config: config.New(
3846+
config.WithEnableMultiInstrumentation(true),
3847+
config.WithEnableDotNetInstrumentation(true),
3848+
),
38493849
},
38503850
{
38513851
name: "multi instrumentation for multiple containers feature gate enabled, container-names not used",
@@ -4503,7 +4503,10 @@ func TestMutatePod(t *testing.T) {
45034503
},
45044504
},
45054505
},
4506-
config: config.New(config.WithEnableMultiInstrumentation(true)),
4506+
config: config.New(
4507+
config.WithEnableMultiInstrumentation(true),
4508+
config.WithEnableDotNetInstrumentation(true),
4509+
),
45074510
},
45084511
{
45094512
name: "multi instrumentation for multiple containers feature gate disabled, multiple instrumentation annotations set",
@@ -4980,7 +4983,10 @@ func TestMutatePod(t *testing.T) {
49804983
},
49814984
},
49824985
},
4983-
config: config.New(config.WithEnableMultiInstrumentation(true)),
4986+
config: config.New(
4987+
config.WithEnableMultiInstrumentation(true),
4988+
config.WithEnableDotNetInstrumentation(true),
4989+
),
49844990
},
49854991
{
49864992
name: "multi instrumentation feature gate disabled, instrumentation feature gate disabled and annotation set, multiple specific containers set",
@@ -5080,14 +5086,10 @@ func TestMutatePod(t *testing.T) {
50805086
},
50815087
},
50825088
},
5083-
config: config.New(config.WithEnableMultiInstrumentation(true)),
5084-
setFeatureGates: func(t *testing.T) {
5085-
originalValDotNetInstr := featuregate.EnableDotnetAutoInstrumentationSupport.IsEnabled()
5086-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), false))
5087-
t.Cleanup(func() {
5088-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableDotnetAutoInstrumentationSupport.ID(), originalValDotNetInstr))
5089-
})
5090-
},
5089+
config: config.New(
5090+
config.WithEnableMultiInstrumentation(true),
5091+
config.WithEnableDotNetInstrumentation(false),
5092+
),
50915093
},
50925094
}
50935095

pkg/instrumentation/upgrade/upgrade.go

+7-7
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.AnnotationDefaultAutoInstrumentationPython: featuregate.EnablePythonAutoInstrumentationSupport,
38-
constants.AnnotationDefaultAutoInstrumentationDotNet: featuregate.EnableDotnetAutoInstrumentationSupport,
3938
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
4039
constants.AnnotationDefaultAutoInstrumentationNginx: featuregate.EnableNginxAutoInstrumentationSupport,
4140
}
@@ -62,7 +61,8 @@ type InstrumentationUpgrade struct {
6261

6362
func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorder record.EventRecorder, cfg config.Config) *InstrumentationUpgrade {
6463
defaultAnnotationToConfig := map[string]autoInstConfig{
65-
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: autoInstConfig{constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()},
64+
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: {constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()},
65+
constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()},
6666
}
6767

6868
return &InstrumentationUpgrade{
@@ -127,6 +127,11 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
127127
upgraded.Spec.ApacheHttpd.Image = u.DefaultAutoInstApacheHttpd
128128
upgraded.Annotations[annotation] = u.DefaultAutoInstApacheHttpd
129129
}
130+
case constants.AnnotationDefaultAutoInstrumentationDotNet:
131+
if inst.Spec.DotNet.Image == autoInst {
132+
upgraded.Spec.DotNet.Image = u.DefaultAutoInstDotNet
133+
upgraded.Annotations[annotation] = u.DefaultAutoInstDotNet
134+
}
130135
}
131136
} else {
132137
u.Logger.Error(nil, "autoinstrumentation not enabled for this language", "flag", config.id)
@@ -155,11 +160,6 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
155160
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
156161
upgraded.Annotations[annotation] = u.DefaultAutoInstPython
157162
}
158-
case constants.AnnotationDefaultAutoInstrumentationDotNet:
159-
if inst.Spec.DotNet.Image == autoInst {
160-
upgraded.Spec.DotNet.Image = u.DefaultAutoInstDotNet
161-
upgraded.Annotations[annotation] = u.DefaultAutoInstDotNet
162-
}
163163
case constants.AnnotationDefaultAutoInstrumentationGo:
164164
if inst.Spec.Go.Image == autoInst {
165165
upgraded.Spec.Go.Image = u.DefaultAutoInstGo

pkg/instrumentation/upgrade/upgrade_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestUpgrade(t *testing.T) {
7979
config.WithAutoInstrumentationApacheHttpdImage("apache-httpd:1"),
8080
config.WithAutoInstrumentationNginxImage("nginx:1"),
8181
config.WithEnableApacheHttpdInstrumentation(true),
82+
config.WithEnableDotNetInstrumentation(true),
8283
),
8384
).Default(context.Background(), inst)
8485
assert.Nil(t, err)
@@ -101,6 +102,7 @@ func TestUpgrade(t *testing.T) {
101102
config.WithAutoInstrumentationApacheHttpdImage("apache-httpd:2"),
102103
config.WithAutoInstrumentationNginxImage("nginx:2"),
103104
config.WithEnableApacheHttpdInstrumentation(true),
105+
config.WithEnableDotNetInstrumentation(true),
104106
)
105107
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)
106108

0 commit comments

Comments
 (0)