Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Increment the:
* [SDK] Downscale base2 exponential histogram buckets in place
[#4324](https://github.com/open-telemetry/opentelemetry-cpp/pull/4324)

* [CONFIGURATION] file configuration - yaml schema 1.1.0
[#4340](https://github.com/open-telemetry/opentelemetry-cpp/pull/4340)

Breaking changes:

* [BUILD] Install an explicit list of ext headers instead of the whole
Expand Down
10 changes: 5 additions & 5 deletions exporters/prometheus/src/prometheus_pull_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> PrometheusPullBuilder
url.append(std::to_string(model->port));

options.url = url;
options.populate_target_info = !model->without_target_info;
options.without_otel_scope = model->without_scope_info;
options.populate_target_info = model->target_info_enabled;
options.without_otel_scope = !model->scope_info_enabled;

switch (model->translation_strategy)
{
Expand All @@ -65,10 +65,10 @@ std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> PrometheusPullBuilder
break;
}

if (model->with_resource_constant_labels != nullptr)
if (model->resource_constant_labels != nullptr)
{
// FIXME: with_resource_constant_labels
OTEL_INTERNAL_LOG_WARN("[Prometheus Exporter] with_resource_constant_labels not supported");
// FIXME: resource_constant_labels
OTEL_INTERNAL_LOG_WARN("[Prometheus Exporter] resource_constant_labels not supported");
}

return PrometheusExporterFactory::Create(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ $ example_yaml --test --yaml shelltests/prometheus_translation_no.yaml
>
MODEL PARSED
[WARNING] [Prometheus Exporter] NoTranslation not supported
[WARNING] [Prometheus Exporter] with_resource_constant_labels not supported
[WARNING] [Prometheus Exporter] resource_constant_labels not supported
SDK CREATED
>= 0
2 changes: 1 addition & 1 deletion install/test/src/test_exporters_prometheus_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TEST(ExportersPrometheusBuilderInstall, PrometheusPullBuilder)
opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration model;
model.host = "localhost";
model.port = 1234;
model.without_scope_info = false;
model.scope_info_enabled = true;

auto exporter = builder->Build(&model);
ASSERT_TRUE(exporter != nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class PrometheusPullMetricExporterConfiguration : public PullMetricExporterConfi
public:
static constexpr const char *kDefaultHost = "localhost";
static constexpr std::size_t kDefaultPort = 9464;
static constexpr bool kDefaultWithoutScopeInfo = false; // schema: scope_info_enabled=true
static constexpr bool kDefaultWithoutTargetInfo = false; // schema: target_info_enabled=true
static constexpr bool kDefaultScopeInfoEnabled = true;
static constexpr bool kDefaultTargetInfoEnabled = true;
static constexpr TranslationStrategy kDefaultTranslationStrategy =
TranslationStrategy::UnderscoreEscapingWithSuffixes;

Expand All @@ -38,9 +38,9 @@ class PrometheusPullMetricExporterConfiguration : public PullMetricExporterConfi

std::string host{kDefaultHost};
std::size_t port{kDefaultPort};
bool without_scope_info{kDefaultWithoutScopeInfo};
bool without_target_info{kDefaultWithoutTargetInfo};
std::unique_ptr<IncludeExcludeConfiguration> with_resource_constant_labels;
bool scope_info_enabled{kDefaultScopeInfoEnabled};
bool target_info_enabled{kDefaultTargetInfoEnabled};
std::unique_ptr<IncludeExcludeConfiguration> resource_constant_labels;
TranslationStrategy translation_strategy{kDefaultTranslationStrategy};
};

Expand Down
64 changes: 52 additions & 12 deletions sdk/src/configuration/configuration_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,18 @@ ConfigurationParser::ParseBatchLogRecordProcessorConfiguration(
model->schedule_delay = node->GetInteger("schedule_delay", Config::kDefaultScheduleDelayMs);
model->export_timeout = node->GetInteger("export_timeout", Config::kDefaultExportTimeoutMs);
model->max_queue_size = node->GetInteger("max_queue_size", Config::kDefaultMaxQueueSize);
model->max_export_batch_size =
node->GetInteger("max_export_batch_size", Config::kDefaultMaxExportBatchSize);

// max_export_batch_size/development added in schema 1.1.0
if ((version_major_ == 1) && (version_minor_ >= 1))
{
model->max_export_batch_size =
node->GetInteger("max_export_batch_size/development", Config::kDefaultMaxExportBatchSize);
}
else
{
// Not configurable in yaml 1.0.0
model->max_export_batch_size = Config::kDefaultMaxExportBatchSize;
}

child = node->GetRequiredChildNode("exporter");
model->exporter = ParseLogRecordExporterConfiguration(child);
Expand Down Expand Up @@ -923,15 +933,35 @@ ConfigurationParser::ParsePrometheusPullMetricExporterConfiguration(

model->host = node->GetString("host", Config::kDefaultHost);
model->port = node->GetInteger("port", Config::kDefaultPort);
model->without_scope_info =
node->GetBoolean("without_scope_info", Config::kDefaultWithoutScopeInfo);
model->without_target_info =
node->GetBoolean("without_target_info", Config::kDefaultWithoutTargetInfo);

child = node->GetChildNode("with_resource_constant_labels");
if (child)
if ((version_major_ == 1) && (version_minor_ >= 1))
{
model->with_resource_constant_labels = ParseIncludeExcludeConfiguration(child);
// Properties renamed in schema 1.1.0
model->scope_info_enabled =
node->GetBoolean("scope_info_enabled", Config::kDefaultScopeInfoEnabled);
model->target_info_enabled =
node->GetBoolean("target_info_enabled/development", Config::kDefaultTargetInfoEnabled);

child = node->GetChildNode("resource_constant_labels");
if (child)
{
model->resource_constant_labels = ParseIncludeExcludeConfiguration(child);
}
}
else
{
// Old properties name in schema 1.0.0
bool without_scope_info = node->GetBoolean("without_scope_info", false);
bool without_target_info = node->GetBoolean("without_target_info", false);

model->scope_info_enabled = !without_scope_info;
model->target_info_enabled = !without_target_info;

child = node->GetChildNode("with_resource_constant_labels");
if (child)
{
model->resource_constant_labels = ParseIncludeExcludeConfiguration(child);
}
}

std::string translation_strategy =
Expand Down Expand Up @@ -2241,8 +2271,18 @@ ConfigurationParser::ParseBatchSpanProcessorConfiguration(
model->schedule_delay = node->GetInteger("schedule_delay", Config::kDefaultScheduleDelayMs);
model->export_timeout = node->GetInteger("export_timeout", Config::kDefaultExportTimeoutMs);
model->max_queue_size = node->GetInteger("max_queue_size", Config::kDefaultMaxQueueSize);
model->max_export_batch_size =
node->GetInteger("max_export_batch_size", Config::kDefaultMaxExportBatchSize);

// max_export_batch_size/development added in schema 1.1.0
if ((version_major_ == 1) && (version_minor_ >= 1))
{
model->max_export_batch_size =
node->GetInteger("max_export_batch_size/development", Config::kDefaultMaxExportBatchSize);
}
else
{
// Not configurable in yaml 1.0.0
model->max_export_batch_size = Config::kDefaultMaxExportBatchSize;
}

child = node->GetRequiredChildNode("exporter");
model->exporter = ParseSpanExporterConfiguration(child);
Expand Down Expand Up @@ -2802,7 +2842,7 @@ std::unique_ptr<Configuration> ConfigurationParser::Parse(std::unique_ptr<Docume
throw InvalidSchemaException(node->Location(), message);
}

if (minor != 0)
if (minor > 1)
{
std::string message("Unsupported file_format, major = ");
message.append(std::to_string(major));
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/configuration/yaml_logs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ file_format: "1.0-logs"
TEST(YamlLogs, default_batch_processor)
{
std::string yaml = R"(
file_format: "1.0-logs"
file_format: "1.1-logs"
logger_provider:
processors:
- batch:
Expand Down Expand Up @@ -132,14 +132,14 @@ file_format: "1.0-logs"
TEST(YamlLogs, batch_processor)
{
std::string yaml = R"(
file_format: "1.0-logs"
file_format: "1.1-logs"
logger_provider:
processors:
- batch:
schedule_delay: 5555
export_timeout: 33333
max_queue_size: 1234
max_export_batch_size: 256
max_export_batch_size/development: 256
exporter:
console:
)";
Expand Down
114 changes: 99 additions & 15 deletions sdk/test/configuration/yaml_metrics_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ file_format: "1.0-metrics"
#endif
}

TEST(YamlMetrics, default_prometheus)
TEST(YamlMetrics, default_prometheus_1_0)
{
std::string yaml = R"(
file_format: "1.0-metrics"
Expand All @@ -620,14 +620,47 @@ file_format: "1.0-metrics"
opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *>(exporter);
ASSERT_EQ(prometheus->host, "localhost");
ASSERT_EQ(prometheus->port, 9464);
ASSERT_EQ(prometheus->without_scope_info, false);
ASSERT_EQ(prometheus->without_target_info, false);
ASSERT_EQ(prometheus->scope_info_enabled, true);
ASSERT_EQ(prometheus->target_info_enabled, true);
ASSERT_EQ(prometheus->translation_strategy,
opentelemetry::sdk::configuration::TranslationStrategy::UnderscoreEscapingWithSuffixes);
ASSERT_EQ(prometheus->with_resource_constant_labels, nullptr);
ASSERT_EQ(prometheus->resource_constant_labels, nullptr);
}

TEST(YamlMetrics, prometheus)
TEST(YamlMetrics, default_prometheus_1_1)
{
std::string yaml = R"(
file_format: "1.1-metrics"
meter_provider:
readers:
- pull:
exporter:
prometheus/development:
)";

auto config = DoParse(yaml);
ASSERT_NE(config, nullptr);
ASSERT_NE(config->meter_provider, nullptr);
ASSERT_EQ(config->meter_provider->readers.size(), 1);
auto *reader = config->meter_provider->readers[0].get();
ASSERT_NE(reader, nullptr);
auto *pull =
reinterpret_cast<opentelemetry::sdk::configuration::PullMetricReaderConfiguration *>(reader);
ASSERT_NE(pull->exporter, nullptr);
auto *exporter = pull->exporter.get();
ASSERT_NE(exporter, nullptr);
auto *prometheus = reinterpret_cast<
opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *>(exporter);
ASSERT_EQ(prometheus->host, "localhost");
ASSERT_EQ(prometheus->port, 9464);
ASSERT_EQ(prometheus->scope_info_enabled, true);
ASSERT_EQ(prometheus->target_info_enabled, true);
ASSERT_EQ(prometheus->translation_strategy,
opentelemetry::sdk::configuration::TranslationStrategy::UnderscoreEscapingWithSuffixes);
ASSERT_EQ(prometheus->resource_constant_labels, nullptr);
}

TEST(YamlMetrics, prometheus_1_0)
{
std::string yaml = R"(
file_format: "1.0-metrics"
Expand Down Expand Up @@ -664,18 +697,69 @@ file_format: "1.0-metrics"
opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *>(exporter);
ASSERT_EQ(prometheus->host, "prometheus");
ASSERT_EQ(prometheus->port, 1234);
ASSERT_EQ(prometheus->without_scope_info, true);
ASSERT_EQ(prometheus->without_target_info, true);
ASSERT_EQ(prometheus->scope_info_enabled, false);
ASSERT_EQ(prometheus->target_info_enabled, false);
ASSERT_EQ(prometheus->translation_strategy,
opentelemetry::sdk::configuration::TranslationStrategy::NoUTF8EscapingWithSuffixes);
ASSERT_NE(prometheus->resource_constant_labels, nullptr);
ASSERT_NE(prometheus->resource_constant_labels->included, nullptr);
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array.size(), 2);
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array[0], "foo.in");
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array[1], "bar.in");
ASSERT_NE(prometheus->resource_constant_labels->excluded, nullptr);
ASSERT_EQ(prometheus->resource_constant_labels->excluded->string_array.size(), 1);
ASSERT_EQ(prometheus->resource_constant_labels->excluded->string_array[0], "baz.ex");
}

TEST(YamlMetrics, prometheus_1_1)
{
std::string yaml = R"(
file_format: "1.1-metrics"
meter_provider:
readers:
- pull:
exporter:
prometheus/development:
host: "prometheus"
port: 1234
scope_info_enabled: false
target_info_enabled/development: false
translation_strategy: NoUTF8EscapingWithSuffixes
resource_constant_labels:
included:
- "foo.in"
- "bar.in"
excluded:
- "baz.ex"
)";

auto config = DoParse(yaml);
ASSERT_NE(config, nullptr);
ASSERT_NE(config->meter_provider, nullptr);
ASSERT_EQ(config->meter_provider->readers.size(), 1);
auto *reader = config->meter_provider->readers[0].get();
ASSERT_NE(reader, nullptr);
auto *pull =
reinterpret_cast<opentelemetry::sdk::configuration::PullMetricReaderConfiguration *>(reader);
ASSERT_NE(pull->exporter, nullptr);
auto *exporter = pull->exporter.get();
ASSERT_NE(exporter, nullptr);
auto *prometheus = reinterpret_cast<
opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *>(exporter);
ASSERT_EQ(prometheus->host, "prometheus");
ASSERT_EQ(prometheus->port, 1234);
ASSERT_EQ(prometheus->scope_info_enabled, false);
ASSERT_EQ(prometheus->target_info_enabled, false);
ASSERT_EQ(prometheus->translation_strategy,
opentelemetry::sdk::configuration::TranslationStrategy::NoUTF8EscapingWithSuffixes);
ASSERT_NE(prometheus->with_resource_constant_labels, nullptr);
ASSERT_NE(prometheus->with_resource_constant_labels->included, nullptr);
ASSERT_EQ(prometheus->with_resource_constant_labels->included->string_array.size(), 2);
ASSERT_EQ(prometheus->with_resource_constant_labels->included->string_array[0], "foo.in");
ASSERT_EQ(prometheus->with_resource_constant_labels->included->string_array[1], "bar.in");
ASSERT_NE(prometheus->with_resource_constant_labels->excluded, nullptr);
ASSERT_EQ(prometheus->with_resource_constant_labels->excluded->string_array.size(), 1);
ASSERT_EQ(prometheus->with_resource_constant_labels->excluded->string_array[0], "baz.ex");
ASSERT_NE(prometheus->resource_constant_labels, nullptr);
ASSERT_NE(prometheus->resource_constant_labels->included, nullptr);
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array.size(), 2);
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array[0], "foo.in");
ASSERT_EQ(prometheus->resource_constant_labels->included->string_array[1], "bar.in");
ASSERT_NE(prometheus->resource_constant_labels->excluded, nullptr);
ASSERT_EQ(prometheus->resource_constant_labels->excluded->string_array.size(), 1);
ASSERT_EQ(prometheus->resource_constant_labels->excluded->string_array[0], "baz.ex");
}

