From 0c52819129028ae3868fe61305ac0bebd55291ef Mon Sep 17 00:00:00 2001 From: Eden Federman Date: Thu, 24 Nov 2022 10:31:28 +0200 Subject: [PATCH] prometheus: send span metrics (#40) This PR adds the ability to send metrics that are calculated based on distributed traces to Prometheus. Metrics are generated using the [SpanMetrics processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/spanmetricsprocessor). --- .../controllers/datacollection/configmap.go | 6 +++-- .../controllers/gateway/config/prometheus.go | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/autoscaler/controllers/datacollection/configmap.go b/autoscaler/controllers/datacollection/configmap.go index 08eeb4762..e7281fbb6 100644 --- a/autoscaler/controllers/datacollection/configmap.go +++ b/autoscaler/controllers/datacollection/configmap.go @@ -148,9 +148,11 @@ func getConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *odigosv for _, s := range dst.Spec.Signals { if s == common.LogsObservabilitySignal && !custom.DestRequiresCustom(dst.Spec.Type) { collectLogs = true - } else if s == common.TracesObservabilitySignal { + } + if s == common.TracesObservabilitySignal || dst.Spec.Type == common.PrometheusDestinationType { collectTraces = true - } else if s == common.MetricsObservabilitySignal && !custom.DestRequiresCustom(dst.Spec.Type) { + } + if s == common.MetricsObservabilitySignal && !custom.DestRequiresCustom(dst.Spec.Type) { collectMetrics = true } } diff --git a/autoscaler/controllers/gateway/config/prometheus.go b/autoscaler/controllers/gateway/config/prometheus.go index b91ee6995..b29dc7774 100644 --- a/autoscaler/controllers/gateway/config/prometheus.go +++ b/autoscaler/controllers/gateway/config/prometheus.go @@ -23,6 +23,7 @@ func (p *Prometheus) ModifyConfig(dest *odigosv1.Destination, currentConfig *com url := addProtocol(url) url = strings.TrimSuffix(url, "/api/v1/write") rwExporterName := "prometheusremotewrite/prometheus" + spanMetricsProcessorName := "spanmetrics" currentConfig.Exporters[rwExporterName] = commonconf.GenericMap{ "endpoint": fmt.Sprintf("%s/api/v1/write", url), } @@ -32,5 +33,28 @@ func (p *Prometheus) ModifyConfig(dest *odigosv1.Destination, currentConfig *com Processors: []string{"batch"}, Exporters: []string{rwExporterName}, } + + // Send SpanMetrics to prometheus + currentConfig.Service.Pipelines["traces/spanmetrics"] = commonconf.Pipeline{ + Receivers: []string{"otlp"}, + Processors: []string{spanMetricsProcessorName}, + Exporters: []string{"logging"}, + } + currentConfig.Exporters["logging"] = struct{}{} // Dummy exporter, needed only because pipeline must have an exporter + currentConfig.Processors[spanMetricsProcessorName] = commonconf.GenericMap{ + "metrics_exporter": rwExporterName, + "latency_histogram_buckets": []string{"100us", "1ms", "2ms", "6ms", "10ms", "100ms", "250ms"}, + "dimensions": []commonconf.GenericMap{ + { + "name": "http.method", + "default": "GET", + }, + { + "name": "http.status_code", + }, + }, + "dimensions_cache_size": 1000, + "aggregation_temporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + } } }