Skip to content

Commit

Permalink
refactor: use existing resource_to_telemetry_conversion convention fr…
Browse files Browse the repository at this point in the history
…om exporterhelper
  • Loading branch information
krak3n committed Apr 13, 2021
1 parent d7f1076 commit 4179644
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions exporter/prometheusexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +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.
- `resource_to_telemetry_conversion`
- `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default.

Example:

Expand All @@ -32,5 +32,6 @@ exporters:
"another label": spaced value
send_timestamps: true
metric_expiration: 180m
resource_attributes_as_tags: true
resource_to_telemetry_conversion:
enabled: true
```
6 changes: 3 additions & 3 deletions exporter/prometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/prometheus/client_golang/prometheus"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

// Config defines configuration for Prometheus exporter.
Expand All @@ -41,7 +42,6 @@ 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"`
// ResourceToTelemetrySettings defines configuration for converting resource attributes to metric labels.
exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`
}
4 changes: 1 addition & 3 deletions exporter/prometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ func createMetricsExporter(
prometheus.ConsumeMetrics,
exporterhelper.WithStart(prometheus.Start),
exporterhelper.WithShutdown(prometheus.Shutdown),
exporterhelper.WithResourceToTelemetryConversion(exporterhelper.ResourceToTelemetrySettings{
Enabled: pcfg.ResourceAttributesAsTags,
}),
exporterhelper.WithResourceToTelemetryConversion(pcfg.ResourceToTelemetrySettings),
)
if err != nil {
return nil, err
Expand Down
11 changes: 7 additions & 4 deletions exporter/prometheusexporter/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/internal/testdata"
"go.opentelemetry.io/collector/translator/internaldata"
)
Expand Down Expand Up @@ -261,10 +262,12 @@ func TestPrometheusExporter_endToEndWithResource(t *testing.T) {
"foo2": "bar2",
"code2": "one2",
},
Endpoint: ":7777",
SendTimestamps: true,
MetricExpiration: 120 * time.Minute,
ResourceAttributesAsTags: true,
Endpoint: ":7777",
SendTimestamps: true,
MetricExpiration: 120 * time.Minute,
ResourceToTelemetrySettings: exporterhelper.ResourceToTelemetrySettings{
Enabled: true,
},
}

factory := NewFactory()
Expand Down

0 comments on commit 4179644

Please sign in to comment.