TEST(YamlMetrics, empty_views)
Expand Down
16 changes: 14 additions & 2 deletions sdk/test/configuration/yaml_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ file_format: "2.0"
TEST(Yaml, unsupported_new_minor_format)
{
std::string yaml = R"(
file_format: "1.1"
file_format: "1.2"
)";

auto config = DoParse(yaml);
ASSERT_EQ(config, nullptr);
}

TEST(Yaml, just_format)
TEST(Yaml, just_format_1_0)
{
std::string yaml = R"(
file_format: "1.0-rc.1"
Expand All @@ -104,6 +104,18 @@ file_format: "1.0-rc.1"
ASSERT_EQ(config->file_format, "1.0-rc.1");
}

TEST(Yaml, just_format_1_1)
{
// 1.1.0 released 2026-06-05
std::string yaml = R"(
file_format: "1.1"
)";

auto config = DoParse(yaml);
ASSERT_NE(config, nullptr);
ASSERT_EQ(config->file_format, "1.1");
}

TEST(Yaml, disabled)
{
std::string yaml = R"(
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/configuration/yaml_trace_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ file_format: "1.0-trace"
TEST(YamlTrace, default_batch_processor)
{
std::string yaml = R"(
file_format: "1.0-trace"
file_format: "1.1-trace"
tracer_provider:
processors:
- batch:
Expand Down Expand Up @@ -235,14 +235,14 @@ file_format: "1.0-trace"
TEST(YamlTrace, batch_processor)
{
std::string yaml = R"(
file_format: "1.0-trace"
file_format: "1.1-trace"
tracer_provider:
processors:
- batch:
schedule_delay: 5555
export_timeout: 33333
max_queue_size: 1234
max_export_batch_size: 256
max_export_batch_size/development: 256
exporter:
console:
)";
Expand Down
Loading