Skip to content

Commit

Permalink
[obsreport] Replace Prometheus namespace with metrics prefix
Browse files Browse the repository at this point in the history
"otelcol" part of the exposed metrics that is set as Prometheus namespace is replaced the same explicit metrics prefix. This change brings names consistency between metrics that can be reported with enabled or disabled "telemetry.useOtelForInternalMetrics" feature gate.
  • Loading branch information
dmitryax committed Aug 21, 2022
1 parent f0d69d6 commit 288dece
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 75 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### 🛑 Breaking changes 🛑

- "otelcol" part of the exposed metrics that is set as Prometheus namespace is replaced the same explicit metrics prefix (#5939)
- This is potentially a breaking change for custom distributions that expose additional OpenCensus metrics. The
"otelcol/" prefix must be explicitly added to those metrics to get the same names as before this change.
- Remove deprecated fields/funcs from `service` (#5907)
- Remove `ConfigProviderSettings.Location`
- Remove `ConfigProviderSettings.MapProviders`
Expand Down
10 changes: 5 additions & 5 deletions exporter/exporterhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@ func newInstruments(registry *metric.Registry) *instruments {
registry: registry,
}
insts.queueSize, _ = registry.AddInt64DerivedGauge(
obsmetrics.ExporterKey+"/queue_size",
obsmetrics.ExporterPrefix+"queue_size",
metric.WithDescription("Current size of the retry queue (in batches)"),
metric.WithLabelKeys(obsmetrics.ExporterKey),
metric.WithUnit(metricdata.UnitDimensionless))

insts.queueCapacity, _ = registry.AddInt64DerivedGauge(
obsmetrics.ExporterKey+"/queue_capacity",
obsmetrics.ExporterPrefix+"queue_capacity",
metric.WithDescription("Fixed capacity of the retry queue (in batches)"),
metric.WithLabelKeys(obsmetrics.ExporterKey),
metric.WithUnit(metricdata.UnitDimensionless))

insts.failedToEnqueueTraceSpans, _ = registry.AddInt64Cumulative(
obsmetrics.ExporterKey+"/enqueue_failed_spans",
obsmetrics.ExporterPrefix+"enqueue_failed_spans",
metric.WithDescription("Number of spans failed to be added to the sending queue."),
metric.WithLabelKeys(obsmetrics.ExporterKey),
metric.WithUnit(metricdata.UnitDimensionless))

insts.failedToEnqueueMetricPoints, _ = registry.AddInt64Cumulative(
obsmetrics.ExporterKey+"/enqueue_failed_metric_points",
obsmetrics.ExporterPrefix+"enqueue_failed_metric_points",
metric.WithDescription("Number of metric points failed to be added to the sending queue."),
metric.WithLabelKeys(obsmetrics.ExporterKey),
metric.WithUnit(metricdata.UnitDimensionless))

insts.failedToEnqueueLogRecords, _ = registry.AddInt64Cumulative(
obsmetrics.ExporterKey+"/enqueue_failed_log_records",
obsmetrics.ExporterPrefix+"enqueue_failed_log_records",
metric.WithDescription("Number of log records failed to be added to the sending queue."),
metric.WithLabelKeys(obsmetrics.ExporterKey),
metric.WithUnit(metricdata.UnitDimensionless))
Expand Down
6 changes: 3 additions & 3 deletions exporter/exporterhelper/queued_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ func TestQueuedRetry_QueueMetricsReported(t *testing.T) {
be := newBaseExporter(&defaultExporterCfg, componenttest.NewNopExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost()))

checkValueForGlobalManager(t, defaultExporterTags, int64(5000), "exporter/queue_capacity")
checkValueForGlobalManager(t, defaultExporterTags, int64(5000), "otelcol/exporter/queue_capacity")
for i := 0; i < 7; i++ {
require.NoError(t, be.sender.send(newErrorRequest(context.Background())))
}
checkValueForGlobalManager(t, defaultExporterTags, int64(7), "exporter/queue_size")
checkValueForGlobalManager(t, defaultExporterTags, int64(7), "otelcol/exporter/queue_size")

assert.NoError(t, be.Shutdown(context.Background()))
checkValueForGlobalManager(t, defaultExporterTags, int64(0), "exporter/queue_size")
checkValueForGlobalManager(t, defaultExporterTags, int64(0), "otelcol/exporter/queue_size")
}

func TestNoCancellationContext(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/obsreportconfig/obsmetrics/obs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
var (
TagKeyExporter, _ = tag.NewKey(ExporterKey)

ExporterPrefix = ExporterKey + NameSep
ExporterPrefix = Prefix + ExporterKey + NameSep
ExportTraceDataOperationSuffix = NameSep + "traces"
ExportMetricsOperationSuffix = NameSep + "metrics"
ExportLogsOperationSuffix = NameSep + "logs"
Expand Down
2 changes: 1 addition & 1 deletion internal/obsreportconfig/obsmetrics/obs_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
var (
TagKeyProcessor, _ = tag.NewKey(ProcessorKey)

ProcessorPrefix = ProcessorKey + NameSep
ProcessorPrefix = Prefix + ProcessorKey + NameSep

// Processor metrics. Any count of data items below is in the internal format
// of the collector since processors only deal with internal format.
Expand Down
2 changes: 1 addition & 1 deletion internal/obsreportconfig/obsmetrics/obs_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
TagKeyReceiver, _ = tag.NewKey(ReceiverKey)
TagKeyTransport, _ = tag.NewKey(TransportKey)

ReceiverPrefix = ReceiverKey + NameSep
ReceiverPrefix = Prefix + ReceiverKey + NameSep
ReceiveTraceDataOperationSuffix = NameSep + "TraceDataReceived"
ReceiverMetricsOperationSuffix = NameSep + "MetricsReceived"
ReceiverLogsOperationSuffix = NameSep + "LogsReceived"
Expand Down
2 changes: 1 addition & 1 deletion internal/obsreportconfig/obsmetrics/obs_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

const (
ScraperPrefix = ScraperKey + NameSep
ScraperPrefix = Prefix + ScraperKey + NameSep
ScraperMetricsOperationSuffix = NameSep + "MetricsScraped"
)

Expand Down
1 change: 1 addition & 0 deletions internal/obsreportconfig/obsmetrics/obsmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ package obsmetrics // import "go.opentelemetry.io/collector/internal/obsreportco

const (
NameSep = "/"
Prefix = "otelcol" + NameSep
)
2 changes: 1 addition & 1 deletion obsreport/obsreport_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ExporterSettings struct {
func NewExporter(cfg ExporterSettings) *Exporter {
return &Exporter{
level: cfg.ExporterCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ExporterPrefix + cfg.ExporterID.String(),
spanNamePrefix: obsmetrics.ExporterKey + obsmetrics.NameSep + cfg.ExporterID.String(),
mutators: []tag.Mutator{tag.Upsert(obsmetrics.TagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))},
tracer: cfg.ExporterCreateSettings.TracerProvider.Tracer(cfg.ExporterID.String()),
}
Expand Down
2 changes: 1 addition & 1 deletion obsreport/obsreport_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ReceiverSettings struct {
func NewReceiver(cfg ReceiverSettings) *Receiver {
return &Receiver{
level: cfg.ReceiverCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ReceiverPrefix + cfg.ReceiverID.String(),
spanNamePrefix: obsmetrics.ReceiverKey + obsmetrics.NameSep + cfg.ReceiverID.String(),
transport: cfg.Transport,
longLivedCtx: cfg.LongLivedCtx,
mutators: []tag.Mutator{
Expand Down
20 changes: 10 additions & 10 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestReceiveTraceDataOp(t *testing.T) {

var acceptedSpans, refusedSpans int
for i, span := range spans {
assert.Equal(t, "receiver/"+receiver.String()+"/TraceDataReceived", span.Name())
assert.Equal(t, "otelcol/receiver/"+receiver.String()+"/TraceDataReceived", span.Name())
switch {
case params[i].err == nil:
acceptedSpans += params[i].items
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestReceiveLogsOp(t *testing.T) {

var acceptedLogRecords, refusedLogRecords int
for i, span := range spans {
assert.Equal(t, "receiver/"+receiver.String()+"/LogsReceived", span.Name())
assert.Equal(t, "otelcol/receiver/"+receiver.String()+"/LogsReceived", span.Name())
switch {
case params[i].err == nil:
acceptedLogRecords += params[i].items
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestReceiveMetricsOp(t *testing.T) {

var acceptedMetricPoints, refusedMetricPoints int
for i, span := range spans {
assert.Equal(t, "receiver/"+receiver.String()+"/MetricsReceived", span.Name())
assert.Equal(t, "otelcol/receiver/"+receiver.String()+"/MetricsReceived", span.Name())
switch {
case params[i].err == nil:
acceptedMetricPoints += params[i].items
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestScrapeMetricsDataOp(t *testing.T) {

var scrapedMetricPoints, erroredMetricPoints int
for i, span := range spans {
assert.Equal(t, "scraper/"+receiver.String()+"/"+scraper.String()+"/MetricsScraped", span.Name())
assert.Equal(t, "otelcol/scraper/"+receiver.String()+"/"+scraper.String()+"/MetricsScraped", span.Name())
switch {
case params[i].err == nil:
scrapedMetricPoints += params[i].items
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestExportTraceDataOp(t *testing.T) {

var sentSpans, failedToSendSpans int
for i, span := range spans {
assert.Equal(t, "exporter/"+exporter.String()+"/traces", span.Name())
assert.Equal(t, "otelcol/exporter/"+exporter.String()+"/traces", span.Name())
switch {
case params[i].err == nil:
sentSpans += params[i].items
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestExportMetricsOp(t *testing.T) {

var sentMetricPoints, failedToSendMetricPoints int
for i, span := range spans {
assert.Equal(t, "exporter/"+exporter.String()+"/metrics", span.Name())
assert.Equal(t, "otelcol/exporter/"+exporter.String()+"/metrics", span.Name())
switch {
case params[i].err == nil:
sentMetricPoints += params[i].items
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestExportLogsOp(t *testing.T) {

var sentLogRecords, failedToSendLogRecords int
for i, span := range spans {
assert.Equal(t, "exporter/"+exporter.String()+"/logs", span.Name())
assert.Equal(t, "otelcol/exporter/"+exporter.String()+"/logs", span.Name())
switch {
case params[i].err == nil:
sentLogRecords += params[i].items
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) {
link := span.Links()[0]
assert.Equal(t, parentSpan.SpanContext().TraceID(), link.SpanContext.TraceID())
assert.Equal(t, parentSpan.SpanContext().SpanID(), link.SpanContext.SpanID())
assert.Equal(t, "receiver/"+receiver.String()+"/TraceDataReceived", span.Name())
assert.Equal(t, "otelcol/receiver/"+receiver.String()+"/TraceDataReceived", span.Name())
require.Contains(t, span.Attributes(), attribute.KeyValue{Key: obsmetrics.TransportKey, Value: attribute.StringValue(transport)})
switch {
case params[i].err == nil:
Expand Down Expand Up @@ -502,11 +502,11 @@ func TestBuildProcessorCustomMetricName(t *testing.T) {
}{
{
name: "firstMeasure",
want: "processor/test_type/firstMeasure",
want: "otelcol/processor/test_type/firstMeasure",
},
{
name: "secondMeasure",
want: "processor/test_type/secondMeasure",
want: "otelcol/processor/test_type/secondMeasure",
},
}
for _, tt := range tests {
Expand Down
52 changes: 26 additions & 26 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func CheckExporterTraces(_ TestTelemetry, exporter config.ComponentID, sentSpans
exporterTags := tagsForExporterView(exporter)
if sendFailedSpans > 0 {
return multierr.Combine(
checkValueForView(exporterTags, sentSpans, "exporter/sent_spans"),
checkValueForView(exporterTags, sendFailedSpans, "exporter/send_failed_spans"))
checkValueForView(exporterTags, sentSpans, "otelcol/exporter/sent_spans"),
checkValueForView(exporterTags, sendFailedSpans, "otelcol/exporter/send_failed_spans"))
}
return checkValueForView(exporterTags, sentSpans, "exporter/sent_spans")
return checkValueForView(exporterTags, sentSpans, "otelcol/exporter/sent_spans")
}

// CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values.
Expand All @@ -120,10 +120,10 @@ func CheckExporterMetrics(_ TestTelemetry, exporter config.ComponentID, sentMetr
exporterTags := tagsForExporterView(exporter)
if sendFailedMetricsPoints > 0 {
return multierr.Combine(
checkValueForView(exporterTags, sentMetricsPoints, "exporter/sent_metric_points"),
checkValueForView(exporterTags, sendFailedMetricsPoints, "exporter/send_failed_metric_points"))
checkValueForView(exporterTags, sentMetricsPoints, "otelcol/exporter/sent_metric_points"),
checkValueForView(exporterTags, sendFailedMetricsPoints, "otelcol/exporter/send_failed_metric_points"))
}
return checkValueForView(exporterTags, sentMetricsPoints, "exporter/sent_metric_points")
return checkValueForView(exporterTags, sentMetricsPoints, "otelcol/exporter/sent_metric_points")
}

// CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values.
Expand All @@ -132,76 +132,76 @@ func CheckExporterLogs(_ TestTelemetry, exporter config.ComponentID, sentLogReco
exporterTags := tagsForExporterView(exporter)
if sendFailedLogRecords > 0 {
return multierr.Combine(
checkValueForView(exporterTags, sentLogRecords, "exporter/sent_log_records"),
checkValueForView(exporterTags, sendFailedLogRecords, "exporter/send_failed_log_records"))
checkValueForView(exporterTags, sentLogRecords, "otelcol/exporter/sent_log_records"),
checkValueForView(exporterTags, sendFailedLogRecords, "otelcol/exporter/send_failed_log_records"))
}
return checkValueForView(exporterTags, sentLogRecords, "exporter/sent_log_records")
return checkValueForView(exporterTags, sentLogRecords, "otelcol/exporter/sent_log_records")
}

// CheckProcessorTraces 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 SetupTelemetry as first thing.
func CheckProcessorTraces(_ TestTelemetry, processor config.ComponentID, acceptedSpans, refusedSpans, droppedSpans int64) error {
processorTags := tagsForProcessorView(processor)
return multierr.Combine(
checkValueForView(processorTags, acceptedSpans, "processor/accepted_spans"),
checkValueForView(processorTags, refusedSpans, "processor/refused_spans"),
checkValueForView(processorTags, droppedSpans, "processor/dropped_spans"))
checkValueForView(processorTags, acceptedSpans, "otelcol/processor/accepted_spans"),
checkValueForView(processorTags, refusedSpans, "otelcol/processor/refused_spans"),
checkValueForView(processorTags, droppedSpans, "otelcol/processor/dropped_spans"))
}

// CheckProcessorMetrics 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 SetupTelemetry as first thing.
func CheckProcessorMetrics(_ TestTelemetry, processor config.ComponentID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error {
processorTags := tagsForProcessorView(processor)
return multierr.Combine(
checkValueForView(processorTags, acceptedMetricPoints, "processor/accepted_metric_points"),
checkValueForView(processorTags, refusedMetricPoints, "processor/refused_metric_points"),
checkValueForView(processorTags, droppedMetricPoints, "processor/dropped_metric_points"))
checkValueForView(processorTags, acceptedMetricPoints, "otelcol/processor/accepted_metric_points"),
checkValueForView(processorTags, refusedMetricPoints, "otelcol/processor/refused_metric_points"),
checkValueForView(processorTags, droppedMetricPoints, "otelcol/processor/dropped_metric_points"))
}

// CheckProcessorLogs 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 SetupTelemetry as first thing.
func CheckProcessorLogs(_ TestTelemetry, processor config.ComponentID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error {
processorTags := tagsForProcessorView(processor)
return multierr.Combine(
checkValueForView(processorTags, acceptedLogRecords, "processor/accepted_log_records"),
checkValueForView(processorTags, refusedLogRecords, "processor/refused_log_records"),
checkValueForView(processorTags, droppedLogRecords, "processor/dropped_log_records"))
checkValueForView(processorTags, acceptedLogRecords, "otelcol/processor/accepted_log_records"),
checkValueForView(processorTags, refusedLogRecords, "otelcol/processor/refused_log_records"),
checkValueForView(processorTags, droppedLogRecords, "otelcol/processor/dropped_log_records"))
}

// CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func CheckReceiverTraces(_ TestTelemetry, receiver config.ComponentID, protocol string, acceptedSpans, droppedSpans int64) error {
receiverTags := tagsForReceiverView(receiver, protocol)
return multierr.Combine(
checkValueForView(receiverTags, acceptedSpans, "receiver/accepted_spans"),
checkValueForView(receiverTags, droppedSpans, "receiver/refused_spans"))
checkValueForView(receiverTags, acceptedSpans, "otelcol/receiver/accepted_spans"),
checkValueForView(receiverTags, droppedSpans, "otelcol/receiver/refused_spans"))
}

// CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func CheckReceiverLogs(_ TestTelemetry, receiver config.ComponentID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
receiverTags := tagsForReceiverView(receiver, protocol)
return multierr.Combine(
checkValueForView(receiverTags, acceptedLogRecords, "receiver/accepted_log_records"),
checkValueForView(receiverTags, droppedLogRecords, "receiver/refused_log_records"))
checkValueForView(receiverTags, acceptedLogRecords, "otelcol/receiver/accepted_log_records"),
checkValueForView(receiverTags, droppedLogRecords, "otelcol/receiver/refused_log_records"))
}

// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func CheckReceiverMetrics(_ TestTelemetry, receiver config.ComponentID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
receiverTags := tagsForReceiverView(receiver, protocol)
return multierr.Combine(
checkValueForView(receiverTags, acceptedMetricPoints, "receiver/accepted_metric_points"),
checkValueForView(receiverTags, droppedMetricPoints, "receiver/refused_metric_points"))
checkValueForView(receiverTags, acceptedMetricPoints, "otelcol/receiver/accepted_metric_points"),
checkValueForView(receiverTags, droppedMetricPoints, "otelcol/receiver/refused_metric_points"))
}

// CheckScraperMetrics checks that for the current exported values for metrics scraper metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func CheckScraperMetrics(_ TestTelemetry, receiver config.ComponentID, scraper config.ComponentID, scrapedMetricPoints, erroredMetricPoints int64) error {
scraperTags := tagsForScraperView(receiver, scraper)
return multierr.Combine(
checkValueForView(scraperTags, scrapedMetricPoints, "scraper/scraped_metric_points"),
checkValueForView(scraperTags, erroredMetricPoints, "scraper/errored_metric_points"))
checkValueForView(scraperTags, scrapedMetricPoints, "otelcol/scraper/scraped_metric_points"),
checkValueForView(scraperTags, erroredMetricPoints, "otelcol/scraper/errored_metric_points"))
}

// checkValueForView checks that for the current exported value in the view with the given name
Expand Down
Loading

0 comments on commit 288dece

Please sign in to comment.