Skip to content

Commit

Permalink
Merge branch 'main' into instrumentation-support-label
Browse files Browse the repository at this point in the history
# Conflicts:
#	bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
  • Loading branch information
crossoverJie committed Apr 2, 2024
2 parents 4025131 + d4b24f3 commit 50ab7a2
Show file tree
Hide file tree
Showing 27 changed files with 224 additions and 263 deletions.
16 changes: 16 additions & 0 deletions .chloggen/2788-fix-k8sattributes-rbac-creation.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: bug_fix

# 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: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix the RBAC resources creation when the processor was only enabled"

# One or more tracking issues related to the change
issues: [2788]

# (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:
16 changes: 16 additions & 0 deletions .chloggen/autoinstrumentation-nginx-cli-flag.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. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: change nginx instrumentation feature gate operator.autoinstrumentation.nginx into command line flag --enable-nginx-instrumentation

# One or more tracking issues related to the change
issues: [2582, 2676]

# (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:
16 changes: 16 additions & 0 deletions .chloggen/promote-rewrite-featuregate.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: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Promote `operator.collector.rewritetargetallocator` feature flag to stable

# One or more tracking issues related to the change
issues: [2796]

# (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: 1 addition & 1 deletion autoinstrumentation/java/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-03-25T15:02:49Z"
createdAt: "2024-03-25T08:38:05Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -487,7 +487,8 @@ spec:
- --enable-leader-election
- --zap-log-level=info
- --zap-time-encoding=rfc3339nano
- --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx
- --feature-gates=+operator.autoinstrumentation.go
- --enable-nginx-instrumentation=true
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0
livenessProbe:
httpGet:
Expand Down
3 changes: 2 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ spec:
- "--enable-leader-election"
- "--zap-log-level=info"
- "--zap-time-encoding=rfc3339nano"
- "--feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx"
- "--feature-gates=+operator.autoinstrumentation.go"
- "--enable-nginx-instrumentation=true"
image: controller
name: manager
livenessProbe:
Expand Down
27 changes: 7 additions & 20 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -109,26 +110,12 @@ func TestMain(m *testing.M) {
fmt.Printf("failed to start testEnv: %v", err)
os.Exit(1)
}
if err = monitoringv1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = networkingv1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = routev1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1alpha1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}
if err = v1beta1.AddToScheme(testScheme); err != nil {
fmt.Printf("failed to register scheme: %v", err)
os.Exit(1)
}

