Skip to content

Commit

Permalink
Upgrade to OpenTelemetry v0.87.0 (#185)
Browse files Browse the repository at this point in the history
* upgrade otel

* fixing test failures

* remove commented out code

* ignore new generated files in headercheck

* fix lint errors

* use glob paths for addlicense

---------

Co-authored-by: Sophie Fang <[email protected]>
  • Loading branch information
braydonk and sophieyfang authored Oct 30, 2023
1 parent 2c2416e commit 9855133
Show file tree
Hide file tree
Showing 46 changed files with 1,331 additions and 1,023 deletions.
2 changes: 2 additions & 0 deletions .github/header-checker-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ignoreFiles:
- receiver/**/generated_config.go
- receiver/**/generated_config_test.go
- receiver/**/generated_status.go
- receiver/**/generated_resource.go
- receiver/**/generated_resource_test.go
- receiver/mongodbreceiver/**/*.go
- receiver/prometheusreceiver/**/*.go
- exporter/googlemanagedprometheusexporter/**/*.go
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ update-components:
grep -v "go.opentelemetry.io/collector/featuregate" | \
grep -v "go.opentelemetry.io/collector/pdata" | \
xargs -t -I '{}' go get {}@$(OTEL_VER)
go get -u github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus@latest
go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \
grep "^github.com/open-telemetry/opentelemetry-collector-contrib" | \
xargs -t -I '{}' go get {}@$(OTEL_VER)
Expand Down Expand Up @@ -88,11 +89,11 @@ install-tools:

.PHONY: addlicense
addlicense:
addlicense -c "Google LLC" -l apache $(ALL_SRC)
addlicense -c "Google LLC" -l apache ./**/*.go

.PHONY: checklicense
checklicense:
@output=`addlicense -check $(ALL_SRC)` && echo checklicense finished successfully || (echo checklicense errors: $$output && exit 1)
@output=`addlicense -check ./**/*.go` && echo checklicense finished successfully || (echo checklicense errors: $$output && exit 1)

.PHONY: lint
lint:
Expand Down
1 change: 1 addition & 0 deletions exporter/googlemanagedprometheusexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| ------------- |-----------|
| Stability | [beta]: metrics |
| Distributions | [contrib], [observiq] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Fgooglemanagedprometheus%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Fgooglemanagedprometheus) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Fgooglemanagedprometheus%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Fgooglemanagedprometheus) |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
29 changes: 16 additions & 13 deletions exporter/googlemanagedprometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pmetric"
)

// Config defines configuration for Google Cloud Managed Service for Prometheus exporter.
Expand Down Expand Up @@ -41,11 +40,12 @@ 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"`
Config googlemanagedprometheus.Config `mapstructure:",squash"`
}

func (c *GMPConfig) toCollectorConfig() collector.Config {
func (c *GMPConfig) toCollectorConfig() (collector.Config, error) {
// start with whatever the default collector config is.
cfg := collector.DefaultConfig()
cfg.MetricConfig.Prefix = c.MetricConfig.Prefix
Expand All @@ -56,28 +56,31 @@ func (c *GMPConfig) toCollectorConfig() collector.Config {
cfg.MetricConfig.InstrumentationLibraryLabels = false
cfg.MetricConfig.ServiceResourceLabels = false
// Update metric naming to match GMP conventions
cfg.MetricConfig.GetMetricName = googlemanagedprometheus.GetMetricName
cfg.MetricConfig.GetMetricName = c.MetricConfig.Config.GetMetricName
// Map to the prometheus_target monitored resource
cfg.MetricConfig.MapMonitoredResource = googlemanagedprometheus.MapToPrometheusTarget
cfg.MetricConfig.MapMonitoredResource = c.MetricConfig.Config.MapToPrometheusTarget
cfg.MetricConfig.EnableSumOfSquaredDeviation = true
// map the GMP config's fields to the collector config
cfg.ProjectID = c.ProjectID
cfg.UserAgent = c.UserAgent
cfg.MetricConfig.ClientConfig = c.MetricConfig.ClientConfig
cfg.MetricConfig.ExtraMetrics = c.MetricConfig.Config.ExtraMetrics
if c.UntypedDoubleExport {
cfg.MetricConfig.ExtraMetrics = func(m pmetric.Metrics) pmetric.ResourceMetricsSlice {
//nolint:errcheck
featuregate.GlobalRegistry().Set("gcp.untyped_double_export", true)
googlemanagedprometheus.AddUntypedMetrics(m)
return m.ResourceMetrics()
err := featuregate.GlobalRegistry().Set("gcp.untyped_double_export", true)
if err != nil {
return cfg, err
}
}

return cfg
return cfg, nil
}

func (cfg *Config) Validate() error {
if err := collector.ValidateConfig(cfg.toCollectorConfig()); err != nil {
collectorConfig, err := cfg.toCollectorConfig()
if err != nil {
return fmt.Errorf("error setting featuregate option: %w", err)
}
if err := collector.ValidateConfig(collectorConfig); err != nil {
return fmt.Errorf("exporter settings are invalid :%w", err)
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions exporter/googlemanagedprometheusexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"github.com/cenkalti/backoff/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -43,6 +44,9 @@ func TestLoadConfig(t *testing.T) {
GMPConfig: GMPConfig{
ProjectID: "my-project",
UserAgent: "opentelemetry-collector-contrib {{version}}",
MetricConfig: MetricConfig{
Config: googlemanagedprometheus.DefaultConfig(),
},
},
RetrySettings: exporterhelper.RetrySettings{
Enabled: true,
Expand Down
12 changes: 11 additions & 1 deletion exporter/googlemanagedprometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -38,6 +39,11 @@ func createDefaultConfig() component.Config {
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
RetrySettings: retrySettings,
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
GMPConfig: GMPConfig{
MetricConfig: MetricConfig{
Config: googlemanagedprometheus.DefaultConfig(),
},
},
}
}

Expand All @@ -47,7 +53,11 @@ func createMetricsExporter(
params exporter.CreateSettings,
cfg component.Config) (exporter.Metrics, error) {
eCfg := cfg.(*Config)
mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, eCfg.GMPConfig.toCollectorConfig(), params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout)
collectorConfig, err := eCfg.GMPConfig.toCollectorConfig()
if err != nil {
return nil, err
}
mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, collectorConfig, params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 9855133

Please sign in to comment.