Skip to content

Commit 3efc14b

Browse files
authored
[CONFIGURATION] File configuration - prometheus translation (#3715)
1 parent 227fbdc commit 3efc14b

19 files changed

+257
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Increment the:
2626
* [CI] Upgrade tools/vcpkg to 2025.09.17
2727
[#3701](https://github.com/open-telemetry/opentelemetry-cpp/pull/3701)
2828

29+
* [CONFIGURATION] File configuration - prometheus translation
30+
[#3715](https://github.com/open-telemetry/opentelemetry-cpp/pull/3715)
31+
2932
## [1.23 2025-09-25]
3033

3134
* [CodeHealth] Fix clang-tidy warnings part 6

exporters/prometheus/src/prometheus_pull_builder.cc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include "opentelemetry/exporters/prometheus/exporter_factory.h"
99
#include "opentelemetry/exporters/prometheus/exporter_options.h"
1010
#include "opentelemetry/exporters/prometheus/prometheus_pull_builder.h"
11+
#include "opentelemetry/sdk/common/global_log_handler.h"
1112
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h"
1213
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h"
1314
#include "opentelemetry/sdk/configuration/registry.h"
15+
#include "opentelemetry/sdk/configuration/translation_strategy.h"
1416
#include "opentelemetry/sdk/metrics/metric_reader.h"
1517
#include "opentelemetry/version.h"
1618

@@ -38,8 +40,36 @@ std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> PrometheusPullBuilder
3840
options.url = url;
3941
options.populate_target_info = true;
4042
options.without_otel_scope = model->without_scope_info;
41-
options.without_units = model->without_units;
42-
options.without_type_suffix = model->without_type_suffix;
43+
44+
switch (model->translation_strategy)
45+
{
46+
case sdk::configuration::TranslationStrategy::UnderscoreEscapingWithSuffixes:
47+
options.without_units = false;
48+
options.without_type_suffix = false;
49+
break;
50+
case sdk::configuration::TranslationStrategy::UnderscoreEscapingWithoutSuffixes:
51+
options.without_units = true;
52+
options.without_type_suffix = true;
53+
break;
54+
case sdk::configuration::TranslationStrategy::NoUTF8EscapingWithSuffixes:
55+
// FIXME: no flag to disable UnderscoreEscaping
56+
OTEL_INTERNAL_LOG_WARN("[Prometheus Exporter] NoUTF8EscapingWithSuffixes not supported");
57+
options.without_units = false;
58+
options.without_type_suffix = false;
59+
break;
60+
case sdk::configuration::TranslationStrategy::NoTranslation:
61+
// FIXME: no flag to disable UnderscoreEscaping
62+
OTEL_INTERNAL_LOG_WARN("[Prometheus Exporter] NoTranslation not supported");
63+
options.without_units = true;
64+
options.without_type_suffix = true;
65+
break;
66+
}
67+
68+
if (model->with_resource_constant_labels != nullptr)
69+
{
70+
// FIXME: with_resource_constant_labels
71+
OTEL_INTERNAL_LOG_WARN("[Prometheus Exporter] with_resource_constant_labels not supported");
72+
}
4373

4474
return PrometheusExporterFactory::Create(options);
4575
}

functional/configuration/shelltests/kitchen-sink.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ $ example_yaml --test --yaml shelltests/kitchen-sink.yaml | egrep -v "(observed_
66
MODEL PARSED
77
[WARNING] attribute_limits not supported, ignoring
88
[WARNING] IncludeExclude attribute processor not supported, ignoring
9+
[WARNING] [Prometheus Exporter] with_resource_constant_labels not supported
910
[WARNING] metric producer not supported, ignoring
1011
[WARNING] metric producer not supported, ignoring
1112
[WARNING] [Periodic Exporting Metric Reader] Invalid configuration: export_timeout_millis_ should be less than export_interval_millis_, using default values
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
$ example_yaml --test --yaml shelltests/prometheus_translation_broken.yaml
5+
>
6+
[ERROR] <shelltests/prometheus_translation_broken.yaml>:9[10](164): Illegal TranslationStrategy: broken
7+
FAILED TO PARSE MODEL
8+
>= 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
file_format: "1.0"
5+
6+
meter_provider:
7+
readers:
8+
- pull:
9+
exporter:
10+
prometheus/development:
11+
host: localhost
12+
port: 9464
13+
without_scope_info: false
14+
# Must fail, invalid
15+
translation_strategy: broken
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
$ example_yaml --test --yaml shelltests/prometheus_translation_no.yaml
5+
>
6+
MODEL PARSED
7+
[WARNING] [Prometheus Exporter] NoTranslation not supported
8+
[WARNING] [Prometheus Exporter] with_resource_constant_labels not supported
9+
SDK CREATED
10+
>= 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
file_format: "1.0"
5+
6+
meter_provider:
7+
readers:
8+
- pull:
9+
exporter:
10+
prometheus/development:
11+
host: localhost
12+
port: 9464
13+
without_scope_info: false
14+
translation_strategy: NoTranslation
15+
with_resource_constant_labels:
16+
included:
17+
- "not supported"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
$ example_yaml --test --yaml shelltests/prometheus_translation_no_utf8.yaml
5+
>
6+
MODEL PARSED
7+
[WARNING] [Prometheus Exporter] NoUTF8EscapingWithSuffixes not supported
8+
SDK CREATED
9+
>= 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
file_format: "1.0"
5+
6+
meter_provider:
7+
readers:
8+
- pull:
9+
exporter:
10+
prometheus/development:
11+
host: localhost
12+
port: 9464
13+
without_scope_info: false
14+
translation_strategy: NoUTF8EscapingWithSuffixes
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
$ example_yaml --test --yaml shelltests/prometheus_translation_with_suffixes.yaml
5+
>
6+
MODEL PARSED
7+
SDK CREATED
8+
>= 0

0 commit comments

Comments
 (0)