Skip to content

Commit

Permalink
Use config.ComponentID in obsreport exporter settings (#3091)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored May 4, 2021
1 parent f4d33bc commit 970b76c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions exporter/exporterhelper/logshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 3 additions & 2 deletions exporter/exporterhelper/logshelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/metricshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/metricshelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/tracehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/tracehelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/prometheusexporter/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions obsreport/obsreport_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go.opencensus.io/tag"
"go.opencensus.io/trace"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtelemetry"
)

Expand Down Expand Up @@ -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))},
}
}

Expand Down
14 changes: 7 additions & 7 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
)

const (
exporter = "fakeExporter"
receiver = "fakeReicever"
scraper = "fakeScraper"
transport = "fakeTransport"
Expand All @@ -45,6 +44,7 @@ const (

var (
processor = config.NewID("fakeProcessor")
exporter = config.NewID("fakeExporter")

errFake = errors.New("errFake")
partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1)
Expand Down Expand Up @@ -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 {
Expand All @@ -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]
Expand Down Expand Up @@ -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}
Expand All @@ -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]
Expand Down Expand Up @@ -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 {
Expand All @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
18 changes: 11 additions & 7 deletions obsreport/obsreporttest/obsreporttest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 970b76c

Please sign in to comment.