Skip to content

Commit

Permalink
Add harcoded namespace to spanmetrics (#540)
Browse files Browse the repository at this point in the history
* Add harcoded namespace to spanmetrics

* Update changelog

* Specify namespace default in docs
  • Loading branch information
mapno authored Apr 16, 2021
1 parent da91dc7 commit bc099ee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cross-compilation issue, but will return in v0.13.0.

- [ENHANCEMENT] Add `headers` field in `remote_write` config for Tempo. `headers`
specifies HTTP headers to forward to the remote endpoint. (@alexbiehl)
- [CHANGE] Add `tempo_spanmetrics` namespace in spanmetrics (@mapno)

- [BUGFIX] Grafana Agent running as a Windows service should start automatically on startup
(@mattdurham)
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,8 @@ spanmetrics:
metrics_exporter:
[ endpoint: <prometheusexporter.endpoint> ]
[ const_labels: <prometheusexporter.const_labels> ]
# Metrics are namespaced to `tempo_spanmetrics` by default.
# They can be further namespaced, i.e. `{namespace}_tempo_spanmetrics`
[ namespace: <prometheusexporter.namespace> ]
[ send_timestamps: <prometheusexporter.send_timestamps> ]
```
Expand Down
28 changes: 25 additions & 3 deletions pkg/tempo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,20 @@ type SpanMetricsConfig struct {
LatencyHistogramBuckets []time.Duration `yaml:"latency_histogram_buckets,omitempty"`
Dimensions []spanmetricsprocessor.Dimension `yaml:"dimensions,omitempty"`

// Configuration for Prometheus exporter: https://github.com/open-telemetry/opentelemetry-collector/blob/7d7ae2eb34/exporter/prometheusexporter/README.md.
MetricsExporter map[string]interface{} `yaml:"metrics_exporter,omitempty"`
// MetricsExporter is a Prometheus metrics exporter
MetricsExporter metricsExporterConfig `yaml:"metrics_exporter,omitempty"`
}

// Configuration for Prometheus exporter: https://github.com/open-telemetry/opentelemetry-collector/blob/7d7ae2eb34/exporter/prometheusexporter/README.md.
type metricsExporterConfig struct {
// The address on which the Prometheus scrape handler will be run on.
Endpoint string `yaml:"endpoint"`
// Namespace if set, exports metrics under the provided value.
Namespace string `yaml:"namespace"`
// ConstLabels are values that are applied for every exported metric.
ConstLabels map[string]interface{} `yaml:"const_labels"`
// SendTimestamps will send the underlying scrape timestamp with the export
SendTimestamps bool `yaml:"send_timestamps"`
}

// exporter builds an OTel exporter from RemoteWriteConfig
Expand Down Expand Up @@ -300,7 +312,17 @@ func (c *InstanceConfig) otelConfig() (*configmodels.Config, error) {

if c.SpanMetrics != nil {
// Configure the metrics exporter.
exporters[defaultSpanMetricsExporter] = c.SpanMetrics.MetricsExporter
namespace := "tempo_spanmetrics"
if len(c.SpanMetrics.MetricsExporter.Namespace) != 0 {
namespace = fmt.Sprintf("%s_%s", c.SpanMetrics.MetricsExporter.Namespace, namespace)
}

exporters[defaultSpanMetricsExporter] = map[string]interface{}{
"endpoint": c.SpanMetrics.MetricsExporter.Endpoint,
"namespace": namespace,
"const_labels": c.SpanMetrics.MetricsExporter.ConstLabels,
"send_timestamps": c.SpanMetrics.MetricsExporter.SendTimestamps,
}

processorNames = append(processorNames, "spanmetrics")
processors["spanmetrics"] = map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion pkg/tempo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ exporters:
max_elapsed_time: 60s
prometheus:
endpoint: "0.0.0.0:8889"
namespace: promexample
namespace: promexample_tempo_spanmetrics
processors:
spanmetrics:
metrics_exporter: prometheus
Expand Down

0 comments on commit bc099ee

Please sign in to comment.