Skip to content

Commit

Permalink
restore prometheus sanitization for GMP exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Nov 1, 2024
1 parent 80050c2 commit d15adeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion exporter/googlemanagedprometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus"
)

// Config defines configuration for Google Cloud Managed Service for Prometheus exporter.
Expand Down Expand Up @@ -47,7 +50,10 @@ func (c *GMPConfig) toCollectorConfig() collector.Config {
cfg.MetricConfig.InstrumentationLibraryLabels = false
cfg.MetricConfig.ServiceResourceLabels = false
// Update metric naming to match GMP conventions
cfg.MetricConfig.GetMetricName = c.MetricConfig.Config.GetMetricName
cfg.MetricConfig.GetMetricName = func(baseName string, metric pmetric.Metric) (string, error) {
compliantName := prometheus.BuildCompliantName(metric, "", c.MetricConfig.Config.AddMetricSuffixes)
return googlemanagedprometheus.GetMetricName(baseName, compliantName, metric)
}
// Map to the prometheus_target monitored resource
cfg.MetricConfig.MapMonitoredResource = c.MetricConfig.Config.MapToPrometheusTarget
cfg.MetricConfig.ExtraMetrics = c.MetricConfig.Config.ExtraMetrics
Expand Down
1 change: 1 addition & 0 deletions exporter/googlemanagedprometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0.49.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.112.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.112.0
go.opentelemetry.io/collector/confmap v1.18.0
Expand Down

0 comments on commit d15adeb

Please sign in to comment.