Skip to content

Commit

Permalink
Upgrade OTel components to v0.89.0
Browse files Browse the repository at this point in the history
Change-Id: I070c2bb5203054607740889fad80678310e92aa2
Signed-off-by: Ridwan Sharif <[email protected]>
  • Loading branch information
ridwanmsharif committed Nov 27, 2023
1 parent 3b1bbb9 commit d3ef1ce
Show file tree
Hide file tree
Showing 34 changed files with 717 additions and 606 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN go install github.com/client9/misspell/cmd/[email protected] \
RUN apt update && apt install -y make
RUN make build

FROM alpine:3
FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /sidecar/bin/rungmpcol /rungmpcol
COPY --from=builder /sidecar/bin/run-gmp-entrypoint /run-gmp-entrypoint
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ 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)
go mod tidy
cd $(TOOLS_DIR) && go get -u github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen@$(OTEL_VER)
cd $(TOOLS_DIR) && go mod tidy

# We can bring this target back when https://github.com/open-telemetry/opentelemetry-collector/issues/8063 is resolved.
update-opentelemetry:
Expand All @@ -68,11 +67,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
28 changes: 15 additions & 13 deletions collector/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,30 @@ 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
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.untypedDoubleExport", 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
18 changes: 12 additions & 6 deletions collector/exporter/googlemanagedprometheusexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/otelcol/otelcoltest"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"github.com/GoogleCloudPlatform/run-gmp-sidecar/collector/exporter/googlemanagedprometheusexporter/internal/metadata"
)

Expand All @@ -29,7 +30,7 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, cfg)

assert.Equal(t, len(cfg.Exporters), 3)
assert.Equal(t, len(cfg.Exporters), 2)

r0 := cfg.Exporters[component.NewID(metadata.Type)].(*Config)
assert.Equal(t, r0, factory.CreateDefaultConfig().(*Config))
Expand All @@ -43,6 +44,16 @@ func TestLoadConfig(t *testing.T) {
GMPConfig: GMPConfig{
ProjectID: "my-project",
UserAgent: "opentelemetry-collector-contrib {{version}}",
MetricConfig: MetricConfig{
Config: googlemanagedprometheus.Config{
AddMetricSuffixes: false,
ExtraMetricsConfig: googlemanagedprometheus.ExtraMetricsConfig{
EnableTargetInfo: false,
EnableScopeInfo: false,
},
},
Prefix: "my-metric-domain.com",
},
},
RetrySettings: exporterhelper.RetrySettings{
Enabled: true,
Expand All @@ -58,9 +69,4 @@ func TestLoadConfig(t *testing.T) {
QueueSize: 10,
},
})

r2 := cfg.Exporters[component.NewIDWithName(metadata.Type, "customprefix")].(*Config)
r2Expected := factory.CreateDefaultConfig().(*Config)
r2Expected.GMPConfig.MetricConfig.Prefix = "my-metric-domain.com"
assert.Equal(t, r2, r2Expected)
}
11 changes: 10 additions & 1 deletion collector/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 @@ -49,7 +55,10 @@ func createMetricsExporter(
eCfg := cfg.(*Config)

// We turn off normalization for serverless environments.
collectorConfig := eCfg.GMPConfig.toCollectorConfig()
collectorConfig, err := eCfg.GMPConfig.toCollectorConfig()
if err != nil {
return nil, err
}
collectorConfig.MetricConfig.CumulativeNormalization = false
mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, collectorConfig, params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ exporters:
initial_interval: 10s
max_interval: 60s
max_elapsed_time: 10m
googlemanagedprometheus/customprefix:
metric:
prefix: my-metric-domain.com
add_metric_suffixes: false
extra_metrics_config:
enable_target_info: false
enable_scope_info: false


service:
Expand Down
7 changes: 4 additions & 3 deletions collector/receiver/prometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ type MetricAdjusterOpts struct {

// Config defines configuration for Prometheus receiver.
type Config struct {
PrometheusConfig *promconfig.Config `mapstructure:"-"`
BufferPeriod time.Duration `mapstructure:"buffer_period"`
BufferCount int `mapstructure:"buffer_count"`
PrometheusConfig *promconfig.Config `mapstructure:"-"`
TrimMetricSuffixes bool `mapstructure:"trim_metric_suffixes"`
BufferPeriod time.Duration `mapstructure:"buffer_period"`
BufferCount int `mapstructure:"buffer_count"`

// PreserveUntyped is a setting that lets the collector preserve the untypedness of
// untyped metrics as a metric attribute. If set, all untyped prometheus metrics from
Expand Down
1 change: 1 addition & 0 deletions collector/receiver/prometheusreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestLoadConfig(t *testing.T) {
assert.Equal(t, r1.PrometheusConfig.ScrapeConfigs[0].JobName, "demo")
assert.Equal(t, time.Duration(r1.PrometheusConfig.ScrapeConfigs[0].ScrapeInterval), 5*time.Second)
assert.Equal(t, r1.AdjusterOpts.UseStartTimeMetric, true)
assert.Equal(t, r1.TrimMetricSuffixes, true)
assert.Equal(t, r1.AdjusterOpts.StartTimeMetricRegex, "^(.+_)*process_start_time_seconds$")

assert.Equal(t, "http://my-targetallocator-service", r1.TargetAllocator.Endpoint)
Expand Down
2 changes: 1 addition & 1 deletion collector/receiver/prometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ func createMetricsReceiver(
cfg component.Config,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
return newPrometheusReceiver(set, cfg.(*Config), nextConsumer, featuregate.GlobalRegistry()), nil
return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil
}
15 changes: 7 additions & 8 deletions collector/receiver/prometheusreceiver/internal/appendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper"
)

// appendable translates Prometheus scraping diffs into OpenTelemetry format.
type appendable struct {
sink consumer.Metrics
metricAdjuster MetricsAdjuster
useStartTimeMetric bool
trimSuffixes bool
preserveUntyped bool
startTimeMetricRegex *regexp.Regexp
externalLabels labels.Labels

settings receiver.CreateSettings
obsrecv *obsreport.Receiver
registry *featuregate.Registry
obsrecv *receiverhelper.ObsReport
}

// NewAppendable returns a storage.Appendable instance that emits metrics to the sink.
Expand All @@ -53,15 +52,15 @@ func NewAppendable(
useCollectorStartTimeFallback bool,
allowCumulativeResets bool,
externalLabels labels.Labels,
registry *featuregate.Registry) (storage.Appendable, error) {
trimSuffixes bool) (storage.Appendable, error) {
var metricAdjuster MetricsAdjuster
if !useStartTimeMetric {
metricAdjuster = NewInitialPointAdjuster(set.Logger, gcInterval, useCreatedMetric)
} else {
metricAdjuster = NewStartTimeMetricAdjuster(set.Logger, gcInterval, startTimeMetricRegex, useCollectorStartTimeFallback, allowCumulativeResets)
}

obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: set.ID, Transport: transport, ReceiverCreateSettings: set})
obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ReceiverID: set.ID, Transport: transport, ReceiverCreateSettings: set})
if err != nil {
return nil, err
}
Expand All @@ -71,14 +70,14 @@ func NewAppendable(
settings: set,
metricAdjuster: metricAdjuster,
useStartTimeMetric: useStartTimeMetric,
trimSuffixes: trimSuffixes,
startTimeMetricRegex: startTimeMetricRegex,
externalLabels: externalLabels,
obsrecv: obsrecv,
registry: registry,
preserveUntyped: preserveUntyped,
}, nil
}

