diff --git a/.chloggen/featuregates-into-cli-go.yaml b/.chloggen/featuregates-into-cli-go.yaml new file mode 100755 index 0000000000..0e39a4b37f --- /dev/null +++ b/.chloggen/featuregates-into-cli-go.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'breaking' + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: 'operator' + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: remove featuregate `operator.autoinstrumentation.go`. Use command line flag `--enable-go-instrumentation` instead + +# One or more tracking issues related to the change +issues: [2675] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 7ee5c89d79..b09eafa381 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -34,6 +34,8 @@ jobs: - e2e-multi-instrumentation - e2e-metadata-filters include: + - group: e2e-instrumentation + setup: "add-operator-arg OPERATOR_ARG=--enable-go-instrumentation prepare-e2e" - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" - group: e2e-metadata-filters diff --git a/internal/config/main.go b/internal/config/main.go index 03b00d2dbd..c3149b258b 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -47,6 +47,7 @@ type Config struct { enableMultiInstrumentation bool enableApacheHttpdInstrumentation bool enableDotNetInstrumentation bool + enableGoInstrumentation bool enableNginxInstrumentation bool enablePythonInstrumentation bool enableJavaInstrumentation bool @@ -89,6 +90,7 @@ func New(opts ...Option) Config { enableMultiInstrumentation: o.enableMultiInstrumentation, enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation, enableDotNetInstrumentation: o.enableDotNetInstrumentation, + enableGoInstrumentation: o.enableGoInstrumentation, enableNginxInstrumentation: o.enableNginxInstrumentation, enablePythonInstrumentation: o.enablePythonInstrumentation, enableJavaInstrumentation: o.enableJavaInstrumentation, @@ -149,6 +151,11 @@ func (c *Config) EnableDotNetAutoInstrumentation() bool { return c.enableDotNetInstrumentation } +// EnableGoAutoInstrumentation is true when the operator supports Go auto instrumentation. +func (c *Config) EnableGoAutoInstrumentation() bool { + return c.enableGoInstrumentation +} + // EnableNginxAutoInstrumentation is true when the operator supports nginx auto instrumentation. func (c *Config) EnableNginxAutoInstrumentation() bool { return c.enableNginxInstrumentation diff --git a/internal/config/options.go b/internal/config/options.go index 961cd8df65..daf5d69067 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -46,6 +46,7 @@ type options struct { enableMultiInstrumentation bool enableApacheHttpdInstrumentation bool enableDotNetInstrumentation bool + enableGoInstrumentation bool enableNginxInstrumentation bool enablePythonInstrumentation bool enableJavaInstrumentation bool @@ -104,6 +105,11 @@ func WithEnableDotNetInstrumentation(s bool) Option { o.enableDotNetInstrumentation = s } } +func WithEnableGoInstrumentation(s bool) Option { + return func(o *options) { + o.enableGoInstrumentation = s + } +} func WithEnableNginxInstrumentation(s bool) Option { return func(o *options) { o.enableNginxInstrumentation = s diff --git a/main.go b/main.go index 0d89d09b22..83bc6ef1a2 100644 --- a/main.go +++ b/main.go @@ -112,6 +112,7 @@ func main() { enableMultiInstrumentation bool enableApacheHttpdInstrumentation bool enableDotNetInstrumentation bool + enableGoInstrumentation bool enablePythonInstrumentation bool enableNginxInstrumentation bool enableJavaInstrumentation bool @@ -141,6 +142,7 @@ func main() { pflag.BoolVar(&enableMultiInstrumentation, "enable-multi-instrumentation", false, "Controls whether the operator supports multi instrumentation") pflag.BoolVar(&enableApacheHttpdInstrumentation, constants.FlagApacheHttpd, true, "Controls whether the operator supports Apache HTTPD auto-instrumentation") pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation") + pflag.BoolVar(&enableGoInstrumentation, constants.FlagGo, false, "Controls whether the operator supports Go auto-instrumentation") pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation") pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation") pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation") @@ -186,6 +188,7 @@ func main() { "enable-multi-instrumentation", enableMultiInstrumentation, "enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation, "enable-dotnet-instrumentation", enableDotNetInstrumentation, + "enable-go-instrumentation", enableGoInstrumentation, "enable-python-instrumentation", enablePythonInstrumentation, "enable-nginx-instrumentation", enableNginxInstrumentation, "enable-java-instrumentation", enableJavaInstrumentation, @@ -208,6 +211,7 @@ func main() { config.WithEnableMultiInstrumentation(enableMultiInstrumentation), config.WithEnableApacheHttpdInstrumentation(enableApacheHttpdInstrumentation), config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation), + config.WithEnableGoInstrumentation(enableGoInstrumentation), config.WithEnableNginxInstrumentation(enableNginxInstrumentation), config.WithEnablePythonInstrumentation(enablePythonInstrumentation), config.WithEnableJavaInstrumentation(enableJavaInstrumentation), diff --git a/pkg/constants/env.go b/pkg/constants/env.go index 76442a1846..fb15aa6ca4 100644 --- a/pkg/constants/env.go +++ b/pkg/constants/env.go @@ -39,6 +39,7 @@ const ( FlagApacheHttpd = "enable-apache-httpd-instrumentation" FlagDotNet = "enable-dotnet-instrumentation" + FlagGo = "enable-go-instrumentation" FlagPython = "enable-python-instrumentation" FlagNginx = "enable-nginx-instrumentation" FlagJava = "enable-java-instrumentation" diff --git a/pkg/featuregate/featuregate.go b/pkg/featuregate/featuregate.go index 9ff966a4f9..2e2798cc85 100644 --- a/pkg/featuregate/featuregate.go +++ b/pkg/featuregate/featuregate.go @@ -31,6 +31,12 @@ var ( featuregate.WithRegisterDescription("controls whether the operator supports NodeJS auto-instrumentation"), featuregate.WithRegisterFromVersion("v0.76.1"), ) + EnableNginxAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister( + "operator.autoinstrumentation.nginx", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("controls whether the operator supports Nginx auto-instrumentation"), + featuregate.WithRegisterFromVersion("v0.86.0"), + ) EnableGoAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister( "operator.autoinstrumentation.go", featuregate.StageAlpha, diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index b22bdad6dd..d82564cde3 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -278,7 +278,7 @@ func (pm *instPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod c logger.Error(err, "failed to select an OpenTelemetry Instrumentation instance for this pod") return pod, err } - if featuregate.EnableGoAutoInstrumentationSupport.IsEnabled() || inst == nil { + if pm.config.EnableGoAutoInstrumentation() || inst == nil { insts.Go.Instrumentation = inst } else { logger.Error(err, "support for Go auto instrumentation is not enabled") diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index d786e63c31..ffc69463a8 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -2721,16 +2721,7 @@ func TestMutatePod(t *testing.T) { }, }, }, - config: config.New(config.WithEnableMultiInstrumentation(true)), - setFeatureGates: func(t *testing.T) { - originalVal := featuregate.EnableGoAutoInstrumentationSupport.IsEnabled() - - require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), true)) - t.Cleanup(func() { - require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal)) - - }) - }, + config: config.New(config.WithEnableGoInstrumentation(true)), }, { name: "go injection feature gate disabled", @@ -2811,6 +2802,7 @@ func TestMutatePod(t *testing.T) { }, }, }, + config: config.New(config.WithEnableGoInstrumentation(false)), }, { name: "apache httpd injection, true", diff --git a/pkg/instrumentation/upgrade/upgrade.go b/pkg/instrumentation/upgrade/upgrade.go index 469c566440..aeedf119e6 100644 --- a/pkg/instrumentation/upgrade/upgrade.go +++ b/pkg/instrumentation/upgrade/upgrade.go @@ -33,7 +33,6 @@ import ( var ( defaultAnnotationToGate = map[string]*featuregate2.Gate{ constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport, - constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport, } ) @@ -60,6 +59,7 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde defaultAnnotationToConfig := map[string]autoInstConfig{ constants.AnnotationDefaultAutoInstrumentationApacheHttpd: {constants.FlagApacheHttpd, cfg.EnableApacheHttpdAutoInstrumentation()}, constants.AnnotationDefaultAutoInstrumentationDotNet: {constants.FlagDotNet, cfg.EnableDotNetAutoInstrumentation()}, + constants.AnnotationDefaultAutoInstrumentationGo: {constants.FlagGo, cfg.EnableGoAutoInstrumentation()}, constants.AnnotationDefaultAutoInstrumentationNginx: {constants.FlagNginx, cfg.EnableNginxAutoInstrumentation()}, constants.AnnotationDefaultAutoInstrumentationPython: {constants.FlagPython, cfg.EnablePythonAutoInstrumentation()}, constants.AnnotationDefaultAutoInstrumentationJava: {constants.FlagJava, cfg.EnableJavaAutoInstrumentation()}, @@ -132,6 +132,11 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru upgraded.Spec.DotNet.Image = u.DefaultAutoInstDotNet upgraded.Annotations[annotation] = u.DefaultAutoInstDotNet } + case constants.AnnotationDefaultAutoInstrumentationGo: + if inst.Spec.Go.Image == autoInst { + upgraded.Spec.Go.Image = u.DefaultAutoInstGo + upgraded.Annotations[annotation] = u.DefaultAutoInstGo + } case constants.AnnotationDefaultAutoInstrumentationNginx: if inst.Spec.Nginx.Image == autoInst { upgraded.Spec.Nginx.Image = u.DefaultAutoInstNginx diff --git a/pkg/instrumentation/upgrade/upgrade_test.go b/pkg/instrumentation/upgrade/upgrade_test.go index 9bb39f3893..bc52a4d3a4 100644 --- a/pkg/instrumentation/upgrade/upgrade_test.go +++ b/pkg/instrumentation/upgrade/upgrade_test.go @@ -22,7 +22,6 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - colfeaturegate "go.opentelemetry.io/collector/featuregate" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -32,16 +31,9 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/pkg/constants" - "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) func TestUpgrade(t *testing.T) { - originalVal := featuregate.EnableGoAutoInstrumentationSupport.IsEnabled() - require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), true)) - t.Cleanup(func() { - require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableGoAutoInstrumentationSupport.ID(), originalVal)) - }) - nsName := strings.ToLower(t.Name()) err := k8sClient.Create(context.Background(), &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ @@ -74,6 +66,7 @@ func TestUpgrade(t *testing.T) { config.WithAutoInstrumentationNginxImage("nginx:1"), config.WithEnableApacheHttpdInstrumentation(true), config.WithEnableDotNetInstrumentation(true), + config.WithEnableGoInstrumentation(true), config.WithEnableNginxInstrumentation(true), config.WithEnablePythonInstrumentation(true), config.WithEnableJavaInstrumentation(true), @@ -100,6 +93,7 @@ func TestUpgrade(t *testing.T) { config.WithAutoInstrumentationNginxImage("nginx:2"), config.WithEnableApacheHttpdInstrumentation(true), config.WithEnableDotNetInstrumentation(true), + config.WithEnableGoInstrumentation(true), config.WithEnableNginxInstrumentation(true), config.WithEnablePythonInstrumentation(true), config.WithEnableJavaInstrumentation(true),