Skip to content

Commit

Permalink
address feedback and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Apr 28, 2022
1 parent c3e8c84 commit a2789c4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
52 changes: 52 additions & 0 deletions exporter/collector/googlemanagedprometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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/exporter/collector/googlemanagedprometheus v0.29.0"
```
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:
# TODO: Add your prometheus scrape configuration here.
# Using kubernetes_sd_configs with namespaced resources
# ensures the namespace is set on your metrics.
processors:
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:
```

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.
4 changes: 3 additions & 1 deletion exporter/collector/googlemanagedprometheus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createDefaultConfig() config.Exporter {
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
GMPConfig: GMPConfig{
UserAgent: "opentelemetry-collector-contrib {{version}}",
UserAgent: "opentelemetry-collector-contrib/{{version}}",
},
}
}
Expand Down Expand Up @@ -83,7 +83,9 @@ func (c *GMPConfig) toCollectorConfig() collector.Config {
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
// TODO: Change to GMP's method of reset handling.
Expand Down
25 changes: 17 additions & 8 deletions exporter/collector/googlemanagedprometheus/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,34 @@
package googlemanagedprometheus

import (
"strings"

"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/pdata/pmetric"
)

func GetMetricName(baseName string, metric pdata.Metric) string {
return baseName + gmpMetricSuffix(metric)
}

func gmpMetricSuffix(metric pdata.Metric) string {
switch metric.DataType() {
case pmetric.MetricDataTypeSum:
return "/counter"
return baseName + "/counter"
case pmetric.MetricDataTypeGauge:
return "/gauge"
return baseName + "/gauge"
case pmetric.MetricDataTypeSummary:
return "/summary"
// summaries are sent as the following series:
// * Sum: prometheus.googleapis.com/<baseName>_sum/summary:counter
// * Count: prometheus.googleapis.com/<baseName>_count/summary
// * Quantiles: prometheus.googleapis.com/<baseName>/summary
if strings.HasSuffix(baseName, "_sum") {
return baseName + "/summary:counter"
}
return baseName + "/summary"
case pmetric.MetricDataTypeHistogram:
return "/histogram"
return baseName + "/histogram"
case pmetric.MetricDataTypeExponentialHistogram:
return baseName + "/exponentialhistogram"
default:
// This should never happen, as we have already dropped other data
// types at this point.
return ""
}
}
2 changes: 1 addition & 1 deletion exporter/collector/googlemanagedprometheus/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestGetMetricName(t *testing.T) {
{
desc: "other",
datatype: pmetric.MetricDataTypeExponentialHistogram,
expected: baseName,
expected: baseName + "/exponentialhistogram",
},
} {
t.Run(tc.desc, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions exporter/collector/integrationtest/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ service:
receivers: [nop]
processors: [nop]
exporters: [googlecloud]
metrics:
receivers: [nop]
processors: [nop]
exporters: [googlecloud]

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exporters:

service:
pipelines:
traces:
metrics:
receivers: [nop]
processors: [nop]
exporters: [googlemanagedprometheus]

0 comments on commit a2789c4

Please sign in to comment.