Skip to content

Commit

Permalink
prometheus: send span metrics (#40)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
edeNFed authored Nov 24, 2022
1 parent 99f1815 commit 0c52819
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autoscaler/controllers/datacollection/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
24 changes: 24 additions & 0 deletions autoscaler/controllers/gateway/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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",
}
}
}

0 comments on commit 0c52819

Please sign in to comment.