Skip to content

Commit 6a0b11e

Browse files
authored
Python instrumentation featuregate to cli (open-telemetry#2751)
* remove python feature gate, use command-line instead * add chlog * fix python upgrade * fix typo at main * fix chlog
1 parent 1741863 commit 6a0b11e

File tree

10 files changed

+47
-15
lines changed

10 files changed

+47
-15
lines changed

.chloggen/featuregate_cli_python.yaml

+16
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.python`. Use command line flag `--enable-python-instrumentation` instead
9+
10+
# One or more tracking issues related to the change
11+
issues: [2582, 2672]
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

+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+
enablePythonInstrumentation bool
4950
autoInstrumentationDotNetImage string
5051
autoInstrumentationGoImage string
5152
autoInstrumentationApacheHttpdImage string
@@ -82,6 +83,7 @@ func New(opts ...Option) Config {
8283
enableMultiInstrumentation: o.enableMultiInstrumentation,
8384
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
8485
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
86+
enablePythonInstrumentation: o.enablePythonInstrumentation,
8587
targetAllocatorImage: o.targetAllocatorImage,
8688
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
8789
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -132,6 +134,11 @@ func (c *Config) EnableDotNetAutoInstrumentation() bool {
132134
return c.enableDotNetInstrumentation
133135
}
134136

137+
// EnablePythonAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
138+
func (c *Config) EnablePythonAutoInstrumentation() bool {
139+
return c.enablePythonInstrumentation
140+
}
141+
135142
// CollectorConfigMapEntry represents the configuration file name for the collector. Immutable.
136143
func (c *Config) CollectorConfigMapEntry() string {
137144
return c.collectorConfigMapEntry

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+
enablePythonInstrumentation bool
4849
targetAllocatorConfigMapEntry string
4950
operatorOpAMPBridgeConfigMapEntry string
5051
targetAllocatorImage string
@@ -99,6 +100,11 @@ func WithEnableDotNetInstrumentation(s bool) Option {
99100
o.enableDotNetInstrumentation = s
100101
}
101102
}
103+
func WithEnablePythonInstrumentation(s bool) Option {
104+
return func(o *options) {
105+
o.enablePythonInstrumentation = s
106+
}
107+
}
102108
func WithTargetAllocatorConfigMapEntry(s string) Option {
103109
return func(o *options) {
104110
o.targetAllocatorConfigMapEntry = s

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func main() {
112112
enableMultiInstrumentation bool
113113
enableApacheHttpdInstrumentation bool
114114
enableDotNetInstrumentation bool
115+
enablePythonInstrumentation bool
115116
collectorImage string
116117
targetAllocatorImage string
117118
operatorOpAMPBridgeImage string
@@ -138,6 +139,7 @@ func main() {
138139
pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation")
139140
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation")
140141
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
142+
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
141143
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.")
142144
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.")
143145
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.")
@@ -180,6 +182,7 @@ func main() {
180182
"enable-multi-instrumentation", enableMultiInstrumentation,
181183
"enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation,
182184
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
185+
"enable-python-instrumentation", enablePythonInstrumentation,
183186
)
184187

185188
restConfig := ctrl.GetConfigOrDie()
@@ -199,6 +202,7 @@ func main() {
199202
config.WithEnableMultiInstrumentation(enableMultiInstrumentation),
200203
config.WithEnableApacheHttpdInstrumentation(enableApacheHttpdInstrumentation),
201204
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
205+
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
202206
config.WithTargetAllocatorImage(targetAllocatorImage),
203207
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),
204208
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ const (
3737

3838
FlagApacheHttpd = "enable-apache-httpd-instrumentation"
3939
FlagDotNet = "enable-dotnet-instrumentation"
40+
FlagPython = "enable-python-instrumentation"
4041
)

pkg/featuregate/featuregate.go

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

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

pkg/instrumentation/podmutator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
253253
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
254254
return pod, err
255255
}
256-
if featuregate.EnablePythonAutoInstrumentationSupport.IsEnabled() || inst == nil {
256+
if pm.config.EnablePythonAutoInstrumentation() || inst == nil {
257257
insts.Python.Instrumentation = inst
258258
} else {
259259
logger.Error(nil, "support for Python auto instrumentation is not enabled")

pkg/instrumentation/podmutator_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ func TestMutatePod(t *testing.T) {
12661266
},
12671267
},
12681268
},
1269+
config: config.New(config.WithEnablePythonInstrumentation(true)),
12691270
},
12701271
{
12711272
name: "python injection multiple containers, true",
@@ -1533,6 +1534,7 @@ func TestMutatePod(t *testing.T) {
15331534
},
15341535
},
15351536
},
1537+
config: config.New(config.WithEnablePythonInstrumentation(true)),
15361538
},
15371539
{
15381540
name: "python injection feature gate disabled",
@@ -1619,13 +1621,6 @@ func TestMutatePod(t *testing.T) {
16191621
},
16201622
},
16211623
},
1622-
setFeatureGates: func(t *testing.T) {
1623-
originalVal := featuregate.EnablePythonAutoInstrumentationSupport.IsEnabled()
1624-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnablePythonAutoInstrumentationSupport.ID(), false))
1625-
t.Cleanup(func() {
1626-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnablePythonAutoInstrumentationSupport.ID(), originalVal))
1627-
})
1628-
},
16291624
},
16301625
{
16311626
name: "dotnet injection, true",
@@ -3844,6 +3839,7 @@ func TestMutatePod(t *testing.T) {
38443839
},
38453840
config: config.New(
38463841
config.WithEnableMultiInstrumentation(true),
3842+
config.WithEnablePythonInstrumentation(true),
38473843
config.WithEnableDotNetInstrumentation(true),
38483844
),
38493845
},
@@ -4506,6 +4502,7 @@ func TestMutatePod(t *testing.T) {
45064502
config: config.New(
45074503
config.WithEnableMultiInstrumentation(true),
45084504
config.WithEnableDotNetInstrumentation(true),
4505+
config.WithEnablePythonInstrumentation(true),
45094506
),
45104507
},
45114508
{

pkg/instrumentation/upgrade/upgrade.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var (
3434
defaultAnnotationToGate = map[string]*featuregate2.Gate{
3535
constants.AnnotationDefaultAutoInstrumentationJava: featuregate.EnableJavaAutoInstrumentationSupport,
3636
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
37-
constants.AnnotationDefaultAutoInstrumentationPython: featuregate.EnablePythonAutoInstrumentationSupport,
3837
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
3938
constants.AnnotationDefaultAutoInstrumentationNginx: featuregate.EnableNginxAutoInstrumentationSupport,
4039
}
@@ -63,6 +62,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
6362
defaultAnnotationToConfig := map[string]autoInstConfig{
6463
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: {constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()},
6564
constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()},
65+
constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()},
6666
}
6767

6868
return &InstrumentationUpgrade{
@@ -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.AnnotationDefaultAutoInstrumentationPython:
136+
if inst.Spec.Python.Image == autoInst {
137+
upgraded.Spec.Python.Image = u.DefaultAutoInstPython
138+
upgraded.Annotations[annotation] = u.DefaultAutoInstPython
139+
}
135140
}
136141
} else {
137142
u.Logger.Error(nil, "autoinstrumentation not enabled for this language", "flag", config.id)

pkg/instrumentation/upgrade/upgrade_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func TestUpgrade(t *testing.T) {
8080
config.WithAutoInstrumentationNginxImage("nginx:1"),
8181
config.WithEnableApacheHttpdInstrumentation(true),
8282
config.WithEnableDotNetInstrumentation(true),
83+
config.WithEnablePythonInstrumentation(true),
8384
),
8485
).Default(context.Background(), inst)
8586
assert.Nil(t, err)
@@ -103,6 +104,7 @@ func TestUpgrade(t *testing.T) {
103104
config.WithAutoInstrumentationNginxImage("nginx:2"),
104105
config.WithEnableApacheHttpdInstrumentation(true),
105106
config.WithEnableDotNetInstrumentation(true),
107+
config.WithEnablePythonInstrumentation(true),
106108
)
107109
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)
108110

0 commit comments

Comments
 (0)