Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telemetry] emit metrics with _ instead of / #9775

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .chloggen/codeboten_use-period.yaml
Original file line number Diff line number Diff line change
@@ -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: breaking

# 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: emit internal collector metrics with . instead of / with OTLP export

# One or more tracking issues or pull requests related to the change
issues: [9774]

# (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: |
This is addressing an issue w/ the names of the metrics generated by the Collector for its
internal metrics. Note that this change only impacts users that emit telemetry using OTLP, which
is currently still in experimental support. The prometheus metrics already replaced `/` with `_`
and they will do the same with `.`.

# 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: []
18 changes: 9 additions & 9 deletions exporter/exporterhelper/obsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,55 +78,55 @@ func (or *ObsReport) createOtelMetrics(cfg ObsReportSettings) error {
var errors, err error

or.sentSpans, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.SentSpansKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.SentSpansKey,
metric.WithDescription("Number of spans successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToSendSpans, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendSpansKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToSendSpansKey,
metric.WithDescription("Number of spans in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToEnqueueSpans, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToEnqueueSpansKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToEnqueueSpansKey,
metric.WithDescription("Number of spans failed to be added to the sending queue."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.sentMetricPoints, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.SentMetricPointsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.SentMetricPointsKey,
metric.WithDescription("Number of metric points successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToSendMetricPoints, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendMetricPointsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToSendMetricPointsKey,
metric.WithDescription("Number of metric points in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToEnqueueMetricPoints, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToEnqueueMetricPointsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToEnqueueMetricPointsKey,
metric.WithDescription("Number of metric points failed to be added to the sending queue."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.sentLogRecords, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.SentLogRecordsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.SentLogRecordsKey,
metric.WithDescription("Number of log record successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToSendLogRecords, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendLogRecordsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToSendLogRecordsKey,
metric.WithDescription("Number of log records in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)

or.failedToEnqueueLogRecords, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToEnqueueLogRecordsKey,
obsmetrics.ExporterMetricPrefix+obsmetrics.FailedToEnqueueLogRecordsKey,
metric.WithDescription("Number of log records failed to be added to the sending queue."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
Expand Down
1 change: 1 addition & 0 deletions internal/obsreportconfig/obsmetrics/obs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (

var (
ExporterPrefix = ExporterKey + NameSep
ExporterMetricPrefix = ExporterKey + MetricSep
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 @@ -18,5 +18,5 @@ const (
)

var (
ProcessorPrefix = ProcessorKey + NameSep
ProcessorMetricPrefix = ProcessorKey + MetricSep
)
1 change: 1 addition & 0 deletions internal/obsreportconfig/obsmetrics/obs_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (

var (
ReceiverPrefix = ReceiverKey + NameSep
ReceiverMetricPrefix = ReceiverKey + MetricSep
ReceiveTraceDataOperationSuffix = NameSep + "TraceDataReceived"
ReceiverMetricsOperationSuffix = NameSep + "MetricsReceived"
ReceiverLogsOperationSuffix = NameSep + "LogsReceived"
Expand Down
1 change: 1 addition & 0 deletions internal/obsreportconfig/obsmetrics/obs_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ const (

const (
ScraperPrefix = ScraperKey + NameSep
ScraperMetricPrefix = ScraperKey + MetricSep
ScraperMetricsOperationSuffix = NameSep + "MetricsScraped"
)
5 changes: 3 additions & 2 deletions internal/obsreportconfig/obsmetrics/obsmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package obsmetrics // import "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"

const (
NameSep = "/"
Scope = "go.opentelemetry.io/collector/obsreport"
NameSep = "/"
codeboten marked this conversation as resolved.
Show resolved Hide resolved
MetricSep = "."
Copy link
Member

@dmitryax dmitryax Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the SIG call, I suggested using _ instead of . until we stabilize the metrics. The reason is that AFAIK Prometheus is working on supporting dots. So once it's ready, it'll be another breaking change for all the users using Prometheus to scrape the internal metrics. Suddenly all the metrics will be converted from otelcol_receiver_accepted_metric_points to otelcol.receiver.accepted.metric_points. If we adopt _ for now, I believe we can avoid that.

I understand that _ is not semantically correct from OTel's perspective, but we will have to make a big migration later anyway, so it might make sense to reduce the amount of breaking changes.

I'm happy to hear other opinions. And I'm not sure about the timeline for dots support in Prometheus. Maybe it's much further away than new stable Collector metrics.

cc @open-telemetry/collector-approvers @open-telemetry/collector-contrib-approvers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, once the dots are supported in Prometheus, we might need a config option to convert .->_ somewhere to preserve the behavior and avoid breaking the users. It can be even a Prometheus receiver config option. In that case, we should be good.

@dashpole, maybe you have some ideas about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that use of dots vs underscores will be negotiated using headers, so users will be able to control it server-side: https://github.com/prometheus/proposals/blob/main/proposals/2023-08-21-utf8.md#query-time. If it is enabled by default at some point in the future, it might still be a surprise for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryax the reason i went with . instead of _ is that other metrics (for example the grpc instrumentation) uses . already when emitting OTLP. Having both separators, depending on the source of the metric, seemed confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that use of dots vs underscores will be negotiated using headers, so users will be able to control it server-side: https://github.com/prometheus/proposals/blob/main/proposals/2023-08-21-utf8.md#query-time. If it is enabled by default at some point in the future, it might still be a surprise for users.

Thanks for the clarification. Looks like, even if it is enabled by default, it won't happen any time soon. I assume the controlling headers will be exposed as a configuration in the Go OTel exporter as well as somewhere in service::telemetry::metrics` section of the collector config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryax the reason i went with . instead of _ is that other metrics (for example the grpc instrumentation) uses . already when emitting OTLP. Having both separators, depending on the source of the metric, seemed confusing.

Makes sense

Scope = "go.opentelemetry.io/collector/obsreport"
)
26 changes: 13 additions & 13 deletions processor/processorhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
// the standards used in the Collector. The configType should be the same
// value used to identify the type on the config.
func BuildCustomMetricName(configType, metric string) string {
componentPrefix := obsmetrics.ProcessorPrefix
if !strings.HasSuffix(componentPrefix, obsmetrics.NameSep) {
componentPrefix += obsmetrics.NameSep
componentPrefix := obsmetrics.ProcessorMetricPrefix
if !strings.HasSuffix(componentPrefix, obsmetrics.MetricSep) {
componentPrefix += obsmetrics.MetricSep

Check warning on line 31 in processor/processorhelper/obsreport.go

View check run for this annotation

Codecov / codecov/patch

processor/processorhelper/obsreport.go#L31

Added line #L31 was not covered by tests
}
if configType == "" {
return componentPrefix
}
return componentPrefix + configType + obsmetrics.NameSep + metric
return componentPrefix + configType + obsmetrics.MetricSep + metric
}

// ObsReport is a helper to add observability to a processor.
Expand Down Expand Up @@ -87,63 +87,63 @@
var errors, err error

or.acceptedSpansCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.AcceptedSpansKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.AcceptedSpansKey,
metric.WithDescription("Number of spans successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.refusedSpansCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedSpansKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.RefusedSpansKey,
metric.WithDescription("Number of spans that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.droppedSpansCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedSpansKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.DroppedSpansKey,
metric.WithDescription("Number of spans that were dropped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.acceptedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.AcceptedMetricPointsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.AcceptedMetricPointsKey,
metric.WithDescription("Number of metric points successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.refusedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedMetricPointsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.RefusedMetricPointsKey,
metric.WithDescription("Number of metric points that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.droppedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedMetricPointsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.DroppedMetricPointsKey,
metric.WithDescription("Number of metric points that were dropped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.acceptedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.AcceptedLogRecordsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.AcceptedLogRecordsKey,
metric.WithDescription("Number of log records successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.refusedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedLogRecordsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.RefusedLogRecordsKey,
metric.WithDescription("Number of log records that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

or.droppedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedLogRecordsKey,
obsmetrics.ProcessorMetricPrefix+obsmetrics.DroppedLogRecordsKey,
metric.WithDescription("Number of log records that were dropped."),
metric.WithUnit("1"),
)
Expand Down
4 changes: 2 additions & 2 deletions processor/processorhelper/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ func TestBuildProcessorCustomMetricName(t *testing.T) {
}{
{
name: "firstMeasure",
want: "processor/test_type/firstMeasure",
want: "processor.test_type.firstMeasure",
},
{
name: "secondMeasure",
want: "processor/test_type/secondMeasure",
want: "processor.test_type.secondMeasure",
},
}
for _, tt := range tests {
Expand Down
12 changes: 6 additions & 6 deletions receiver/receiverhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,42 +88,42 @@ func (rec *ObsReport) createOtelMetrics() error {
var errors, err error

rec.acceptedSpansCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.AcceptedSpansKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.AcceptedSpansKey,
metric.WithDescription("Number of spans successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

rec.refusedSpansCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedSpansKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.RefusedSpansKey,
metric.WithDescription("Number of spans that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

rec.acceptedMetricPointsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.AcceptedMetricPointsKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.AcceptedMetricPointsKey,
metric.WithDescription("Number of metric points successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

rec.refusedMetricPointsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedMetricPointsKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.RefusedMetricPointsKey,
metric.WithDescription("Number of metric points that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

rec.acceptedLogRecordsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.AcceptedLogRecordsKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.AcceptedLogRecordsKey,
metric.WithDescription("Number of log records successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)

rec.refusedLogRecordsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedLogRecordsKey,
obsmetrics.ReceiverMetricPrefix+obsmetrics.RefusedLogRecordsKey,
metric.WithDescription("Number of log records that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
Expand Down
Loading