utilruntime.Must(monitoringv1.AddToScheme(testScheme))
utilruntime.Must(networkingv1.AddToScheme(testScheme))
utilruntime.Must(routev1.AddToScheme(testScheme))
utilruntime.Must(v1alpha1.AddToScheme(testScheme))
utilruntime.Must(v1beta1.AddToScheme(testScheme))

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
Expand Down
7 changes: 7 additions & 0 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
enableMultiInstrumentation bool
enableApacheHttpdInstrumentation bool
enableDotNetInstrumentation bool
enableNginxInstrumentation bool
enablePythonInstrumentation bool
autoInstrumentationDotNetImage string
autoInstrumentationGoImage string
Expand Down Expand Up @@ -83,6 +84,7 @@ func New(opts ...Option) Config {
enableMultiInstrumentation: o.enableMultiInstrumentation,
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
enableNginxInstrumentation: o.enableNginxInstrumentation,
enablePythonInstrumentation: o.enablePythonInstrumentation,
targetAllocatorImage: o.targetAllocatorImage,
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
Expand Down Expand Up @@ -134,6 +136,11 @@ func (c *Config) EnableDotNetAutoInstrumentation() bool {
return c.enableDotNetInstrumentation
}

// EnableNginxAutoInstrumentation is true when the operator supports nginx auto instrumentation.
func (c *Config) EnableNginxAutoInstrumentation() bool {
return c.enableNginxInstrumentation
}

// EnablePythonAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
func (c *Config) EnablePythonAutoInstrumentation() bool {
return c.enablePythonInstrumentation
Expand Down
6 changes: 6 additions & 0 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type options struct {
enableMultiInstrumentation bool
enableApacheHttpdInstrumentation bool
enableDotNetInstrumentation bool
enableNginxInstrumentation bool
enablePythonInstrumentation bool
targetAllocatorConfigMapEntry string
operatorOpAMPBridgeConfigMapEntry string
Expand Down Expand Up @@ -100,6 +101,11 @@ func WithEnableDotNetInstrumentation(s bool) Option {
o.enableDotNetInstrumentation = s
}
}
func WithEnableNginxInstrumentation(s bool) Option {
return func(o *options) {
o.enableNginxInstrumentation = s
}
}
func WithEnablePythonInstrumentation(s bool) Option {
return func(o *options) {
o.enablePythonInstrumentation = s
Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/collector/adapters/config_to_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[
}

if err != nil {
logger.V(2).Info("no parser found for '%s'", cmptName)
logger.V(2).Info("no parser found for", "component", cmptName)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/collector/adapters/config_to_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ConfigToRBAC(logger logr.Logger, config map[interface{}]interface{}) []rbac
processorName := key.(string)
processorParser, err := processor.For(logger, processorName, processorCfg)
if err != nil {
logger.V(2).Info("no parser found for '%s'", processorName)
logger.V(2).Info("no parser found for", "processor", processorName)
continue
}

Expand Down
61 changes: 1 addition & 60 deletions internal/manifests/collector/config_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,17 @@ import (
"os"
"testing"

"github.com/prometheus/prometheus/discovery/http"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
colfeaturegate "go.opentelemetry.io/collector/featuregate"
"gopkg.in/yaml.v2"

ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
)

func TestPrometheusParser(t *testing.T) {
param, err := newParams("test/test-img", "testdata/http_sd_config_test.yaml")
assert.NoError(t, err)

t.Run("should update config with http_sd_config", func(t *testing.T) {
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
require.NoError(t, err)
t.Cleanup(func() {
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
})
actualConfig, err := ReplaceConfig(param.OtelCol)
assert.NoError(t, err)

// prepare
var cfg Config
promCfgMap, err := ta.ConfigToPromConfig(actualConfig)
assert.NoError(t, err)

promCfg, err := yaml.Marshal(promCfgMap)
assert.NoError(t, err)

err = yaml.UnmarshalStrict(promCfg, &cfg)
assert.NoError(t, err)

// test
expectedMap := map[string]bool{
"prometheus": false,
"service-x": false,
}
for _, scrapeConfig := range cfg.PromConfig.ScrapeConfigs {
assert.Len(t, scrapeConfig.ServiceDiscoveryConfigs, 1)
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].Name(), "http")
assert.Equal(t, scrapeConfig.ServiceDiscoveryConfigs[0].(*http.SDConfig).URL, "http://test-targetallocator:80/jobs/"+scrapeConfig.JobName+"/targets?collector_id=$POD_NAME")
expectedMap[scrapeConfig.JobName] = true
}
for k := range expectedMap {
assert.True(t, expectedMap[k], k)
}
assert.True(t, cfg.TargetAllocConfig == nil)
})

t.Run("should update config with targetAllocator block if block not present", func(t *testing.T) {
// Set up the test scenario
param.OtelCol.Spec.TargetAllocator.Enabled = true
Expand Down Expand Up @@ -171,26 +131,7 @@ func TestReplaceConfig(t *testing.T) {
assert.YAMLEq(t, expectedConfig, actualConfig)
})

t.Run("should rewrite scrape configs with SD config when TargetAllocator is enabled and feature flag is not set", func(t *testing.T) {
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
require.NoError(t, err)
t.Cleanup(func() {
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
})

param.OtelCol.Spec.TargetAllocator.Enabled = true

expectedConfigBytes, err := os.ReadFile("testdata/relabel_config_expected_with_sd_config.yaml")
assert.NoError(t, err)
expectedConfig := string(expectedConfigBytes)

actualConfig, err := ReplaceConfig(param.OtelCol)
assert.NoError(t, err)

assert.YAMLEq(t, expectedConfig, actualConfig)
})

t.Run("should remove scrape configs if TargetAllocator is enabled and feature flag is set", func(t *testing.T) {
t.Run("should remove scrape configs if TargetAllocator is enabled", func(t *testing.T) {
param.OtelCol.Spec.TargetAllocator.Enabled = true

expectedConfigBytes, err := os.ReadFile("testdata/config_expected_targetallocator.yaml")
Expand Down
109 changes: 0 additions & 109 deletions internal/manifests/collector/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ package collector
import (
"testing"

colfeaturegate "go.opentelemetry.io/collector/featuregate"

"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
)

func TestDesiredConfigMap(t *testing.T) {
Expand Down Expand Up @@ -73,111 +69,6 @@ service:
}
})

t.Run("should return expected collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) {
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
assert.NoError(t, err)
t.Cleanup(func() {
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
})
expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
expectedLables["app.kubernetes.io/name"] = "test-collector"

expectedData := map[string]string{
"collector.yaml": `exporters:
debug:
receivers:
jaeger:
protocols:
grpc: null
prometheus:
config:
scrape_configs:
- http_sd_configs:
- url: http://test-targetallocator:80/jobs/otel-collector/targets?collector_id=$POD_NAME
job_name: otel-collector
scrape_interval: 10s
service:
pipelines:
metrics:
exporters:
- debug
processors: []
receivers:
- prometheus
- jaeger
`,
}

param := deploymentParams()
param.OtelCol.Spec.TargetAllocator.Enabled = true
actual, err := ConfigMap(param)

assert.NoError(t, err)
assert.Equal(t, "test-collector", actual.GetName())
assert.Equal(t, expectedLables, actual.GetLabels())
assert.Equal(t, len(expectedData), len(actual.Data))
for k, expected := range expectedData {
assert.YAMLEq(t, expected, actual.Data[k])
}

})

t.Run("should return expected escaped collector config map with http_sd_config if rewrite flag disabled", func(t *testing.T) {
err := colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), false)
assert.NoError(t, err)
t.Cleanup(func() {
_ = colfeaturegate.GlobalRegistry().Set(featuregate.EnableTargetAllocatorRewrite.ID(), true)
})

expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
expectedLables["app.kubernetes.io/name"] = "test-collector"
expectedLables["app.kubernetes.io/version"] = "latest"

expectedData := map[string]string{
"collector.yaml": `exporters:
debug:
receivers:
prometheus:
config:
scrape_configs:
- http_sd_configs:
- url: http://test-targetallocator:80/jobs/serviceMonitor%2Ftest%2Ftest%2F0/targets?collector_id=$POD_NAME
job_name: serviceMonitor/test/test/0
target_allocator:
collector_id: ${POD_NAME}
endpoint: http://test-targetallocator:80
http_sd_config:
refresh_interval: 60s
interval: 30s
service:
pipelines:
metrics:
exporters:
- debug
processors: []
receivers:
- prometheus
`,
}

param, err := newParams("test/test-img", "testdata/http_sd_config_servicemonitor_test_ta_set.yaml")
assert.NoError(t, err)
param.OtelCol.Spec.TargetAllocator.Enabled = true
actual, err := ConfigMap(param)

assert.NoError(t, err)
assert.Equal(t, "test-collector", actual.Name)
assert.Equal(t, expectedLables, actual.Labels)
assert.Equal(t, len(expectedData), len(actual.Data))
for k, expected := range expectedData {
assert.YAMLEq(t, expected, actual.Data[k])
}

// Reset the value
expectedLables["app.kubernetes.io/version"] = "0.47.0"

})

t.Run("should return expected escaped collector config map with target_allocator config block", func(t *testing.T) {
expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector"
expectedLables["app.kubernetes.io/name"] = "test-collector"
Expand Down
Loading

0 comments on commit 50ab7a2

Please sign in to comment.