From 970b76cc794a48c7b14c691fb84699e1458937b1 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 4 May 2021 14:32:19 -0700 Subject: [PATCH] Use config.ComponentID in obsreport exporter settings (#3091) Signed-off-by: Bogdan Drutu --- exporter/exporterhelper/logshelper.go | 4 ++-- exporter/exporterhelper/logshelper_test.go | 5 +++-- exporter/exporterhelper/metricshelper.go | 4 ++-- exporter/exporterhelper/metricshelper_test.go | 4 ++-- exporter/exporterhelper/tracehelper.go | 4 ++-- exporter/exporterhelper/tracehelper_test.go | 4 ++-- exporter/prometheusexporter/prometheus.go | 4 ++-- obsreport/obsreport_exporter.go | 12 ++++++------ obsreport/obsreport_test.go | 14 +++++++------- obsreport/obsreporttest/obsreporttest.go | 12 ++++++------ obsreport/obsreporttest/obsreporttest_test.go | 18 +++++++++++------- 11 files changed, 45 insertions(+), 40 deletions(-) diff --git a/exporter/exporterhelper/logshelper.go b/exporter/exporterhelper/logshelper.go index 01152ece543c..289528645351 100644 --- a/exporter/exporterhelper/logshelper.go +++ b/exporter/exporterhelper/logshelper.go @@ -93,8 +93,8 @@ func NewLogsExporter( be.wrapConsumerSender(func(nextSender requestSender) requestSender { return &logsExporterWithObservability{ obsrep: obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.GetMetricsLevelFlagValue(), - ExporterName: cfg.ID().String(), + Level: configtelemetry.GetMetricsLevelFlagValue(), + ExporterID: cfg.ID(), }), nextSender: nextSender, } diff --git a/exporter/exporterhelper/logshelper_test.go b/exporter/exporterhelper/logshelper_test.go index 560d13966316..334694be0198 100644 --- a/exporter/exporterhelper/logshelper_test.go +++ b/exporter/exporterhelper/logshelper_test.go @@ -33,12 +33,13 @@ import ( ) const ( - fakeLogsExporterName = "fake_logs_exporter/with_name" fakeLogsParentSpanName = "fake_logs_parent_span_name" ) +var fakeLogsExporterName = config.MustIDFromString("fake_logs_exporter/with_name") + var ( - fakeLogsExporterConfig = config.NewExporterSettings(config.MustIDFromString(fakeLogsExporterName)) + fakeLogsExporterConfig = config.NewExporterSettings(fakeLogsExporterName) ) func TestLogsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/metricshelper.go b/exporter/exporterhelper/metricshelper.go index 48ccdbc3547e..a895bfa0af4e 100644 --- a/exporter/exporterhelper/metricshelper.go +++ b/exporter/exporterhelper/metricshelper.go @@ -97,8 +97,8 @@ func NewMetricsExporter( be.wrapConsumerSender(func(nextSender requestSender) requestSender { return &metricsSenderWithObservability{ obsrep: obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.GetMetricsLevelFlagValue(), - ExporterName: cfg.ID().String(), + Level: configtelemetry.GetMetricsLevelFlagValue(), + ExporterID: cfg.ID(), }), nextSender: nextSender, } diff --git a/exporter/exporterhelper/metricshelper_test.go b/exporter/exporterhelper/metricshelper_test.go index 1bbe4f2542bf..88d6e49a4a6e 100644 --- a/exporter/exporterhelper/metricshelper_test.go +++ b/exporter/exporterhelper/metricshelper_test.go @@ -33,12 +33,12 @@ import ( ) const ( - fakeMetricsExporterName = "fake_metrics_exporter/with_name" fakeMetricsParentSpanName = "fake_metrics_parent_span_name" ) var ( - fakeMetricsExporterConfig = config.NewExporterSettings(config.MustIDFromString(fakeMetricsExporterName)) + fakeMetricsExporterName = config.MustIDFromString("fake_metrics_exporter/with_name") + fakeMetricsExporterConfig = config.NewExporterSettings(fakeMetricsExporterName) ) func TestMetricsRequest(t *testing.T) { diff --git a/exporter/exporterhelper/tracehelper.go b/exporter/exporterhelper/tracehelper.go index bbbf174d47c6..bd9177c1ccd0 100644 --- a/exporter/exporterhelper/tracehelper.go +++ b/exporter/exporterhelper/tracehelper.go @@ -95,8 +95,8 @@ func NewTracesExporter( return &tracesExporterWithObservability{ obsrep: obsreport.NewExporter( obsreport.ExporterSettings{ - Level: configtelemetry.GetMetricsLevelFlagValue(), - ExporterName: cfg.ID().String(), + Level: configtelemetry.GetMetricsLevelFlagValue(), + ExporterID: cfg.ID(), }), nextSender: nextSender, } diff --git a/exporter/exporterhelper/tracehelper_test.go b/exporter/exporterhelper/tracehelper_test.go index 9e9333d12399..414ab5eaa69f 100644 --- a/exporter/exporterhelper/tracehelper_test.go +++ b/exporter/exporterhelper/tracehelper_test.go @@ -34,12 +34,12 @@ import ( ) const ( - fakeTracesExporterName = "fake_traces_exporter/with_name" fakeTraceParentSpanName = "fake_trace_parent_span_name" ) var ( - fakeTracesExporterConfig = config.NewExporterSettings(config.MustIDFromString(fakeTracesExporterName)) + fakeTracesExporterName = config.MustIDFromString("fake_traces_exporter/with_name") + fakeTracesExporterConfig = config.NewExporterSettings(fakeTracesExporterName) ) func TestTracesRequest(t *testing.T) { diff --git a/exporter/prometheusexporter/prometheus.go b/exporter/prometheusexporter/prometheus.go index 8b9a1eb1ca8e..9fbf78fde3ec 100644 --- a/exporter/prometheusexporter/prometheus.go +++ b/exporter/prometheusexporter/prometheus.go @@ -50,8 +50,8 @@ func newPrometheusExporter(config *Config, logger *zap.Logger) (*prometheusExpor } obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.GetMetricsLevelFlagValue(), - ExporterName: config.ID().String(), + Level: configtelemetry.GetMetricsLevelFlagValue(), + ExporterID: config.ID(), }) collector := newCollector(config, logger) diff --git a/obsreport/obsreport_exporter.go b/obsreport/obsreport_exporter.go index 2a339e53bd7f..1d8f54976320 100644 --- a/obsreport/obsreport_exporter.go +++ b/obsreport/obsreport_exporter.go @@ -21,6 +21,7 @@ import ( "go.opencensus.io/tag" "go.opencensus.io/trace" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" ) @@ -92,17 +93,16 @@ type Exporter struct { // ExporterSettings are settings for creating an Exporter. type ExporterSettings struct { - Level configtelemetry.Level - ExporterName string + Level configtelemetry.Level + ExporterID config.ComponentID } // NewExporter creates a new Exporter. func NewExporter(cfg ExporterSettings) *Exporter { - level, exporterName := cfg.Level, cfg.ExporterName return &Exporter{ - level: level, - exporterName: exporterName, - mutators: []tag.Mutator{tag.Upsert(tagKeyExporter, exporterName, tag.WithTTL(tag.TTLNoPropagation))}, + level: cfg.Level, + exporterName: cfg.ExporterID.String(), + mutators: []tag.Mutator{tag.Upsert(tagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))}, } } diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index e7ea32e5501d..8c923505aaaf 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -36,7 +36,6 @@ import ( ) const ( - exporter = "fakeExporter" receiver = "fakeReicever" scraper = "fakeScraper" transport = "fakeTransport" @@ -45,6 +44,7 @@ const ( var ( processor = config.NewID("fakeProcessor") + exporter = config.NewID("fakeExporter") errFake = errors.New("errFake") partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1) @@ -340,7 +340,7 @@ func TestExportTraceDataOp(t *testing.T) { t.Name(), trace.WithSampler(trace.AlwaysSample())) defer parentSpan.End() - obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterName: exporter}) + obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterID: exporter}) errs := []error{nil, errFake} numExportedSpans := []int{22, 14} for i, err := range errs { @@ -354,7 +354,7 @@ func TestExportTraceDataOp(t *testing.T) { var sentSpans, failedToSendSpans int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter+"/traces", span.Name) + assert.Equal(t, "exporter/"+exporter.String()+"/traces", span.Name) switch errs[i] { case nil: sentSpans += numExportedSpans[i] @@ -387,7 +387,7 @@ func TestExportMetricsOp(t *testing.T) { t.Name(), trace.WithSampler(trace.AlwaysSample())) defer parentSpan.End() - obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterName: exporter}) + obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterID: exporter}) errs := []error{nil, errFake} toSendMetricPoints := []int{17, 23} @@ -403,7 +403,7 @@ func TestExportMetricsOp(t *testing.T) { var sentMetricPoints, failedToSendMetricPoints int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter+"/metrics", span.Name) + assert.Equal(t, "exporter/"+exporter.String()+"/metrics", span.Name) switch errs[i] { case nil: sentMetricPoints += toSendMetricPoints[i] @@ -436,7 +436,7 @@ func TestExportLogsOp(t *testing.T) { t.Name(), trace.WithSampler(trace.AlwaysSample())) defer parentSpan.End() - obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterName: exporter}) + obsrep := obsreport.NewExporter(obsreport.ExporterSettings{Level: configtelemetry.LevelNormal, ExporterID: exporter}) errs := []error{nil, errFake} toSendLogRecords := []int{17, 23} for i, err := range errs { @@ -451,7 +451,7 @@ func TestExportLogsOp(t *testing.T) { var sentLogRecords, failedToSendLogRecords int for i, span := range spans { - assert.Equal(t, "exporter/"+exporter+"/logs", span.Name) + assert.Equal(t, "exporter/"+exporter.String()+"/logs", span.Name) switch errs[i] { case nil: sentLogRecords += toSendLogRecords[i] diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index 9d69ab5fc5c4..efd4a4d0872b 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -58,24 +58,24 @@ func SetupRecordedMetricsTest() (func(), error) { // CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values. // When this function is called it is required to also call SetupRecordedMetricsTest as first thing. -func CheckExporterTraces(t *testing.T, exporter string, acceptedSpans, droppedSpans int64) { - exporterTags := tagsForExporterView(exporter) +func CheckExporterTraces(t *testing.T, exporter config.ComponentID, acceptedSpans, droppedSpans int64) { + exporterTags := tagsForExporterView(exporter.String()) checkValueForView(t, exporterTags, acceptedSpans, "exporter/sent_spans") checkValueForView(t, exporterTags, droppedSpans, "exporter/send_failed_spans") } // CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values. // When this function is called it is required to also call SetupRecordedMetricsTest as first thing. -func CheckExporterMetrics(t *testing.T, exporter string, acceptedMetricsPoints, droppedMetricsPoints int64) { - exporterTags := tagsForExporterView(exporter) +func CheckExporterMetrics(t *testing.T, exporter config.ComponentID, acceptedMetricsPoints, droppedMetricsPoints int64) { + exporterTags := tagsForExporterView(exporter.String()) checkValueForView(t, exporterTags, acceptedMetricsPoints, "exporter/sent_metric_points") checkValueForView(t, exporterTags, droppedMetricsPoints, "exporter/send_failed_metric_points") } // CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values. // When this function is called it is required to also call SetupRecordedMetricsTest as first thing. -func CheckExporterLogs(t *testing.T, exporter string, acceptedLogRecords, droppedLogRecords int64) { - exporterTags := tagsForExporterView(exporter) +func CheckExporterLogs(t *testing.T, exporter config.ComponentID, acceptedLogRecords, droppedLogRecords int64) { + exporterTags := tagsForExporterView(exporter.String()) checkValueForView(t, exporterTags, acceptedLogRecords, "exporter/sent_log_records") checkValueForView(t, exporterTags, droppedLogRecords, "exporter/send_failed_log_records") } diff --git a/obsreport/obsreporttest/obsreporttest_test.go b/obsreport/obsreporttest/obsreporttest_test.go index d90ce841c27d..9c1804327c1f 100644 --- a/obsreport/obsreporttest/obsreporttest_test.go +++ b/obsreport/obsreporttest/obsreporttest_test.go @@ -21,18 +21,22 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/obsreport/obsreporttest" ) const ( - exporter = "fakeExporter" receiver = "fakeReicever" transport = "fakeTransport" format = "fakeFormat" ) +var ( + exporter = config.NewID("fakeExporter") +) + func TestCheckReceiverTracesViews(t *testing.T) { doneFn, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) @@ -82,8 +86,8 @@ func TestCheckExporterTracesViews(t *testing.T) { defer doneFn() obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.LevelNormal, - ExporterName: exporter, + Level: configtelemetry.LevelNormal, + ExporterID: exporter, }) ctx := obsrep.StartTracesExportOp(context.Background()) assert.NotNil(t, ctx) @@ -99,8 +103,8 @@ func TestCheckExporterMetricsViews(t *testing.T) { defer doneFn() obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.LevelNormal, - ExporterName: exporter, + Level: configtelemetry.LevelNormal, + ExporterID: exporter, }) ctx := obsrep.StartMetricsExportOp(context.Background()) assert.NotNil(t, ctx) @@ -116,8 +120,8 @@ func TestCheckExporterLogsViews(t *testing.T) { defer doneFn() obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ - Level: configtelemetry.LevelNormal, - ExporterName: exporter, + Level: configtelemetry.LevelNormal, + ExporterID: exporter, }) ctx := obsrep.StartLogsExportOp(context.Background()) assert.NotNil(t, ctx)