Skip to content

Commit fbf82ed

Browse files
authored
feat: change java feature gate to cli flag (#2831)
* feat: change java feature gate to cli flag * fix test * set java to default enable * set enableJavaInstrumentation by default true * add call to config contructor in the java tests
1 parent 32f4fd2 commit fbf82ed

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
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: change java instrumentation feature gate operator.autoinstrumentation.java into command line flag --enable-java-instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [2673, 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:

internal/config/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
enableDotNetInstrumentation bool
5050
enableNginxInstrumentation bool
5151
enablePythonInstrumentation bool
52+
enableJavaInstrumentation bool
5253
autoInstrumentationDotNetImage string
5354
autoInstrumentationGoImage string
5455
autoInstrumentationApacheHttpdImage string
@@ -74,6 +75,7 @@ func New(opts ...Option) Config {
7475
operatorOpAMPBridgeConfigMapEntry: defaultOperatorOpAMPBridgeConfigMapEntry,
7576
logger: logf.Log.WithName("config"),
7677
version: version.Get(),
78+
enableJavaInstrumentation: true,
7779
}
7880
for _, opt := range opts {
7981
opt(&o)
@@ -89,6 +91,7 @@ func New(opts ...Option) Config {
8991
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
9092
enableNginxInstrumentation: o.enableNginxInstrumentation,
9193
enablePythonInstrumentation: o.enablePythonInstrumentation,
94+
enableJavaInstrumentation: o.enableJavaInstrumentation,
9295
targetAllocatorImage: o.targetAllocatorImage,
9396
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
9497
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -151,6 +154,11 @@ func (c *Config) EnableNginxAutoInstrumentation() bool {
151154
return c.enableNginxInstrumentation
152155
}
153156

157+
// EnableJavaAutoInstrumentation is true when the operator supports nginx auto instrumentation.
158+
func (c *Config) EnableJavaAutoInstrumentation() bool {
159+
return c.enableJavaInstrumentation
160+
}
161+
154162
// EnablePythonAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
155163
func (c *Config) EnablePythonAutoInstrumentation() bool {
156164
return c.enablePythonInstrumentation

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type options struct {
4848
enableDotNetInstrumentation bool
4949
enableNginxInstrumentation bool
5050
enablePythonInstrumentation bool
51+
enableJavaInstrumentation bool
5152
targetAllocatorConfigMapEntry string
5253
operatorOpAMPBridgeConfigMapEntry string
5354
targetAllocatorImage string
@@ -108,6 +109,11 @@ func WithEnableNginxInstrumentation(s bool) Option {
108109
o.enableNginxInstrumentation = s
109110
}
110111
}
112+
func WithEnableJavaInstrumentation(s bool) Option {
113+
return func(o *options) {
114+
o.enableJavaInstrumentation = s
115+
}
116+
}
111117
func WithEnablePythonInstrumentation(s bool) Option {
112118
return func(o *options) {
113119
o.enablePythonInstrumentation = s

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func main() {
114114
enableDotNetInstrumentation bool
115115
enablePythonInstrumentation bool
116116
enableNginxInstrumentation bool
117+
enableJavaInstrumentation bool
117118
collectorImage string
118119
targetAllocatorImage string
119120
operatorOpAMPBridgeImage string
@@ -142,6 +143,7 @@ func main() {
142143
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
143144
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
144145
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
146+
pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation")
145147
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.")
146148
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.")
147149
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.")
@@ -186,6 +188,7 @@ func main() {
186188
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
187189
"enable-python-instrumentation", enablePythonInstrumentation,
188190
"enable-nginx-instrumentation", enableNginxInstrumentation,
191+
"enable-java-instrumentation", enableJavaInstrumentation,
189192
)
190193

191194
restConfig := ctrl.GetConfigOrDie()
@@ -207,6 +210,7 @@ func main() {
207210
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
208211
config.WithEnableNginxInstrumentation(enableNginxInstrumentation),
209212
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
213+
config.WithEnableJavaInstrumentation(enableJavaInstrumentation),
210214
config.WithTargetAllocatorImage(targetAllocatorImage),
211215
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),
212216
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ const (
4141
FlagDotNet = "enable-dotnet-instrumentation"
4242
FlagPython = "enable-python-instrumentation"
4343
FlagNginx = "enable-nginx-instrumentation"
44+
FlagJava = "enable-java-instrumentation"
4445
)

pkg/featuregate/featuregate.go

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

2727
var (
28-
EnableJavaAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
29-
"operator.autoinstrumentation.java",
30-
featuregate.StageBeta,
31-
featuregate.WithRegisterDescription("controls whether the operator supports Java auto-instrumentation"),
32-
featuregate.WithRegisterFromVersion("v0.76.1"),
33-
)
3428
EnableNodeJSAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
3529
"operator.autoinstrumentation.nodejs",
3630
featuregate.StageBeta,

pkg/instrumentation/podmutator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
229229
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
230230
return pod, err
231231
}
232-
if featuregate.EnableJavaAutoInstrumentationSupport.IsEnabled() || inst == nil {
232+
if pm.config.EnableJavaAutoInstrumentation() || inst == nil {
233233
insts.Java.Instrumentation = inst
234234
} else {
235235
logger.Error(nil, "support for Java auto instrumentation is not enabled")

pkg/instrumentation/podmutator_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func TestMutatePod(t *testing.T) {
245245
},
246246
},
247247
},
248+
config: config.New(),
248249
},
249250
{
250251
name: "javaagent injection multiple containers, true",
@@ -540,6 +541,7 @@ func TestMutatePod(t *testing.T) {
540541
},
541542
},
542543
},
544+
config: config.New(),
543545
},
544546
{
545547
name: "javaagent injection feature gate disabled",
@@ -629,13 +631,7 @@ func TestMutatePod(t *testing.T) {
629631
},
630632
},
631633
},
632-
setFeatureGates: func(t *testing.T) {
633-
originalVal := featuregate.EnableJavaAutoInstrumentationSupport.IsEnabled()
634-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableJavaAutoInstrumentationSupport.ID(), false))
635-
t.Cleanup(func() {
636-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableJavaAutoInstrumentationSupport.ID(), originalVal))
637-
})
638-
},
634+
config: config.New(config.WithEnableJavaInstrumentation(false)),
639635
},
640636
{
641637
name: "nodejs injection, true",

pkg/instrumentation/upgrade/upgrade.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
var (
3434
defaultAnnotationToGate = map[string]*featuregate2.Gate{
35-
constants.AnnotationDefaultAutoInstrumentationJava: featuregate.EnableJavaAutoInstrumentationSupport,
3635
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
3736
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
3837
}
@@ -63,6 +62,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
6362
constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()},
6463
constants.AnnotationDefaultAutoInstrumentationNginx: {constants.FlagNginx, cfg.EnableNginxAutoInstrumentation()},
6564
constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()},
65+
constants.AnnotationDefaultAutoInstrumentationJava: {constants.FlagJava, cfg.EnableJavaAutoInstrumentation()},
6666
}
6767

