Skip to content

Commit

Permalink
Golang instrumentation featuregates into cli (#2750)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
yuriolisa authored Apr 26, 2024
1 parent 5bafbfd commit 16e1134
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 20 deletions.
16 changes: 16 additions & 0 deletions .chloggen/featuregates-into-cli-go.yaml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {
enableMultiInstrumentation bool
enableApacheHttpdInstrumentation bool
enableDotNetInstrumentation bool
enableGoInstrumentation bool
enableNginxInstrumentation bool
enablePythonInstrumentation bool
enableJavaInstrumentation bool
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type options struct {
enableMultiInstrumentation bool
enableApacheHttpdInstrumentation bool
enableDotNetInstrumentation bool
enableGoInstrumentation bool
enableNginxInstrumentation bool
enablePythonInstrumentation bool
enableJavaInstrumentation bool
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
enableMultiInstrumentation bool
enableApacheHttpdInstrumentation bool
enableDotNetInstrumentation bool
enableGoInstrumentation bool
enablePythonInstrumentation bool
enableNginxInstrumentation bool
enableJavaInstrumentation bool
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions pkg/featuregate/featuregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/instrumentation/podmutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 2 additions & 10 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -2811,6 +2802,7 @@ func TestMutatePod(t *testing.T) {
},
},
},
config: config.New(config.WithEnableGoInstrumentation(false)),
},
{
name: "apache httpd injection, true",
Expand Down
7 changes: 6 additions & 1 deletion pkg/instrumentation/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
var (
defaultAnnotationToGate = map[string]*featuregate2.Gate{
constants.AnnotationDefaultAutoInstrumentationNodeJS: featuregate.EnableNodeJSAutoInstrumentationSupport,
constants.AnnotationDefaultAutoInstrumentationGo: featuregate.EnableGoAutoInstrumentationSupport,
}
)

Expand All @@ -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()},
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions pkg/instrumentation/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 16e1134

Please sign in to comment.