Skip to content

Commit

Permalink
otelcol.exporter.prometheus add_metrics_suffixes option (#5568)
Browse files Browse the repository at this point in the history
* otelcol.exporter.prometheus add add_metrics_suffixes option

* otelcol.exporter.prometheus add add_metrics_suffixes option. Add tests

* otelcol.exporter.prometheus add add_metrics_suffixes option. Update docs

* otelcol.exporter.prometheus add add_metrics_suffixes option. Added changelog, fixed readme

* otelcol.exporter.prometheus add add_metric_suffixes option. Fix option name

* otelcol.exporter.prometheus add add_metric_suffixes option. Add more tests

* otelcol.exporter.prometheus add add_metric_suffixes option. Added convertArgumentsToConvertOptions

* otelcol.exporter.prometheus add add_metric_suffixes option. Fix changelog message
  • Loading branch information
mar4uk authored Oct 25, 2023
1 parent c0a52bc commit 5a7c16a
Show file tree
Hide file tree
Showing 6 changed files with 556 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Main (unreleased)
- `otelcol.receiver.kafka` has a new `version` argument to change the version of
the SASL Protocol for SASL authentication.

- Added an `add_metric_suffixes` option to `otelcol.exporter.prometheus` in flow mode,
which configures whether to add type and unit suffixes to metrics names. (@mar4uk)

v0.37.2 (2023-10-16)
-----------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Options struct {
// IncludeScopeLabels includes the otel_scope_name and otel_scope_version
// labels from the scope in the metrics.
IncludeScopeLabels bool
// AddMetricSuffixes controls whether suffixes are added to metric names. Defaults to true.
AddMetricSuffixes bool
}

var _ consumer.Metrics = (*Converter)(nil)
Expand Down Expand Up @@ -286,8 +288,7 @@ func (conv *Converter) consumeMetric(app storage.Appender, memResource *memorySe
}

func (conv *Converter) consumeGauge(app storage.Appender, memResource *memorySeries, memScope *memorySeries, m pmetric.Metric) {
// TODO: should we make the param addMetricSuffixes configurable? For now we set the default value (true) to keep the same behavior as before
metricName := prometheus.BuildCompliantName(m, "", true)
metricName := prometheus.BuildCompliantName(m, "", conv.opts.AddMetricSuffixes)

metricMD := conv.createOrUpdateMetadata(metricName, metadata.Metadata{
Type: textparse.MetricTypeGauge,
Expand Down Expand Up @@ -389,7 +390,7 @@ func getNumberDataPointValue(dp pmetric.NumberDataPoint) float64 {
}

func (conv *Converter) consumeSum(app storage.Appender, memResource *memorySeries, memScope *memorySeries, m pmetric.Metric) {
metricName := prometheus.BuildCompliantName(m, "", true)
metricName := prometheus.BuildCompliantName(m, "", conv.opts.AddMetricSuffixes)

// Excerpt from the spec:
//
Expand Down Expand Up @@ -447,7 +448,7 @@ func (conv *Converter) consumeSum(app storage.Appender, memResource *memorySerie
}

func (conv *Converter) consumeHistogram(app storage.Appender, memResource *memorySeries, memScope *memorySeries, m pmetric.Metric) {
metricName := prometheus.BuildCompliantName(m, "", true)
metricName := prometheus.BuildCompliantName(m, "", conv.opts.AddMetricSuffixes)

if m.Histogram().AggregationTemporality() != pmetric.AggregationTemporalityCumulative {
// Drop non-cumulative histograms for now, which is permitted by the spec.
Expand Down Expand Up @@ -606,7 +607,7 @@ func (conv *Converter) convertExemplar(otelExemplar pmetric.Exemplar, ts time.Ti
}

func (conv *Converter) consumeSummary(app storage.Appender, memResource *memorySeries, memScope *memorySeries, m pmetric.Metric) {
metricName := prometheus.BuildCompliantName(m, "", true)
metricName := prometheus.BuildCompliantName(m, "", conv.opts.AddMetricSuffixes)

metricMD := conv.createOrUpdateMetadata(metricName, metadata.Metadata{
Type: textparse.MetricTypeSummary,
Expand Down
Loading

0 comments on commit 5a7c16a

Please sign in to comment.