Skip to content

Commit a2789c4

Browse files
committed
address feedback and add readme
1 parent c3e8c84 commit a2789c4

File tree

6 files changed

+78
-11
lines changed

6 files changed

+78
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Google Managed Service for Prometheus Collector Exporter
2+
3+
## Building a container image with the googlemanagedprometheus exporter
4+
5+
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:
6+
```yaml
7+
exporters:
8+
- gomod: "github.com/GoogleCloudPlatform/exporter/collector/googlemanagedprometheus v0.29.0"
9+
```
10+
11+
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).
12+
13+
In the `configs` directory, add your collector configuration yaml file, which should look something like:
14+
15+
```yaml
16+
receivers:
17+
prometheus:
18+
config:
19+
scrape_configs:
20+
# TODO: Add your prometheus scrape configuration here.
21+
# Using kubernetes_sd_configs with namespaced resources
22+
# ensures the namespace is set on your metrics.
23+
processors:
24+
batch:
25+
# batch metrics before sending to reduce API usage
26+
send_batch_max_size: 200
27+
send_batch_size: 200
28+
timeout: 5s
29+
memory_limiter:
30+
# drop metrics if memory usage gets too high
31+
check_interval: 1s
32+
limit_percentage: 65
33+
spike_limit_percentage: 20
34+
resourcedetection:
35+
# detect cluster name and location
36+
detectors: [gce, gke]
37+
timeout: 10s
38+
exporters:
39+
googlemanagedprometheus:
40+
```
41+
42+
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).
43+
44+
Finally, build the image:
45+
46+
```sh
47+
DISTRIBUTIONS=my-distribution make build
48+
```
49+
50+
## Additional Options
51+
52+
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.

exporter/collector/googlemanagedprometheus/factory.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func createDefaultConfig() config.Exporter {
4848
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
4949
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
5050
GMPConfig: GMPConfig{
51-
UserAgent: "opentelemetry-collector-contrib {{version}}",
51+
UserAgent: "opentelemetry-collector-contrib/{{version}}",
5252
},
5353
}
5454
}
@@ -83,7 +83,9 @@ func (c *GMPConfig) toCollectorConfig() collector.Config {
8383
cfg.MetricConfig.SkipCreateMetricDescriptor = true
8484
cfg.MetricConfig.InstrumentationLibraryLabels = false
8585
cfg.MetricConfig.ServiceResourceLabels = false
86+
// Update metric naming to match GMP conventions
8687
cfg.MetricConfig.GetMetricName = GetMetricName
88+
// Map to the prometheus_target monitored resource
8789
cfg.MetricConfig.MapMonitoredResource = MapToPrometheusTarget
8890
cfg.MetricConfig.EnableSumOfSquaredDeviation = true
8991
// TODO: Change to GMP's method of reset handling.

exporter/collector/googlemanagedprometheus/naming.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,34 @@
1515
package googlemanagedprometheus
1616

1717
import (
18+
"strings"
19+
1820
"go.opentelemetry.io/collector/model/pdata"
1921
"go.opentelemetry.io/collector/pdata/pmetric"
2022
)
2123

2224
func GetMetricName(baseName string, metric pdata.Metric) string {
23-
return baseName + gmpMetricSuffix(metric)
24-
}
25-
26-
func gmpMetricSuffix(metric pdata.Metric) string {
2725
switch metric.DataType() {
2826
case pmetric.MetricDataTypeSum:
29-
return "/counter"
27+
return baseName + "/counter"
3028
case pmetric.MetricDataTypeGauge:
31-
return "/gauge"
29+
return baseName + "/gauge"
3230
case pmetric.MetricDataTypeSummary:
33-
return "/summary"
31+
// summaries are sent as the following series:
32+
// * Sum: prometheus.googleapis.com/<baseName>_sum/summary:counter
33+
// * Count: prometheus.googleapis.com/<baseName>_count/summary
34+
// * Quantiles: prometheus.googleapis.com/<baseName>/summary
35+
if strings.HasSuffix(baseName, "_sum") {
36+
return baseName + "/summary:counter"
37+
}
38+
return baseName + "/summary"
3439
case pmetric.MetricDataTypeHistogram:
35-
return "/histogram"
40+
return baseName + "/histogram"
41+
case pmetric.MetricDataTypeExponentialHistogram:
42+
return baseName + "/exponentialhistogram"
3643
default:
44+
// This should never happen, as we have already dropped other data
45+
// types at this point.
3746
return ""
3847
}
3948
}

exporter/collector/googlemanagedprometheus/naming_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestGetMetricName(t *testing.T) {
5151
{
5252
desc: "other",
5353
datatype: pmetric.MetricDataTypeExponentialHistogram,
54-
expected: baseName,
54+
expected: baseName + "/exponentialhistogram",
5555
},
5656
} {
5757
t.Run(tc.desc, func(t *testing.T) {

exporter/collector/integrationtest/testdata/config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ service:
2424
receivers: [nop]
2525
processors: [nop]
2626
exporters: [googlecloud]
27+
metrics:
28+
receivers: [nop]
29+
processors: [nop]
30+
exporters: [googlecloud]
2731

exporter/collector/integrationtest/testdata/gmp_config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exporters:
1414

1515
service:
1616
pipelines:
17-
traces:
17+
metrics:
1818
receivers: [nop]
1919
processors: [nop]
2020
exporters: [googlemanagedprometheus]

0 commit comments

Comments
 (0)