Skip to content

Commit

Permalink
add resource_to_telemetry_conversion support in prometheusremotewrite…
Browse files Browse the repository at this point in the history
…rexporter
  • Loading branch information
mxiamxia committed Apr 26, 2021
1 parent 955cd77 commit b3fd5f5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions exporter/prometheusremotewriteexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ Several helper files are leveraged to provide additional capabilities automatica
- [HTTP settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/confighttp/README.md)
- [TLS and mTLS settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md)
- [Retry and timeout settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md), note that the exporter doesn't support `sending_queue`.
- [Resource attributes to Metric labels](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md),
5 changes: 5 additions & 0 deletions exporter/prometheusremotewriteexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type Config struct {
ExternalLabels map[string]string `mapstructure:"external_labels"`

HTTPClientSettings confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.

// ResourceToTelemetrySettings is the option for converting resource attributes to telemetry attributes.
// "Enabled" - A boolean field to enable/disable this option. Default is `false`.
// If enabled, all the resource attributes will be converted to metric labels by default.
exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`
}

var _ config.Exporter = (*Config)(nil)
Expand Down
1 change: 1 addition & 0 deletions exporter/prometheusremotewriteexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ func Test_loadConfig(t *testing.T) {
"prometheus-remote-write-version": "0.1.0",
"x-scope-orgid": "234"},
},
ResourceToTelemetrySettings: exporterhelper.ResourceToTelemetrySettings{Enabled: true},
})
}
1 change: 1 addition & 0 deletions exporter/prometheusremotewriteexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func createMetricsExporter(_ context.Context, params component.ExporterCreatePar
// and allow users to modify the queue size.
}),
exporterhelper.WithRetry(prwCfg.RetrySettings),
exporterhelper.WithResourceToTelemetryConversion(prwCfg.ResourceToTelemetrySettings),
exporterhelper.WithShutdown(prwe.Shutdown),
)

Expand Down
2 changes: 2 additions & 0 deletions exporter/prometheusremotewriteexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exporters:
external_labels:
key1: value1
key2: value2
resource_to_telemetry_conversion:
enabled: true

service:
pipelines:
Expand Down

0 comments on commit b3fd5f5

Please sign in to comment.