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

[exporter/googlemanagedprometheus] Add target and scope info metrics by default #24372

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/gmp-exporter-add-target-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# 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: GMP exporter now automatically adds target_info and otel_scope_info metrics.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24372]

# (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:
29 changes: 27 additions & 2 deletions exporter/googlemanagedprometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/pmetric"
)

// Config defines configuration for Google Cloud Managed Service for Prometheus exporter.
Expand All @@ -31,8 +32,17 @@ type GMPConfig struct {
type MetricConfig struct {
// Prefix configures the prefix of metrics sent to GoogleManagedPrometheus. Defaults to prometheus.googleapis.com.
// Changing this prefix is not recommended, as it may cause metrics to not be queryable with promql in the Cloud Monitoring UI.
Prefix string `mapstructure:"prefix"`
ClientConfig collector.ClientConfig `mapstructure:",squash"`
Prefix string `mapstructure:"prefix"`
ClientConfig collector.ClientConfig `mapstructure:",squash"`
ExtraMetricsConfig ExtraMetricsConfig `mapstructure:"extra_metrics_config"`
}

// ExtraMetricsConfig controls the inclusion of additional metrics.
type ExtraMetricsConfig struct {
// Add `target_info` metric based on the resource. On by default.
EnableTargetInfo bool `mapstructure:"enable_target_info"`
// Add `otel_scope_info` metric and `scope_name`/`scope_version` attributes to all other metrics. On by default.
EnableScopeInfo bool `mapstructure:"enable_scope_info"`
}

func (c *GMPConfig) toCollectorConfig() collector.Config {
Expand All @@ -54,6 +64,21 @@ func (c *GMPConfig) toCollectorConfig() collector.Config {
cfg.ProjectID = c.ProjectID
cfg.UserAgent = c.UserAgent
cfg.MetricConfig.ClientConfig = c.MetricConfig.ClientConfig

// add target_info and scope_info metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, added and enabled by default

extraMetricsFuncs := make([]func(m pmetric.Metrics), 0)
if c.MetricConfig.ExtraMetricsConfig.EnableTargetInfo {
extraMetricsFuncs = append(extraMetricsFuncs, googlemanagedprometheus.AddTargetInfoMetric)
}
if c.MetricConfig.ExtraMetricsConfig.EnableScopeInfo {
extraMetricsFuncs = append(extraMetricsFuncs, googlemanagedprometheus.AddScopeInfoMetric)
}
cfg.MetricConfig.ExtraMetrics = func(m pmetric.Metrics) pmetric.ResourceMetricsSlice {
for _, extraMetricsFunc := range extraMetricsFuncs {
extraMetricsFunc(m)
}
return m.ResourceMetrics()
}
return cfg
}

Expand Down
6 changes: 6 additions & 0 deletions exporter/googlemanagedprometheusexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func TestLoadConfig(t *testing.T) {
GMPConfig: GMPConfig{
ProjectID: "my-project",
UserAgent: "opentelemetry-collector-contrib {{version}}",
MetricConfig: MetricConfig{
ExtraMetricsConfig: ExtraMetricsConfig{
EnableTargetInfo: true,
EnableScopeInfo: true,
},
},
},
RetrySettings: exporterhelper.RetrySettings{
Enabled: true,
Expand Down
8 changes: 8 additions & 0 deletions exporter/googlemanagedprometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func createDefaultConfig() component.Config {
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
RetrySettings: retrySettings,
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
GMPConfig: GMPConfig{
MetricConfig: MetricConfig{
ExtraMetricsConfig: ExtraMetricsConfig{
EnableTargetInfo: true,
EnableScopeInfo: true,
},
},
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/googlemanagedprometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
go.opentelemetry.io/collector v0.81.0
go.opentelemetry.io/collector/component v0.81.0
go.opentelemetry.io/collector/exporter v0.81.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0013
)

require (
Expand Down Expand Up @@ -78,7 +79,6 @@ require (
go.opentelemetry.io/collector/consumer v0.81.0 // indirect
go.opentelemetry.io/collector/extension v0.81.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0013 // indirect
go.opentelemetry.io/collector/pdata v1.0.0-rcv0013 // indirect
go.opentelemetry.io/collector/processor v0.81.0 // indirect
go.opentelemetry.io/collector/receiver v0.81.0 // indirect
go.opentelemetry.io/collector/semconv v0.81.0 // indirect
Expand Down