Skip to content

Commit

Permalink
[surfacers.otel] Allow adding a prefix to metric names. (cloudprober#658
Browse files Browse the repository at this point in the history
)

- Default prefix is cloudprober_.
- This is important to identify cloudprober metrics on the final
metrics system.
  • Loading branch information
manugarg committed Dec 20, 2023
1 parent 5b8013b commit ae2ac84
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
4 changes: 2 additions & 2 deletions surfacers/internal/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ func (os *OtelSurfacer) convertMetric(em *metrics.EventMetrics, metricName strin

otelmetrics := func(data metricdata.Aggregation) metricdata.Metrics {
return metricdata.Metrics{
Name: metricName,
Description: metricName + " metric for Cloudprober",
Name: os.c.GetMetricsPrefix() + metricName,
Description: os.c.GetMetricsPrefix() + metricName + " metric for Cloudprober",
Unit: unit,
Data: data,
}
Expand Down
16 changes: 8 additions & 8 deletions surfacers/internal/otel/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func TestOtelSurfacerWrite(t *testing.T) {
"probe.p1": {
Scope: instrumentation.Scope{Name: "probe.p1"},
Metrics: []metricdata.Metrics{
testMetric("failures", "1", sumData(dataPoint[int64](20, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("latency", "us", sumData(dataPoint[float64](9.2, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("cloudprober_failures", "1", sumData(dataPoint[int64](20, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("cloudprober_latency", "us", sumData(dataPoint[float64](9.2, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
},
},
},
Expand All @@ -118,10 +118,10 @@ func TestOtelSurfacerWrite(t *testing.T) {
"probe.p2": {
Scope: instrumentation.Scope{Name: "probe.p2"},
Metrics: []metricdata.Metrics{
testMetric("resp_code", "1", sumData(
testMetric("cloudprober_resp_code", "1", sumData(
dataPoint[int64](2, [][2]string{{"probe", "p2"}, {"code", "200"}}, startTime, ems[1].Timestamp),
dataPoint[int64](1, [][2]string{{"probe", "p2"}, {"code", "500"}}, startTime, ems[1].Timestamp))),
testMetric("latency", "ms", metricdata.Histogram[float64]{
testMetric("cloudprober_latency", "ms", metricdata.Histogram[float64]{
DataPoints: []metricdata.HistogramDataPoint[float64]{
{
Attributes: attribute.NewSet(attribute.String("probe", "p2")),
Expand All @@ -146,10 +146,10 @@ func TestOtelSurfacerWrite(t *testing.T) {
"probe.p1": {
Scope: instrumentation.Scope{Name: "probe.p1"},
Metrics: []metricdata.Metrics{
testMetric("failures", "1", sumData(dataPoint[int64](20, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("latency", "us", sumData(dataPoint[float64](9.2, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("failures", "1", sumData(dataPoint[int64](25, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp.Add(2*time.Second)))),
testMetric("latency", "us", sumData(dataPoint[float64](8.7, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp.Add(2*time.Second)))),
testMetric("cloudprober_failures", "1", sumData(dataPoint[int64](20, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("cloudprober_latency", "us", sumData(dataPoint[float64](9.2, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp))),
testMetric("cloudprober_failures", "1", sumData(dataPoint[int64](25, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp.Add(2*time.Second)))),
testMetric("cloudprober_latency", "us", sumData(dataPoint[float64](8.7, [][2]string{{"probe", "p1"}}, startTime, ems[0].Timestamp.Add(2*time.Second)))),
},
},
},
Expand Down
38 changes: 27 additions & 11 deletions surfacers/internal/otel/proto/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions surfacers/internal/otel/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ message SurfacerConf {
GRPCExporter otlp_grpc_exporter = 2;
}

// How often metrics will be exported. Note that metrics are accumulated
// internally and exported at this interval. Increasing this value will
// increase the memory usage.
optional int32 export_interval_sec = 3 [default = 10];

// Prefix to use for metrics. Defaults to "cloudprober_".
optional string metrics_prefix = 4 [default = "cloudprober_"];
}
7 changes: 7 additions & 0 deletions surfacers/internal/otel/proto/config_proto_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ import "github.com/cloudprober/cloudprober/internal/tlsconfig/proto"
// OTLP gRPC exporter.
otlpGrpcExporter: #GRPCExporter @protobuf(2,GRPCExporter,name=otlp_grpc_exporter)
}

// How often metrics will be exported. Note that metrics are accumulated
// internally and exported at this interval. Increasing this value will
// increase the memory usage.
exportIntervalSec?: int32 @protobuf(3,int32,name=export_interval_sec,"default=10")

// Prefix to use for metrics. Defaults to "cloudprober_".
metricsPrefix?: string @protobuf(4,string,name=metrics_prefix,#"default="cloudprober_""#)
}

0 comments on commit ae2ac84

Please sign in to comment.