From 2f716b8bddee18e81c59041dbc29e561c904052f Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Thu, 7 Jul 2022 15:22:01 +0000 Subject: [PATCH] Remove GMP factory functions and readme --- .../googlemanagedprometheus/README.md | 87 ----------------- .../googlemanagedprometheus/config.go | 52 ---------- .../googlemanagedprometheus/factory.go | 96 ------------------- 3 files changed, 235 deletions(-) delete mode 100644 exporter/collector/googlemanagedprometheus/README.md delete mode 100644 exporter/collector/googlemanagedprometheus/config.go delete mode 100644 exporter/collector/googlemanagedprometheus/factory.go diff --git a/exporter/collector/googlemanagedprometheus/README.md b/exporter/collector/googlemanagedprometheus/README.md deleted file mode 100644 index 3a53959c8..000000000 --- a/exporter/collector/googlemanagedprometheus/README.md +++ /dev/null @@ -1,87 +0,0 @@ -# Google Managed Service for Prometheus Collector Exporter - -## Building a container image with the googlemanagedprometheus exporter - -In your own fork of [open-telemetry/opentelemetry-collector-releases](https://github.com/open-telemetry/opentelemetry-collector-releases), add your own "distribution" directory within the distributions directory, based on either the otelcol or otelcol-contrib distributions. In the `exporters` list in `manifest.yaml`, add: -```yaml -exporters: - - gomod: "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.30.1" -``` - -The syntax of `manifest.yaml` is described in the [Collector Builder documentation](https://github.com/open-telemetry/opentelemetry-collector/blob/54f271b7d473f36b4ecbc21994d59359dbd263f6/cmd/builder/README.md#opentelemetry-collector-builder). - -In the `configs` directory, add your collector configuration yaml file, which should look something like: - -```yaml -receivers: - prometheus: - config: - scrape_configs: - # Add your prometheus scrape configuration here. - # Using kubernetes_sd_configs with namespaced resources - # ensures the namespace is set on your metrics. - - job_name: 'kubernetes-pods' - kubernetes_sd_configs: - - role: pod - relabel_configs: - - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] - action: keep - regex: true - - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] - action: replace - target_label: __metrics_path__ - regex: (.+) - - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] - action: replace - regex: (.+):(?:\d+);(\d+) - replacement: $$1:$$2 - target_label: __address__ - - action: labelmap - regex: __meta_kubernetes_pod_label_(.+) -processors: - # groupbyattrs promotes labels from metrics to resources, allowing them to - # be added to the prometheus_target monitored resource. - # This allows exporters which monitor multiple namespaces, such as - # kube-state-metrics, to override the namespace in the resource by setting - # metric labels. - groupbyattrs: - keys: - - namespace - - cluster - - location - batch: - # batch metrics before sending to reduce API usage - send_batch_max_size: 200 - send_batch_size: 200 - timeout: 5s - memory_limiter: - # drop metrics if memory usage gets too high - check_interval: 1s - limit_percentage: 65 - spike_limit_percentage: 20 - resourcedetection: - # detect cluster name and location - detectors: [gce, gke] - timeout: 10s -exporters: - googlemanagedprometheus: - -service: - pipelines: - metrics: - receivers: [prometheus] - processors: [groupbyattrs, batch, memory_limiter, resourcedetection] - exporters: [googlemanagedprometheus] -``` - -Change the Dockerfile in your directory within `distributions` to point to your collector config [here](https://github.com/open-telemetry/opentelemetry-collector-releases/blob/main/distributions/otelcol-contrib/Dockerfile#L17). - -Finally, build the image: - -```sh -DISTRIBUTIONS=my-distribution make build -``` - -## Additional Options - -The [filterprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor) can filter out metrics. The [metricstransformprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstransformprocessor) can manipulate metrics in a variety of ways, including synthesizing new metrics from other metrics, adding or removing labels, renaming metrics, and scaling metrics. `metric_relabl_configs` within the prometheus receiver configuration can also be used to manipulate metrics. diff --git a/exporter/collector/googlemanagedprometheus/config.go b/exporter/collector/googlemanagedprometheus/config.go deleted file mode 100644 index f07231a94..000000000 --- a/exporter/collector/googlemanagedprometheus/config.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package googlemanagedprometheus - -import ( - "fmt" - - "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/exporter/exporterhelper" - - "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" -) - -// Config defines configuration for Google Cloud Managed Service for Prometheus exporter. -type Config struct { - config.ExporterSettings `mapstructure:",squash"` - GMPConfig `mapstructure:",squash"` - - // Timeout for all API calls. If not set, defaults to 12 seconds. - exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. - exporterhelper.QueueSettings `mapstructure:"sending_queue"` - exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` -} - -// GMPConfig is a subset of the collector config. -type GMPConfig struct { - ProjectID string `mapstructure:"project"` - UserAgent string `mapstructure:"user_agent"` - ClientConfig collector.ClientConfig `mapstructure:",squash"` -} - -func (cfg *Config) Validate() error { - if err := cfg.ExporterSettings.Validate(); err != nil { - return fmt.Errorf("exporter settings are invalid :%w", err) - } - if err := collector.ValidateConfig(cfg.toCollectorConfig()); err != nil { - return fmt.Errorf("exporter settings are invalid :%w", err) - } - return nil -} diff --git a/exporter/collector/googlemanagedprometheus/factory.go b/exporter/collector/googlemanagedprometheus/factory.go deleted file mode 100644 index e08a3d767..000000000 --- a/exporter/collector/googlemanagedprometheus/factory.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package googlemanagedprometheus - -import ( - "context" - "time" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/exporter/exporterhelper" - - "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" -) - -const ( - // The value of "type" key in configuration. - typeStr = "googlemanagedprometheus" - defaultTimeout = 12 * time.Second // Consistent with Cloud Monitoring's timeout -) - -// NewFactory creates a factory for the googlemanagedprometheus exporter -func NewFactory() component.ExporterFactory { - return component.NewExporterFactory( - typeStr, - createDefaultConfig, - component.WithMetricsExporter(createMetricsExporter), - ) -} - -// createDefaultConfig creates the default configuration for exporter. -func createDefaultConfig() config.Exporter { - return &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), - TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout}, - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), - GMPConfig: GMPConfig{ - UserAgent: "opentelemetry-collector-contrib/{{version}}", - }, - } -} - -// createMetricsExporter creates a metrics exporter based on this config. -func createMetricsExporter( - ctx context.Context, - params component.ExporterCreateSettings, - cfg config.Exporter) (component.MetricsExporter, error) { - eCfg := cfg.(*Config) - mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, eCfg.GMPConfig.toCollectorConfig(), params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout) - if err != nil { - return nil, err - } - return exporterhelper.NewMetricsExporter( - cfg, - params, - mExp.PushMetrics, - exporterhelper.WithShutdown(mExp.Shutdown), - // Disable exporterhelper Timeout, since we are using a custom mechanism - // within exporter itself - exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}), - exporterhelper.WithQueue(eCfg.QueueSettings), - exporterhelper.WithRetry(eCfg.RetrySettings)) -} - -func (c *GMPConfig) toCollectorConfig() collector.Config { - // start with whatever the default collector config is. - cfg := collector.DefaultConfig() - // hard-code some config options to make it work with GMP - cfg.MetricConfig.Prefix = "prometheus.googleapis.com" - cfg.MetricConfig.SkipCreateMetricDescriptor = true - cfg.MetricConfig.InstrumentationLibraryLabels = false - cfg.MetricConfig.ServiceResourceLabels = false - // Update metric naming to match GMP conventions - cfg.MetricConfig.GetMetricName = GetMetricName - // Map to the prometheus_target monitored resource - cfg.MetricConfig.MapMonitoredResource = 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.ClientConfig - return cfg -}