diff --git a/.chloggen/addretrysetvalidation.yaml b/.chloggen/addretrysetvalidation.yaml new file mode 100755 index 00000000000..db6b49d0309 --- /dev/null +++ b/.chloggen/addretrysetvalidation.yaml @@ -0,0 +1,13 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: "enhancement" + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: "exporterhelper" + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add RetrySettings validation function" + +# One or more tracking issues or pull requests related to the change +issues: [9089] diff --git a/.chloggen/codeboten_make-otel-default.yaml b/.chloggen/codeboten_make-otel-default.yaml new file mode 100755 index 00000000000..a0bd1505c3e --- /dev/null +++ b/.chloggen/codeboten_make-otel-default.yaml @@ -0,0 +1,29 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Enable `telemetry.useOtelForInternalMetrics` by updating the flag to beta" + +# One or more tracking issues or pull requests related to the change +issues: [7454] + +# (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: | + The metrics generated should be consistent with the metrics generated + previously with OpenCensus. Users can disable the behaviour + by setting `--feature-gates -telemetry.useOtelForInternalMetrics` at + collector start. + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] \ No newline at end of file diff --git a/exporter/exporterhelper/obsexporter_test.go b/exporter/exporterhelper/obsexporter_test.go index 0bab9828360..769406741d8 100644 --- a/exporter/exporterhelper/obsexporter_test.go +++ b/exporter/exporterhelper/obsexporter_test.go @@ -180,6 +180,11 @@ type testParams struct { func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt obsreporttest.TestTelemetry, useOtel bool)) { t.Run("WithOC", func(t *testing.T) { + originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -188,11 +193,6 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt }) t.Run("WithOTel", func(t *testing.T) { - originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), true)) - defer func() { - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) - }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) diff --git a/exporter/exporterhelper/obsreport_test.go b/exporter/exporterhelper/obsreport_test.go index 8424c7f784e..b4c2e54d73e 100644 --- a/exporter/exporterhelper/obsreport_test.go +++ b/exporter/exporterhelper/obsreport_test.go @@ -11,6 +11,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/featuregate" + "go.opentelemetry.io/collector/internal/obsreportconfig" "go.opentelemetry.io/collector/obsreport/obsreporttest" ) @@ -26,6 +28,12 @@ func TestExportEnqueueFailure(t *testing.T) { }) require.NoError(t, err) + originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() + logRecords := int64(7) obsrep.recordEnqueueFailureWithOC(context.Background(), component.DataTypeLogs, logRecords) require.NoError(t, tt.CheckExporterEnqueueFailedLogs(logRecords)) diff --git a/exporter/exporterhelper/queue_sender_test.go b/exporter/exporterhelper/queue_sender_test.go index b3e3cf084ec..3fb8e47af33 100644 --- a/exporter/exporterhelper/queue_sender_test.go +++ b/exporter/exporterhelper/queue_sender_test.go @@ -144,6 +144,8 @@ func setFeatureGateForTest(t testing.TB, gate *featuregate.Gate, enabled bool) f } func TestQueuedRetry_QueueMetricsReported(t *testing.T) { + resetFlag := setFeatureGateForTest(t, obsreportconfig.UseOtelForInternalMetricsfeatureGate, false) + defer resetFlag() tt, err := obsreporttest.SetupTelemetry(defaultID) require.NoError(t, err) @@ -166,9 +168,6 @@ func TestQueuedRetry_QueueMetricsReported(t *testing.T) { } func TestQueuedRetry_QueueMetricsReportedUsingOTel(t *testing.T) { - resetFlag := setFeatureGateForTest(t, obsreportconfig.UseOtelForInternalMetricsfeatureGate, true) - defer resetFlag() - tt, err := obsreporttest.SetupTelemetry(defaultID) require.NoError(t, err) diff --git a/exporter/exporterhelper/retry_sender.go b/exporter/exporterhelper/retry_sender.go index 82ffce4389a..e437d50df0b 100644 --- a/exporter/exporterhelper/retry_sender.go +++ b/exporter/exporterhelper/retry_sender.go @@ -39,6 +39,28 @@ type RetrySettings struct { MaxElapsedTime time.Duration `mapstructure:"max_elapsed_time"` } +func (cfg *RetrySettings) Validate() error { + if !cfg.Enabled { + return nil + } + if cfg.InitialInterval < 0 { + return errors.New("'initial_interval' must be non-negative") + } + if cfg.RandomizationFactor < 0 || cfg.RandomizationFactor > 1 { + return errors.New("'randomization_factor' must be within [0, 1]") + } + if cfg.Multiplier <= 0 { + return errors.New("'multiplier' must be positive") + } + if cfg.MaxInterval < 0 { + return errors.New("'max_interval' must be non-negative") + } + if cfg.MaxElapsedTime < 0 { + return errors.New("'max_elapsed' time must be non-negative") + } + return nil +} + // NewDefaultRetrySettings returns the default settings for RetrySettings. func NewDefaultRetrySettings() RetrySettings { return RetrySettings{ diff --git a/exporter/exporterhelper/retry_sender_test.go b/exporter/exporterhelper/retry_sender_test.go index 9ecbb71906b..9169858c091 100644 --- a/exporter/exporterhelper/retry_sender_test.go +++ b/exporter/exporterhelper/retry_sender_test.go @@ -404,3 +404,66 @@ func tagsMatchLabelKeys(tags []tag.Tag, keys []metricdata.LabelKey, labels []met } return true } + +func TestNewDefaultRetrySettings(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + assert.Equal(t, + RetrySettings{ + Enabled: true, + InitialInterval: 5 * time.Second, + RandomizationFactor: 0.5, + Multiplier: 1.5, + MaxInterval: 30 * time.Second, + MaxElapsedTime: 5 * time.Minute, + }, cfg) +} + +func TestInvalidInitialInterval(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + cfg.InitialInterval = -1 + assert.Error(t, cfg.Validate()) +} + +func TestInvalidRandomizationFactor(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + cfg.RandomizationFactor = -1 + assert.Error(t, cfg.Validate()) + cfg.RandomizationFactor = 2 + assert.Error(t, cfg.Validate()) +} + +func TestInvalidMultiplier(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + cfg.Multiplier = 0 + assert.Error(t, cfg.Validate()) +} + +func TestInvalidMaxInterval(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + cfg.MaxInterval = -1 + assert.Error(t, cfg.Validate()) +} + +func TestInvalidMaxElapsedTime(t *testing.T) { + cfg := NewDefaultRetrySettings() + assert.NoError(t, cfg.Validate()) + cfg.MaxElapsedTime = -1 + assert.Error(t, cfg.Validate()) +} + +func TestDisabledWithInvalidValues(t *testing.T) { + cfg := RetrySettings{ + Enabled: false, + InitialInterval: -1, + RandomizationFactor: -1, + Multiplier: 0, + MaxInterval: -1, + MaxElapsedTime: -1, + } + assert.NoError(t, cfg.Validate()) +} diff --git a/internal/obsreportconfig/obsreportconfig.go b/internal/obsreportconfig/obsreportconfig.go index 7b970d81bf9..28ec8510ddb 100644 --- a/internal/obsreportconfig/obsreportconfig.go +++ b/internal/obsreportconfig/obsreportconfig.go @@ -17,7 +17,7 @@ import ( // telemetrySettings for internal metrics. var UseOtelForInternalMetricsfeatureGate = featuregate.GlobalRegistry().MustRegister( "telemetry.useOtelForInternalMetrics", - featuregate.StageAlpha, + featuregate.StageBeta, featuregate.WithRegisterDescription("controls whether the collector uses OpenTelemetry for internal metrics")) // DisableHighCardinalityMetricsfeatureGate is the feature gate that controls whether the collector should enable diff --git a/internal/obsreportconfig/obsreportconfig_test.go b/internal/obsreportconfig/obsreportconfig_test.go index 4156c5c01c6..3ec5745244a 100644 --- a/internal/obsreportconfig/obsreportconfig_test.go +++ b/internal/obsreportconfig/obsreportconfig_test.go @@ -7,11 +7,18 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config/configtelemetry" + "go.opentelemetry.io/collector/featuregate" ) func TestConfigure(t *testing.T) { + originalValue := UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() tests := []struct { name string level configtelemetry.Level diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 2cbcd712d22..b7b60c131bb 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -15,7 +15,7 @@ require ( go.opentelemetry.io/build-tools/multimod v0.12.0 go.opentelemetry.io/build-tools/semconvgen v0.12.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 - golang.org/x/tools v0.16.0 + golang.org/x/tools v0.16.1 golang.org/x/vuln v1.0.1 ) diff --git a/internal/tools/go.sum b/internal/tools/go.sum index cdd312c3f55..dcc32980bb4 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -932,8 +932,8 @@ golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= +golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/vuln v1.0.1 h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU= golang.org/x/vuln v1.0.1/go.mod h1:bb2hMwln/tqxg32BNY4CcxHWtHXuYa3SbIBmtsyjxtM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/processor/memorylimiterprocessor/config.go b/processor/memorylimiterprocessor/config.go index 3f526fb4f4f..940366741d8 100644 --- a/processor/memorylimiterprocessor/config.go +++ b/processor/memorylimiterprocessor/config.go @@ -6,11 +6,21 @@ package memorylimiterprocessor // import "go.opentelemetry.io/collector/processor/memorylimiterprocessor" import ( + "errors" "time" "go.opentelemetry.io/collector/component" ) +var ( + errCheckIntervalOutOfRange = errors.New("'check_interval' must be greater than zero") + errLimitOutOfRange = errors.New("'limit_mib' or 'limit_percentage' must be greater than zero") + errSpikeLimitOutOfRange = errors.New("'spike_limit_mib' must be smaller than 'limit_mib'") + errSpikeLimitPercentageOutOfRange = errors.New("'spike_limit_percentage' must be smaller than 'limit_percentage'") + errLimitPercentageOutOfRange = errors.New( + "'limit_percentage' and 'spike_limit_percentage' must be greater than zero and less than or equal to hundred") +) + // Config defines configuration for memory memoryLimiter processor. type Config struct { // CheckInterval is the time between measurements of memory usage for the @@ -46,13 +56,13 @@ func (cfg *Config) Validate() error { return errLimitOutOfRange } if cfg.MemoryLimitPercentage > 100 || cfg.MemorySpikePercentage > 100 { - return errPercentageLimitOutOfRange + return errLimitPercentageOutOfRange } if cfg.MemoryLimitMiB > 0 && cfg.MemoryLimitMiB <= cfg.MemorySpikeLimitMiB { - return errMemSpikeLimitOutOfRange + return errSpikeLimitOutOfRange } if cfg.MemoryLimitPercentage > 0 && cfg.MemoryLimitPercentage <= cfg.MemorySpikePercentage { - return errMemSpikePercentageLimitOutOfRange + return errSpikeLimitPercentageOutOfRange } return nil } diff --git a/processor/memorylimiterprocessor/config_test.go b/processor/memorylimiterprocessor/config_test.go index 37f9f7a51c5..d4d2e787b85 100644 --- a/processor/memorylimiterprocessor/config_test.go +++ b/processor/memorylimiterprocessor/config_test.go @@ -77,7 +77,7 @@ func TestConfigValidate(t *testing.T) { MemoryLimitMiB: 10, MemorySpikeLimitMiB: 10, }, - err: errMemSpikeLimitOutOfRange, + err: errSpikeLimitOutOfRange, }, { name: "invalid memory percentage limit", @@ -85,7 +85,7 @@ func TestConfigValidate(t *testing.T) { CheckInterval: 1 * time.Second, MemoryLimitPercentage: 101, }, - err: errPercentageLimitOutOfRange, + err: errLimitPercentageOutOfRange, }, { name: "invalid memory spike percentage limit", @@ -94,7 +94,7 @@ func TestConfigValidate(t *testing.T) { MemoryLimitPercentage: 50, MemorySpikePercentage: 60, }, - err: errMemSpikePercentageLimitOutOfRange, + err: errSpikeLimitPercentageOutOfRange, }, } for _, tt := range tests { diff --git a/processor/memorylimiterprocessor/memorylimiter.go b/processor/memorylimiterprocessor/memorylimiter.go index 6cf4a3e67f6..1e6c334472e 100644 --- a/processor/memorylimiterprocessor/memorylimiter.go +++ b/processor/memorylimiterprocessor/memorylimiter.go @@ -32,19 +32,6 @@ var ( // that data is being refused due to high memory usage. errDataRefused = errors.New("data refused due to high memory usage") - // Construction errors - - errCheckIntervalOutOfRange = errors.New("check_interval must be greater than zero") - - errLimitOutOfRange = errors.New("limit_mib or limit_percentage must be greater than zero") - - errMemSpikeLimitOutOfRange = errors.New("spike_limit_mib must be smaller than limit_mib") - - errMemSpikePercentageLimitOutOfRange = errors.New("spike_limit_percentage must be smaller than limit_percentage") - - errPercentageLimitOutOfRange = errors.New( - "limit_percentage and spike_limit_percentage must be greater than zero and less than or equal to hundred") - errShutdownNotStarted = errors.New("no existing monitoring routine is running") ) diff --git a/processor/processorhelper/obsreport_test.go b/processor/processorhelper/obsreport_test.go index d251bc9052b..3ba5418d050 100644 --- a/processor/processorhelper/obsreport_test.go +++ b/processor/processorhelper/obsreport_test.go @@ -101,6 +101,11 @@ func TestProcessorLogRecords(t *testing.T) { func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt obsreporttest.TestTelemetry, useOtel bool)) { t.Run("WithOC", func(t *testing.T) { + originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -109,11 +114,6 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt }) t.Run("WithOTel", func(t *testing.T) { - originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), true)) - defer func() { - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) - }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index bc7cd3738b7..2de4628455c 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -32,7 +32,6 @@ import ( "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" @@ -179,7 +178,7 @@ func TestJsonHttp(t *testing.T) { // Set the buffer count to 1 to make it flush the test span immediately. sink := &errOrSinkConsumer{TracesSink: new(consumertest.TracesSink)} - ocr := newHTTPReceiver(t, addr, tracesURLPath, metricsURLPath, logsURLPath, sink, nil) + ocr := newHTTPReceiver(t, componenttest.NewNopTelemetrySettings(), addr, tracesURLPath, metricsURLPath, logsURLPath, sink, nil) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost()), "Failed to start trace receiver") t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) @@ -469,7 +468,7 @@ func TestProtoHttp(t *testing.T) { // Set the buffer count to 1 to make it flush the test span immediately. tSink := &errOrSinkConsumer{TracesSink: new(consumertest.TracesSink)} - ocr := newHTTPReceiver(t, addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, tSink, consumertest.NewNop()) + ocr := newHTTPReceiver(t, componenttest.NewNopTelemetrySettings(), addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, tSink, consumertest.NewNop()) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost()), "Failed to start trace receiver") t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) @@ -617,7 +616,7 @@ func TestOTLPReceiverInvalidContentEncoding(t *testing.T) { // Set the buffer count to 1 to make it flush the test span immediately. tSink := new(consumertest.TracesSink) mSink := new(consumertest.MetricsSink) - ocr := newHTTPReceiver(t, addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, tSink, mSink) + ocr := newHTTPReceiver(t, componenttest.NewNopTelemetrySettings(), addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, tSink, mSink) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost()), "Failed to start trace receiver") t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) @@ -662,7 +661,7 @@ func TestGRPCNewPortAlreadyUsed(t *testing.T) { assert.NoError(t, ln.Close()) }) - r := newGRPCReceiver(t, addr, consumertest.NewNop(), consumertest.NewNop()) + r := newGRPCReceiver(t, componenttest.NewNopTelemetrySettings(), addr, consumertest.NewNop(), consumertest.NewNop()) require.NotNil(t, r) require.Error(t, r.Start(context.Background(), componenttest.NewNopHost())) @@ -676,7 +675,7 @@ func TestHTTPNewPortAlreadyUsed(t *testing.T) { assert.NoError(t, ln.Close()) }) - r := newHTTPReceiver(t, addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, consumertest.NewNop(), consumertest.NewNop()) + r := newHTTPReceiver(t, componenttest.NewNopTelemetrySettings(), addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, consumertest.NewNop(), consumertest.NewNop()) require.NotNil(t, r) require.Error(t, r.Start(context.Background(), componenttest.NewNopHost())) @@ -720,7 +719,7 @@ func TestOTLPReceiverGRPCTracesIngestTest(t *testing.T) { sink := &errOrSinkConsumer{TracesSink: new(consumertest.TracesSink)} - ocr := newGRPCReceiver(t, addr, sink, nil) + ocr := newGRPCReceiver(t, tt.TelemetrySettings, addr, sink, nil) require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) @@ -787,7 +786,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) { sink := &errOrSinkConsumer{TracesSink: new(consumertest.TracesSink)} - ocr := newHTTPReceiver(t, addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, sink, nil) + ocr := newHTTPReceiver(t, tt.TelemetrySettings, addr, defaultTracesURLPath, defaultMetricsURLPath, defaultLogsURLPath, sink, nil) require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) @@ -865,7 +864,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPC.NetAddr.Endpoint = addr cfg.HTTP = nil - ocr := newReceiver(t, factory, cfg, otlpReceiverID, sink, nil) + ocr := newReceiver(t, componenttest.NewNopTelemetrySettings(), factory, cfg, otlpReceiverID, sink, nil) require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) @@ -879,7 +878,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { require.NoError(t, ocr.Shutdown(context.Background())) cfg.GRPC.MaxRecvMsgSizeMiB = 100 - ocr = newReceiver(t, factory, cfg, otlpReceiverID, sink, nil) + ocr = newReceiver(t, componenttest.NewNopTelemetrySettings(), factory, cfg, otlpReceiverID, sink, nil) require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) @@ -976,15 +975,15 @@ func TestHTTPMaxRequestBodySize_TooLarge(t *testing.T) { testHTTPMaxRequestBodySizeJSON(t, traceJSON, len(traceJSON)-1, 400) } -func newGRPCReceiver(t *testing.T, endpoint string, tc consumer.Traces, mc consumer.Metrics) component.Component { +func newGRPCReceiver(t *testing.T, settings component.TelemetrySettings, endpoint string, tc consumer.Traces, mc consumer.Metrics) component.Component { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPC.NetAddr.Endpoint = endpoint cfg.HTTP = nil - return newReceiver(t, factory, cfg, otlpReceiverID, tc, mc) + return newReceiver(t, settings, factory, cfg, otlpReceiverID, tc, mc) } -func newHTTPReceiver(t *testing.T, endpoint string, tracesURLPath string, metricsURLPath string, logsURLPath string, tc consumer.Traces, mc consumer.Metrics) component.Component { +func newHTTPReceiver(t *testing.T, settings component.TelemetrySettings, endpoint string, tracesURLPath string, metricsURLPath string, logsURLPath string, tc consumer.Traces, mc consumer.Metrics) component.Component { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) cfg.HTTP.Endpoint = endpoint @@ -992,12 +991,12 @@ func newHTTPReceiver(t *testing.T, endpoint string, tracesURLPath string, metric cfg.HTTP.MetricsURLPath = metricsURLPath cfg.HTTP.LogsURLPath = logsURLPath cfg.GRPC = nil - return newReceiver(t, factory, cfg, otlpReceiverID, tc, mc) + return newReceiver(t, settings, factory, cfg, otlpReceiverID, tc, mc) } -func newReceiver(t *testing.T, factory receiver.Factory, cfg *Config, id component.ID, tc consumer.Traces, mc consumer.Metrics) component.Component { +func newReceiver(t *testing.T, settings component.TelemetrySettings, factory receiver.Factory, cfg *Config, id component.ID, tc consumer.Traces, mc consumer.Metrics) component.Component { set := receivertest.NewNopCreateSettings() - set.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal + set.TelemetrySettings = settings set.ID = id var r component.Component var err error diff --git a/receiver/receiverhelper/obsreport_test.go b/receiver/receiverhelper/obsreport_test.go index a99912f4ceb..02a8788161c 100644 --- a/receiver/receiverhelper/obsreport_test.go +++ b/receiver/receiverhelper/obsreport_test.go @@ -237,6 +237,11 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt obsreporttest.TestTelemetry, useOtel bool)) { t.Run("WithOC", func(t *testing.T) { + originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -245,11 +250,6 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt }) t.Run("WithOTel", func(t *testing.T) { - originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), true)) - defer func() { - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) - }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) diff --git a/receiver/scraperhelper/obsreport_test.go b/receiver/scraperhelper/obsreport_test.go index 4adbf981654..f109a05364c 100644 --- a/receiver/scraperhelper/obsreport_test.go +++ b/receiver/scraperhelper/obsreport_test.go @@ -94,6 +94,11 @@ func TestScrapeMetricsDataOp(t *testing.T) { func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt obsreporttest.TestTelemetry, useOtel bool)) { t.Run("WithOC", func(t *testing.T) { + originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), false)) + defer func() { + require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) + }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -102,11 +107,6 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt }) t.Run("WithOTel", func(t *testing.T) { - originalValue := obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), true)) - defer func() { - require.NoError(t, featuregate.GlobalRegistry().Set(obsreportconfig.UseOtelForInternalMetricsfeatureGate.ID(), originalValue)) - }() tt, err := obsreporttest.SetupTelemetry(id) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })