Skip to content

Commit

Permalink
fix: add resource_attributes_as_tags support prometheusexporter
Browse files Browse the repository at this point in the history
  • Loading branch information
krak3n committed Apr 7, 2021
1 parent c5ddd09 commit 0be56e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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
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"`
}
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,
}),
)
}

0 comments on commit 0be56e9

Please sign in to comment.