diff --git a/exporter/googlemanagedprometheusexporter/README.md b/exporter/googlemanagedprometheusexporter/README.md index 4bc8fada6d5d..237a29030fc5 100644 --- a/exporter/googlemanagedprometheusexporter/README.md +++ b/exporter/googlemanagedprometheusexporter/README.md @@ -18,6 +18,8 @@ The following configuration options are supported: - `user_agent` (optional): Override the user agent string sent on requests to Cloud Monitoring (currently only applies to metrics). Specify `{{version}}` to include the application version number. Defaults to `opentelemetry-collector-contrib {{version}}`. - `endpoint` (optional): Endpoint where metric data is going to be sent to. Replaces `endpoint`. - `use_insecure` (optional): If true, use gRPC as their communication transport. Only has effect if Endpoint is not "". +- `resource_to_telemetry_conversion` (optional) Configuration for converting resource attributes to telemetry attributes + - `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default. - `retry_on_failure` (optional): Configuration for how to handle retries when sending data to Google Cloud fails. - `enabled` (default = true) - `initial_interval` (default = 5s): Time to wait after the first failure before retrying; ignored if `enabled` is `false` diff --git a/exporter/googlemanagedprometheusexporter/config.go b/exporter/googlemanagedprometheusexporter/config.go index 273664888792..0246c1e00fcf 100644 --- a/exporter/googlemanagedprometheusexporter/config.go +++ b/exporter/googlemanagedprometheusexporter/config.go @@ -19,6 +19,7 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/exporter/exporterhelper" ) @@ -32,6 +33,9 @@ type Config struct { exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` + + // ResourceToTelemetrySettings defines configuration for converting resource attributes to metric labels. + ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"` } // GMPConfig is a subset of the collector config applicable to the GMP exporter. diff --git a/exporter/googlemanagedprometheusexporter/config_test.go b/exporter/googlemanagedprometheusexporter/config_test.go index deeb20bfacaf..92bd9a041fbb 100644 --- a/exporter/googlemanagedprometheusexporter/config_test.go +++ b/exporter/googlemanagedprometheusexporter/config_test.go @@ -65,5 +65,6 @@ func TestLoadConfig(t *testing.T) { NumConsumers: 2, QueueSize: 10, }, + ResourceToTelemetrySettings: resourcetotelemetry.Settings{Enabled: true}, }) } diff --git a/exporter/googlemanagedprometheusexporter/factory.go b/exporter/googlemanagedprometheusexporter/factory.go index 94492b3656d2..167d9f5b69df 100644 --- a/exporter/googlemanagedprometheusexporter/factory.go +++ b/exporter/googlemanagedprometheusexporter/factory.go @@ -19,6 +19,7 @@ import ( "time" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -61,7 +62,8 @@ func createMetricsExporter( if err != nil { return nil, err } - return exporterhelper.NewMetricsExporter( + + exporter, err := exporterhelper.NewMetricsExporter( ctx, params, cfg, @@ -72,4 +74,9 @@ func createMetricsExporter( exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}), exporterhelper.WithQueue(eCfg.QueueSettings), exporterhelper.WithRetry(eCfg.RetrySettings)) + + if err != nil { + return nil, err + } + return resourcetotelemetry.WrapMetricsExporter(eCfg.ResourceToTelemetrySettings, exporter), nil } diff --git a/exporter/googlemanagedprometheusexporter/testdata/config.yaml b/exporter/googlemanagedprometheusexporter/testdata/config.yaml index ba2db05a3da6..960fb84a25ce 100644 --- a/exporter/googlemanagedprometheusexporter/testdata/config.yaml +++ b/exporter/googlemanagedprometheusexporter/testdata/config.yaml @@ -19,6 +19,8 @@ exporters: initial_interval: 10s max_interval: 60s max_elapsed_time: 10m + resource_to_telemetry_conversion: + enabled: true service: diff --git a/unreleased/googlemanagedprometheusexporter-add-resource-to-telemetry.yaml b/unreleased/googlemanagedprometheusexporter-add-resource-to-telemetry.yaml new file mode 100644 index 000000000000..52e75f527f22 --- /dev/null +++ b/unreleased/googlemanagedprometheusexporter-add-resource-to-telemetry.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: googlemanagedprometheusexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for resource_to_telemetry_conversion feature + +# One or more tracking issues related to the change +issues: [12175] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: