Skip to content

Commit 16e1134

Browse files
authored
Golang instrumentation featuregates into cli (#2750)
* Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed featuregate into CLI - instrumentation go Signed-off-by: Yuri Sa <[email protected]> * Changed e2e job Signed-off-by: Yuri Sa <[email protected]> --------- Signed-off-by: Yuri Sa <[email protected]>
1 parent 5bafbfd commit 16e1134

File tree

11 files changed

+53
-20
lines changed

11 files changed

+53
-20
lines changed
+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.go`. Use command line flag `--enable-go-instrumentation` instead
9+
10+
# One or more tracking issues related to the change
11+
issues: [2675]
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
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
- e2e-multi-instrumentation
3535
- e2e-metadata-filters
3636
include:
37+
- group: e2e-instrumentation
38+
setup: "add-operator-arg OPERATOR_ARG=--enable-go-instrumentation prepare-e2e"
3739
- group: e2e-multi-instrumentation
3840
setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e"
3941
- group: e2e-metadata-filters

internal/config/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Config struct {
4747
enableMultiInstrumentation bool
4848
enableApacheHttpdInstrumentation bool
4949
enableDotNetInstrumentation bool
50+
enableGoInstrumentation bool
5051
enableNginxInstrumentation bool
5152
enablePythonInstrumentation bool
5253
enableJavaInstrumentation bool
@@ -89,6 +90,7 @@ func New(opts ...Option) Config {
8990
enableMultiInstrumentation: o.enableMultiInstrumentation,
9091
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
9192
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
93+
enableGoInstrumentation: o.enableGoInstrumentation,
9294
enableNginxInstrumentation: o.enableNginxInstrumentation,
9395
enablePythonInstrumentation: o.enablePythonInstrumentation,
9496
enableJavaInstrumentation: o.enableJavaInstrumentation,
@@ -149,6 +151,11 @@ func (c *Config) EnableDotNetAutoInstrumentation() bool {
149151
return c.enableDotNetInstrumentation
150152
}
151153

154+
// EnableGoAutoInstrumentation is true when the operator supports Go auto instrumentation.
155+
func (c *Config) EnableGoAutoInstrumentation() bool {
156+
return c.enableGoInstrumentation
157+
}
158+
152159
// EnableNginxAutoInstrumentation is true when the operator supports nginx auto instrumentation.
153160
func (c *Config) EnableNginxAutoInstrumentation() bool {
154161
return c.enableNginxInstrumentation

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type options struct {
4646
enableMultiInstrumentation bool
4747
enableApacheHttpdInstrumentation bool
4848
enableDotNetInstrumentation bool
49+
enableGoInstrumentation bool
4950
enableNginxInstrumentation bool
5051
enablePythonInstrumentation bool
5152
enableJavaInstrumentation bool
@@ -104,6 +105,11 @@ func WithEnableDotNetInstrumentation(s bool) Option {
104105
o.enableDotNetInstrumentation = s
105106
}
106107
}
108+
func WithEnableGoInstrumentation(s bool) Option {
109+
return func(o *options) {
110+
o.enableGoInstrumentation = s
111+
}
112+
}
107113
func WithEnableNginxInstrumentation(s bool) Option {
108114
return func(o *options) {
109115
o.enableNginxInstrumentation = 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+
enableGoInstrumentation bool
115116
enablePythonInstrumentation bool
116117
enableNginxInstrumentation bool
117118
enableJavaInstrumentation bool
@@ -141,6 +142,7 @@ func main() {
141142
pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation")
142143
pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation")
143144
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
145+
pflag.BoolVar(&enableGoInstrumentation, constants.FlagGo, false, "Controls whether the operator supports Go auto-instrumentation")
144146
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
145147
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
146148
pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation")
@@ -186,6 +188,7 @@ func main() {
186188
"enable-multi-instrumentation", enableMultiInstrumentation,
187189
"enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation,
188190
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
191+
"enable-go-instrumentation", enableGoInstrumentation,
189192
"enable-python-instrumentation", enablePythonInstrumentation,
190193
"enable-nginx-instrumentation", enableNginxInstrumentation,
191194
"enable-java-instrumentation", enableJavaInstrumentation,
@@ -208,6 +211,7 @@ func main() {
208211
config.WithEnableMultiInstrumentation(enableMultiInstrumentation),
209212
config.WithEnableApacheHttpdInstrumentation(enableApacheHttpdInstrumentation),
210213
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
214+
config.WithEnableGoInstrumentation(enableGoInstrumentation),
211215
config.WithEnableNginxInstrumentation(enableNginxInstrumentation),
212216
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
213217
config.WithEnableJavaInstrumentation(enableJavaInstrumentation),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939

4040
FlagApacheHttpd = "enable-apache-httpd-instrumentation"
4141
FlagDotNet = "enable-dotnet-instrumentation"
42+
FlagGo = "enable-go-instrumentation"
4243
FlagPython = "enable-python-instrumentation"
4344
FlagNginx = "enable-nginx-instrumentation"
4445
FlagJava = "enable-java-instrumentation"

pkg/featuregate/featuregate.go

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ var (
3131
featuregate.WithRegisterDescription("controls whether the operator supports NodeJS auto-instrumentation"),
3232
featuregate.WithRegisterFromVersion("v0.76.1"),
3333
)
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+
)
3440
EnableGoAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
3541
"operator.autoinstrumentation.go",
3642
featuregate.StageAlpha,

pkg/instrumentation/podmutator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c
278278
logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod")
279279
return pod, err
280280
}
281-
if featuregate.EnableGoAutoInstrumentationSupport.IsEnabled() || inst == nil {
281+
if pm.config.EnableGoAutoInstrumentation() || inst == nil {
282282
insts.Go.Instrumentation = inst
283283
} else {
284284
logger.Error(err, "support for Go auto instrumentation is not enabled")

pkg/instrumentation/podmutator_test.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -2721,16 +2721,7 @@ func TestMutatePod(t *testing.T) {
27212721
},
27222722
},
27232723
},
2724-
config: config.New(config.WithEnableMultiInstrumentation(true)),
2725-
setFeatureGates: func(t *testing.T) {
2726-
originalVal := featuregate.EnableGoAutoInstrumentationSupport.IsEnabled()
2727-
2728-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), true))
2729-
t.Cleanup(func() {
2730-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal))
2731-
2732-
})
2733-
},
2724+
config: config.New(config.WithEnableGoInstrumentation(true)),
27342725
},
27352726
{
27362727
name: "go injection feature gate disabled",
@@ -2811,6 +2802,7 @@ func TestMutatePod(t *testing.T) {
28112802
},
28122803
},
28132804
},
2805+
config: config.New(config.WithEnableGoInstrumentation(false)),
28142806
},
28152807
{
28162808
name: "apache httpd injection, true",

pkg/instrumentation/upgrade/upgrade.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
var (
3434
defaultAnnotationToGate = map[string]*featuregate2.Gate{
3535
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
36-
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
3736
}
3837
)
3938

@@ -60,6 +59,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
6059
defaultAnnotationToConfig := map[string]autoInstConfig{
6160
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: {constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()},
6261
constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()},
62+
constants.AnnotationDefaultAutoInstrumentationGo: {constants.FlagGo, cfg.EnableGoAutoInstrumentation()},
6363
constants.AnnotationDefaultAutoInstrumentationNginx: {constants.FlagNginx, cfg.EnableNginxAutoInstrumentation()},
6464
constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()},
6565
constants.AnnotationDefaultAutoInstrumentationJava: {constants.FlagJava, cfg.EnableJavaAutoInstrumentation()},
@@ -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.AnnotationDefaultAutoInstrumentationGo:
136+
if inst.Spec.Go.Image == autoInst {
137+
upgraded.Spec.Go.Image = u.DefaultAutoInstGo
138+
upgraded.Annotations[annotation] = u.DefaultAutoInstGo
139+
}
135140
case constants.AnnotationDefaultAutoInstrumentationNginx:
136141
if inst.Spec.Nginx.Image == autoInst {
137142
upgraded.Spec.Nginx.Image = u.DefaultAutoInstNginx

pkg/instrumentation/upgrade/upgrade_test.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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/apimachinery/pkg/types"
@@ -32,16 +31,9 @@ import (
3231
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
3332
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3433
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
35-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3634
)
3735

3836
func TestUpgrade(t *testing.T) {
39-
originalVal := featuregate.EnableGoAutoInstrumentationSupport.IsEnabled()
40-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), true))
41-
t.Cleanup(func() {
42-
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal))
43-
})
44-
4537
nsName := strings.ToLower(t.Name())
4638
err := k8sClient.Create(context.Background(), &corev1.Namespace{
4739
ObjectMeta: metav1.ObjectMeta{
@@ -74,6 +66,7 @@ func TestUpgrade(t *testing.T) {
7466
config.WithAutoInstrumentationNginxImage("nginx:1"),
7567
config.WithEnableApacheHttpdInstrumentation(true),
7668
config.WithEnableDotNetInstrumentation(true),
69+
config.WithEnableGoInstrumentation(true),
7770
config.WithEnableNginxInstrumentation(true),
7871
config.WithEnablePythonInstrumentation(true),
7972
config.WithEnableJavaInstrumentation(true),
@@ -100,6 +93,7 @@ func TestUpgrade(t *testing.T) {
10093
config.WithAutoInstrumentationNginxImage("nginx:2"),
10194
config.WithEnableApacheHttpdInstrumentation(true),
10295
config.WithEnableDotNetInstrumentation(true),
96+
config.WithEnableGoInstrumentation(true),
10397
config.WithEnableNginxInstrumentation(true),
10498
config.WithEnablePythonInstrumentation(true),
10599
config.WithEnableJavaInstrumentation(true),

0 commit comments

Comments
 (0)