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
10 changes: 6 additions & 4 deletions src/datadog/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Expected<ConfigManager::Update> parse_dynamic_config(const nlohmann::json& j) {
ConfigManager::Update config_update;

if (auto sampling_rate_it = j.find("tracing_sampling_rate");
sampling_rate_it != j.cend()) {
sampling_rate_it != j.cend() && !sampling_rate_it->is_null()) {
if (!sampling_rate_it->is_number_float()) {
return make_err_property_msg("tracing_sampling_rate",
sampling_rate_it->type_name());
Expand All @@ -236,7 +236,8 @@ Expected<ConfigManager::Update> parse_dynamic_config(const nlohmann::json& j) {
config_update.trace_sampling_rate = *maybe_rate;
}

if (auto tags_it = j.find("tracing_tags"); tags_it != j.cend()) {
if (auto tags_it = j.find("tracing_tags");
tags_it != j.cend() && !tags_it->is_null()) {
if (!tags_it->is_array()) {
return make_err_property_msg("tracing_tags", tags_it->type_name());
}
Expand All @@ -250,7 +251,7 @@ Expected<ConfigManager::Update> parse_dynamic_config(const nlohmann::json& j) {
}

if (auto tracing_enabled_it = j.find("tracing_enabled");
tracing_enabled_it != j.cend()) {
tracing_enabled_it != j.cend() && !tracing_enabled_it->is_null()) {
if (!tracing_enabled_it->is_boolean()) {
return make_err_property_msg("tracing_enabled",
tracing_enabled_it->type_name());
Expand All @@ -260,7 +261,8 @@ Expected<ConfigManager::Update> parse_dynamic_config(const nlohmann::json& j) {
}

if (auto tracing_sampling_rules_it = j.find("tracing_sampling_rules");
tracing_sampling_rules_it != j.cend()) {
tracing_sampling_rules_it != j.cend() &&
!tracing_sampling_rules_it->is_null()) {
if (!tracing_sampling_rules_it->is_array()) {
return make_err_property_msg("tracing_sampling_rules",
tracing_sampling_rules_it->type_name());
Expand Down
137 changes: 123 additions & 14 deletions test/test_config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,31 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
}

SECTION(
"an RC payload without the `tracing_sampling_rate` does not raise an "
"error nor update the sampling rate") {
config_update.content = R"({
"an RC payload without the `tracing_sampling_rate` or with a null "
"value does not raise an error nor update the sampling rate") {
struct TestCase {
size_t line;
std::string_view name;
std::string_view input;
};

const auto test_case = GENERATE(values<TestCase>({
{
__LINE__,
"tracing_sampling_rate is missing",
"",
},
{
__LINE__,
"tracing_sampling_rate is null",
R"("tracing_sampling_rate": null,)",
},
}));

char payload[1024];
std::snprintf(payload, 1024, R"({
"lib_config": {
%s
"library_language": "all",
"library_version": "latest",
"service_name": "testsvc",
Expand All @@ -122,7 +143,13 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
"service": "testsvc",
"env": "test"
}
})";
})",
test_case.input.data());

config_update.content = payload;

CAPTURE(test_case.line);
CAPTURE(test_case.name);

const auto old_trace_sampler_config =
config_manager.trace_sampler()->config_json();
Expand Down Expand Up @@ -232,10 +259,35 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
}

SECTION(
"payload without `tracing_tags` does not raise an error nor update the "
"payload without `tracing_tags` or with a null value does not raise an "
"error nor update the "
"list of tags") {
config_update.content = R"({
struct TestCase {
size_t line;
std::string_view name;
std::string_view input;
};

const auto test_case = GENERATE(values<TestCase>({
{
__LINE__,
"tracing_tags is missing",
"",
},
{
__LINE__,
"tracing_tags is null",
R"("tracing_tags": null,)",
},
}));

CAPTURE(test_case.line);
CAPTURE(test_case.name);

char payload[1024];
std::snprintf(payload, 1024, R"({
"lib_config": {
%s
"library_language": "all",
"library_version": "latest",
"service_name": "testsvc",
Expand All @@ -245,7 +297,10 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
"service": "testsvc",
"env": "test"
}
})";
})",
test_case.input.data());

config_update.content = payload;

const auto old_tags = config_manager.span_defaults()->tags;

Expand Down Expand Up @@ -357,10 +412,34 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
}

SECTION(
"An RC payload without `tracing_enabled` does not raise an error nor "
"update the value") {
config_update.content = R"({
"An RC payload without `tracing_enabled` or with a null value does not "
"raise an error nor update the value") {
struct TestCase {
size_t line;
std::string_view name;
std::string_view input;
};

const auto test_case = GENERATE(values<TestCase>({
{
__LINE__,
"tracing_enabled is absent from the RC payload",
"",
},
{
__LINE__,
"tracing_enabled is null",
R"("tracing_enabled": null,)",
},
}));

CAPTURE(test_case.line);
CAPTURE(test_case.name);

char payload[1024];
std::snprintf(payload, 1024, R"({
"lib_config": {
%s
"library_language": "all",
"library_version": "latest",
"service_name": "testsvc",
Expand All @@ -370,7 +449,10 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
"service": "testsvc",
"env": "test"
}
})";
})",
test_case.input.data());

config_update.content = payload;

const auto old_tracing_status = config_manager.report_traces();

Expand Down Expand Up @@ -526,9 +608,33 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
CHECK(old_sampler_cfg == new_sampler_cfg);
}

SECTION("empty") {
config_update.content = R"({
SECTION("null value or the absence of the field is ignored") {
struct TestCase {
size_t line;
std::string_view name;
std::string_view input;
};

const auto test_case = GENERATE(values<TestCase>({
{
__LINE__,
"tracing_sampling_rules is absent from the RC payload",
"",
},
{
__LINE__,
"tracing_sampling_rules is null",
R"("tracing_sampling_rules": null,)",
},
}));

CAPTURE(test_case.line);
CAPTURE(test_case.name);

char payload[1024];
std::snprintf(payload, 1024, R"({
"lib_config": {
%s
"library_language": "all",
"library_version": "latest",
"service_name": "testsvc",
Expand All @@ -538,7 +644,10 @@ CONFIG_MANAGER_TEST("remote configuration handling") {
"service": "testsvc",
"env": "test"
}
})";
})",
test_case.input.data());

config_update.content = payload;

const auto old_sampler_cfg =
config_manager.trace_sampler()->config_json();
Expand Down