Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions .chloggen/fix_46984.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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. receiver/filelog)
component: receiver/prometheus_remote_write

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add remaining metric metadata translations (Name, Unit) from Prometheus to OTLP as per compatibility spec

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [46984]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: []
1 change: 1 addition & 0 deletions receiver/prometheusremotewritereceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Config holds common fields and embedded protocol-specific configurations
type Config struct {
confighttp.ServerConfig `mapstructure:",squash"`
TrimMetricSuffixes bool `mapstructure:"trim_metric_suffixes"`
}

var _ component.Config = (*Config)(nil)
Expand Down
3 changes: 3 additions & 0 deletions receiver/prometheusremotewritereceiver/config.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
description: Config holds common fields and embedded protocol-specific configurations
type: object
properties:
trim_metric_suffixes:
type: boolean
allOf:
- $ref: go.opentelemetry.io/collector/config/confighttp.server_config
1 change: 1 addition & 0 deletions receiver/prometheusremotewritereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func createDefaultConfig() component.Config {
ServerConfig: confighttp.ServerConfig{
NetAddr: netAddr,
},
TrimMetricSuffixes: false,
}
}

Expand Down
21 changes: 21 additions & 0 deletions receiver/prometheusremotewritereceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,27 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
unit := req.Symbols[ts.Metadata.UnitRef]
description := req.Symbols[ts.Metadata.HelpRef]

if unit != "" {
if unit == "ratio" {
unit = "1"
} else {
unit = strings.ReplaceAll(unit, "_per_", "/")
unit = prometheus.UnitWordToUCUM(unit)
}
}

if prw.config.TrimMetricSuffixes {
metricName = strings.TrimSuffix(metricName, "_total")
metricName = strings.TrimSuffix(metricName, "_sum")
metricName = strings.TrimSuffix(metricName, "_count")
metricName = strings.TrimSuffix(metricName, "_bucket")

origUnit := req.Symbols[ts.Metadata.UnitRef]
if origUnit != "" {
metricName = strings.TrimSuffix(metricName, "_"+origUnit)
}
}

// Handle histograms separately due to their complex mixed-schema processing
if ts.Metadata.Type == writev2.Metadata_METRIC_TYPE_HISTOGRAM ||
ts.Metadata.Type == writev2.Metadata_METRIC_TYPE_UNSPECIFIED && len(ts.Histograms) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions receiver/prometheusremotewritereceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func TestTranslateV2(t *testing.T) {
// The second metric should have 1 data point.
metrics1 := sm1.Metrics().AppendEmpty()
metrics1.SetName("test_metric")
metrics1.SetUnit("seconds")
metrics1.SetUnit("s")
metrics1.SetDescription("longer description")
metrics1.Metadata().PutStr(prometheus.MetricMetadataTypeKey, "gauge")

Expand All @@ -595,7 +595,7 @@ func TestTranslateV2(t *testing.T) {

metrics2 := sm1.Metrics().AppendEmpty()
metrics2.SetName("test_metric")
metrics2.SetUnit("milliseconds")
metrics2.SetUnit("ms")
metrics2.SetDescription("small desc")
metrics2.Metadata().PutStr(prometheus.MetricMetadataTypeKey, "gauge")

Expand Down
Loading