func (o *appendable) Appender(ctx context.Context) storage.Appender {
return newTransaction(ctx, o.metricAdjuster, o.sink, o.externalLabels, o.settings, o.obsrecv, o.registry, o.preserveUntyped)
return newTransaction(ctx, o.metricAdjuster, o.sink, o.externalLabels, o.settings, o.obsrecv, o.trimSuffixes, o.preserveUntyped)
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,13 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels
return nil
}

func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, normalizer *prometheus.Normalizer) {
func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, trimSuffixes bool) {
metric := pmetric.NewMetric()
// Trims type's and unit's suffixes from metric name
metric.SetName(normalizer.TrimPromSuffixes(mf.name, mf.mtype, mf.metadata.Unit))
name := mf.name
if trimSuffixes {
name = prometheus.TrimPromSuffixes(name, mf.mtype, mf.metadata.Unit)
}
metric.SetName(name)
metric.SetDescription(mf.metadata.Help)
metric.SetUnit(mf.metadata.Unit)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ import (
"github.com/prometheus/prometheus/model/value"
"github.com/prometheus/prometheus/scrape"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus"
)

type testMetadataStore map[string]scrape.MetricMetadata
Expand Down Expand Up @@ -263,7 +260,7 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) {
require.Len(t, mp.groups, 1)

sl := pmetric.NewMetricSlice()
mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry()))
mp.appendMetric(sl, false)

require.Equal(t, 1, sl.Len(), "Exactly one metric expected")
metric := sl.At(0)
Expand Down Expand Up @@ -551,7 +548,7 @@ func TestMetricGroupData_toSummaryUnitTest(t *testing.T) {
require.Len(t, mp.groups, 1)

sl := pmetric.NewMetricSlice()
mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry()))
mp.appendMetric(sl, false)

require.Equal(t, 1, sl.Len(), "Exactly one metric expected")
metric := sl.At(0)
Expand Down Expand Up @@ -657,7 +654,7 @@ func TestMetricGroupData_toNumberDataUnitTest(t *testing.T) {
require.Len(t, mp.groups, 1)

sl := pmetric.NewMetricSlice()
mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry()))
mp.appendMetric(sl, false)

require.Equal(t, 1, sl.Len(), "Exactly one metric expected")
metric := sl.At(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ service:
require.NoError(t, err)

appSettings := otelcol.CollectorSettings{
Factories: factories,
Factories: func() (otelcol.Factories, error) { return factories, nil },
ConfigProvider: configProvider,
BuildInfo: component.BuildInfo{
Command: "otelcol",
Expand Down
Loading

0 comments on commit d3ef1ce

Please sign in to comment.