6868
return &InstrumentationUpgrade{
@@ -142,6 +142,11 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
142142
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
143143
upgraded.Annotations[annotation] = u.DefaultAutoInstPython
144144
}
145+
case constants.AnnotationDefaultAutoInstrumentationJava:
146+
if inst.Spec.Java.Image == autoInst {
147+
upgraded.Spec.Java.Image = u.DefaultAutoInstJava
148+
upgraded.Annotations[annotation] = u.DefaultAutoInstJava
149+
}
145150
}
146151
} else {
147152
u.Logger.V(4).Info("autoinstrumentation not enabled for this language", "flag", instCfg.id)
@@ -154,11 +159,6 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru
154159
if autoInst != "" {
155160
if gate.IsEnabled() {
156161
switch annotation {
157-
case constants.AnnotationDefaultAutoInstrumentationJava:
158-
if inst.Spec.Java.Image == autoInst {
159-
upgraded.Spec.Java.Image = u.DefaultAutoInstJava
160-
upgraded.Annotations[annotation] = u.DefaultAutoInstJava
161-
}
162162
case constants.AnnotationDefaultAutoInstrumentationNodeJS:
163163
if inst.Spec.NodeJS.Image == autoInst {
164164
upgraded.Spec.NodeJS.Image = u.DefaultAutoInstNodeJS

pkg/instrumentation/upgrade/upgrade_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func TestUpgrade(t *testing.T) {
7676
config.WithEnableDotNetInstrumentation(true),
7777
config.WithEnableNginxInstrumentation(true),
7878
config.WithEnablePythonInstrumentation(true),
79+
config.WithEnableJavaInstrumentation(true),
7980
),
8081
).Default(context.Background(), inst)
8182
assert.Nil(t, err)
@@ -101,6 +102,7 @@ func TestUpgrade(t *testing.T) {
101102
config.WithEnableDotNetInstrumentation(true),
102103
config.WithEnableNginxInstrumentation(true),
103104
config.WithEnablePythonInstrumentation(true),
105+
config.WithEnableJavaInstrumentation(true),
104106
)
105107
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)
106108

0 commit comments

Comments
 (0)