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

Fix prometheusexporter droping the OTEL resource labels #2899

Merged
Next Next commit
fix: add resource_attributes_as_tags support prometheusexporter
  • Loading branch information
krak3n committed Apr 7, 2021
commit 0be56e93cb1f904bd60dae9bcefc39740a476762
3 changes: 3 additions & 0 deletions exporter/prometheusexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The following settings can be optionally configured:
- `send_timestamps` (default = `false`): if true, sends the timestamp of the underlying
metric sample in the response.
- `metric_expiration` (default = `5m`): defines how long metrics are exposed without updates
- `resource_attributes_as_tag` (default = `false`): if set to true will transform all resource

Choose a reason for hiding this comment

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

I was looking into this exact same feature with the prometheusremotewriteexporter. Was just wondering - strictly speaking it is "resource attributes as labels"? I guess Prometheus uses the term "label" instead of "tag"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @bogdandrutu I'll switch it to a convention thats used over in the contrib repo so things are kept consistent, so this will change too

        resource_to_telemetry_conversion:
            enabled: true

Copy link
Member

Choose a reason for hiding this comment

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

seems to be tags not tag

attributes into labels.

Example:

Expand All @@ -30,4 +32,5 @@ exporters:
"another label": spaced value
send_timestamps: true
metric_expiration: 180m
resource_attributes_as_tags: true
```
4 changes: 4 additions & 0 deletions exporter/prometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ type Config struct {

// MetricExpiration defines how long metrics are kept without updates
MetricExpiration time.Duration `mapstructure:"metric_expiration"`

// ResourceAttributesAsTags, if sMet to true, will use the exporterhelper feature to
// transform all resource attributes into metric labels.
ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"`
Copy link
Member

Choose a reason for hiding this comment

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

In contrib where we use this, we have config like:

	exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`

so the config will be:

   resource_to_telemetry_conversion:
      enabled: true

If you don't like that name maybe embed that settings but use the name resource_attributes_as_tags? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah cool, it should be consistent with existing implementations so happy to switch it up to:

        resource_to_telemetry_conversion:
            enabled: true

}
16 changes: 15 additions & 1 deletion exporter/prometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,19 @@ func createMetricsExporter(
) (component.MetricsExporter, error) {
pcfg := cfg.(*Config)

return newPrometheusExporter(pcfg, params.Logger)
exporter, err := newPrometheusExporter(pcfg, params.Logger)
if err != nil {
return nil, err
}

return exporterhelper.NewMetricsExporter(
cfg,
params.Logger,
exporter.ConsumeMetrics,
exporterhelper.WithStart(exporter.Start),
exporterhelper.WithShutdown(exporter.Shutdown),
exporterhelper.WithResourceToTelemetryConversion(exporterhelper.ResourceToTelemetrySettings{
Enabled: pcfg.ResourceAttributesAsTags,
}),
)
}