Repository navigation
feat(tracing): load stable configuration through libdatadog #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ build/ | |
| dist/ | ||
| MODULE.bazel.lock | ||
| out/ | ||
| rust/**/target/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,7 @@ | |
| [submodule "benchmark/tinycc"] | ||
| path = benchmark/tinycc | ||
| url = https://github.com/TinyCC/tinycc.git | ||
| [submodule "vendor/libdatadog"] | ||
| path = vendor/libdatadog | ||
| url = https://github.com/datadog/libdatadog.git | ||
| branch = pawel/no-std-library-config | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This temporary thing should be solved. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ project( | |
| option(BUILD_SHARED_LIBS "Build shared libraries" ON) | ||
| option(BUILD_STATIC_LIBS "Build static libraries" ON) | ||
| option(DD_TRACE_BUILD_C_BINDING "Build C binding" OFF) | ||
| option(DD_TRACE_BUILD_STABLE_CONFIG "Build the libdatadog stable config loader" OFF) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need at least one CI job that uses this option. |
||
|
|
||
| if (WIN32) | ||
| option(DD_TRACE_STATIC_CRT "Build dd-trace-cpp with static CRT with MSVC" OFF) | ||
|
|
@@ -166,6 +167,7 @@ target_sources(dd-trace-cpp-objects | |
| include/datadog/span_defaults.h | ||
| include/datadog/span_matcher.h | ||
| include/datadog/span_sampler_config.h | ||
| include/datadog/stable_config.h | ||
| include/datadog/string_view.h | ||
| include/datadog/trace_id.h | ||
| include/datadog/trace_sampler_config.h | ||
|
|
@@ -214,6 +216,7 @@ target_sources(dd-trace-cpp-objects | |
| src/datadog/span_matcher.cpp | ||
| src/datadog/span_sampler_config.cpp | ||
| src/datadog/span_sampler.cpp | ||
| src/datadog/stable_config.cpp | ||
| src/datadog/string_util.cpp | ||
| src/datadog/tags.cpp | ||
| src/datadog/tag_propagation.cpp | ||
|
|
@@ -367,6 +370,16 @@ if (BUILD_STATIC_LIBS) | |
| ) | ||
| endif () | ||
|
|
||
| if (DD_TRACE_BUILD_STABLE_CONFIG) | ||
| include(cmake/stable_config.cmake) | ||
| if (DD_TRACE_BUILD_TESTING) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should rather be the in |
||
| target_sources(tests PRIVATE test/test_stable_config.cpp) | ||
| target_link_libraries(tests PRIVATE dd-trace-cpp::stable-config) | ||
| target_compile_definitions(tests PRIVATE | ||
| "DD_TRACE_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"") | ||
| endif () | ||
| endif () | ||
|
|
||
| # install target | ||
| write_basic_package_version_file( | ||
| "${PROJECT_NAME}-config-version.cmake" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,28 @@ bazel_dep(name = "abseil-cpp", version = "20260817.0", repo_name = "com_google_a | |
| bazel_dep(name = "bazel_skylib", version = "1.9.2") | ||
| bazel_dep(name = "platforms", version = "1.1.0") | ||
| bazel_dep(name = "rules_cc", version = "0.2.22") | ||
| bazel_dep(name = "rules_rs", version = "0.0.112") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should move all the stable configuration stuff in a separate Bazel module, so that the core C++ Tracer module remains free of Rust dependency. |
||
|
|
||
| rust_toolchains = use_extension("@rules_rs//rs/toolchains:module_extension.bzl", "toolchains") | ||
| rust_toolchains.toolchain( | ||
| edition = "2021", | ||
| version = "1.92.0", | ||
| ) | ||
| use_repo(rust_toolchains, "default_rust_toolchains") | ||
| register_toolchains("@default_rust_toolchains//...") | ||
|
|
||
| stable_config_crates = use_extension("@rules_rs//rs:extensions.bzl", "crate") | ||
| stable_config_crates.from_cargo( | ||
| name = "stable_config_crates", | ||
| cargo_lock = "//rust/stable-config-bazel-deps:Cargo.lock", | ||
| cargo_toml = "//rust/stable-config-bazel-deps:Cargo.toml", | ||
| platform_triples = [ | ||
| "aarch64-apple-darwin", | ||
| "aarch64-unknown-linux-gnu", | ||
| "x86_64-apple-darwin", | ||
| "x86_64-pc-windows-msvc", | ||
| "x86_64-unknown-linux-gnu", | ||
| "x86_64-unknown-linux-musl", | ||
| ], | ||
| ) | ||
| use_repo(stable_config_crates, "stable_config_crates") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| find_program(DD_TRACE_CARGO cargo REQUIRED) | ||
|
|
||
| file(GLOB_RECURSE DD_TRACE_LIBDD_LIBRARY_CONFIG_SOURCES CONFIGURE_DEPENDS | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This goes against the "don't use glob rule" stated line 121 of |
||
| "${CMAKE_CURRENT_SOURCE_DIR}/vendor/libdatadog/libdd-library-config/src/*.rs") | ||
|
|
||
| set(DD_TRACE_RUST_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/stable-config-rust") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This is not about Rust, but about stable configuration. So maybe we could rather name this |
||
| set(DD_TRACE_RUST_FILE_NAME | ||
| "${CMAKE_STATIC_LIBRARY_PREFIX}dd_trace_cpp_stable_config_ffi${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
| set(DD_TRACE_RUST_LIBRARY | ||
| "${DD_TRACE_RUST_TARGET_DIR}/release/${DD_TRACE_RUST_FILE_NAME}") | ||
|
|
||
| add_custom_command( | ||
| OUTPUT "${DD_TRACE_RUST_LIBRARY}" | ||
| COMMAND ${CMAKE_COMMAND} -E env | ||
| "CARGO_TARGET_DIR=${DD_TRACE_RUST_TARGET_DIR}" | ||
| ${DD_TRACE_CARGO} build --release --locked | ||
| --manifest-path "${CMAKE_CURRENT_SOURCE_DIR}/rust/stable-config-ffi/Cargo.toml" | ||
| DEPENDS | ||
| rust/stable-config-ffi/Cargo.toml | ||
| rust/stable-config-ffi/Cargo.lock | ||
| rust/stable-config-ffi/src/lib.rs | ||
| vendor/libdatadog/libdd-library-config/Cargo.toml | ||
| ${DD_TRACE_LIBDD_LIBRARY_CONFIG_SOURCES} | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_target(dd-trace-cpp-stable-config-rust | ||
| DEPENDS "${DD_TRACE_RUST_LIBRARY}") | ||
| add_library(dd-trace-cpp-stable-config-rust-lib STATIC IMPORTED GLOBAL) | ||
| set_target_properties(dd-trace-cpp-stable-config-rust-lib PROPERTIES | ||
| IMPORTED_LOCATION "${DD_TRACE_RUST_LIBRARY}") | ||
| add_dependencies(dd-trace-cpp-stable-config-rust-lib | ||
| dd-trace-cpp-stable-config-rust) | ||
|
|
||
| add_library(dd-trace-cpp-stable-config STATIC | ||
| src/datadog/stable_config_loader.cpp) | ||
|
pawelchcki marked this conversation as resolved.
Resolved
|
||
| add_library(dd-trace-cpp::stable-config ALIAS dd-trace-cpp-stable-config) | ||
| set_target_properties(dd-trace-cpp-stable-config PROPERTIES EXPORT_NAME stable-config) | ||
| set_target_properties(dd-trace-cpp-stable-config PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: merge the |
||
| target_compile_features(dd-trace-cpp-stable-config PUBLIC cxx_std_17) | ||
| target_include_directories(dd-trace-cpp-stable-config PUBLIC | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It seems this |
||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
| "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") | ||
| target_sources(dd-trace-cpp-stable-config PUBLIC | ||
| FILE_SET public_headers TYPE HEADERS BASE_DIRS include | ||
| FILES include/datadog/stable_config_loader.h) | ||
| target_link_libraries(dd-trace-cpp-stable-config | ||
| PUBLIC dd-trace-cpp-stable-config-rust-lib) | ||
| if (BUILD_SHARED_LIBS) | ||
| target_link_libraries(dd-trace-cpp-stable-config PUBLIC dd-trace-cpp::shared) | ||
| elseif (BUILD_STATIC_LIBS) | ||
| target_link_libraries(dd-trace-cpp-stable-config PUBLIC dd-trace-cpp::static) | ||
| else () | ||
| message(FATAL_ERROR "Stable config requires a dd-trace-cpp library") | ||
| endif () | ||
|
|
||
| install(TARGETS dd-trace-cpp-stable-config | ||
| EXPORT dd-trace-cpp-targets | ||
| FILE_SET public_headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| install(FILES "${DD_TRACE_RUST_LIBRARY}" | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,9 @@ struct ConfigMetadata { | |
| ENVIRONMENT_VARIABLE, // Originating from environment variables | ||
| CODE, // Defined in code | ||
| REMOTE_CONFIG, // Retrieved from remote configuration | ||
| DEFAULT // Default value | ||
| DEFAULT, // Default value | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It feels a bit weird to let the default value in the middle. I would rather move it at the top, or keep it at the bottom. (Note that we don't care about binary compatibility which is broken anyway, notably by the addition of |
||
| LOCAL_STABLE_CONFIG, | ||
| FLEET_STABLE_CONFIG | ||
| }; | ||
|
|
||
| // Name of the configuration parameter | ||
|
|
@@ -56,11 +58,17 @@ struct ConfigMetadata { | |
| Origin origin; | ||
| // Optional error associated with the configuration parameter | ||
| Optional<Error> error; | ||
| Optional<std::string> config_id; | ||
|
|
||
| ConfigMetadata() = default; | ||
| ConfigMetadata(ConfigName n, std::string v, Origin orig, | ||
| Optional<Error> err = nullopt) | ||
| : name(n), value(std::move(v)), origin(orig), error(std::move(err)) {} | ||
| Optional<Error> err = nullopt, | ||
| Optional<std::string> id = nullopt) | ||
| : name(n), | ||
| value(std::move(v)), | ||
| origin(orig), | ||
| error(std::move(err)), | ||
| config_id(std::move(id)) {} | ||
| }; | ||
|
|
||
| // Returns the final configuration value using the following | ||
|
|
@@ -96,7 +104,11 @@ Value resolve_and_record_config( | |
| const Optional<Value>& from_env, const Optional<Value>& from_user, | ||
| std::unordered_map<ConfigName, std::vector<ConfigMetadata>>* metadata, | ||
| ConfigName config_name, DefaultValue fallback = nullptr, | ||
| Stringifier to_string_fn = nullptr) { | ||
| Stringifier to_string_fn = nullptr, | ||
| ConfigMetadata::Origin from_env_origin = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for consistency, document new parameters |
||
| ConfigMetadata::Origin::ENVIRONMENT_VARIABLE, | ||
| Optional<std::string> from_env_config_id = nullopt, | ||
| bool programmatic_wins = false) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we have two kind of conflicting precedence models:
I think this adds complexity and is error prone. Could we rather keep environment > code with stable configuration? Or should we change current behavior (without stable configuration) because we do want code > environment? |
||
| auto stringify = [&](const Value& v) -> std::string { | ||
| if constexpr (!std::is_same_v<Stringifier, std::nullptr_t>) { | ||
| return to_string_fn(v); // use provided function | ||
|
|
@@ -112,9 +124,11 @@ Value resolve_and_record_config( | |
| std::vector<ConfigMetadata> metadata_entries; | ||
| Optional<Value> chosen_value; | ||
|
|
||
| auto add_entry = [&](ConfigMetadata::Origin origin, const Value& val) { | ||
| auto add_entry = [&](ConfigMetadata::Origin origin, const Value& val, | ||
| Optional<std::string> config_id = nullopt) { | ||
| std::string val_str = stringify(val); | ||
| metadata_entries.emplace_back(ConfigMetadata{config_name, val_str, origin}); | ||
| metadata_entries.emplace_back( | ||
| ConfigMetadata{config_name, val_str, origin, nullopt, config_id}); | ||
| chosen_value = val; | ||
| }; | ||
|
|
||
|
|
@@ -123,12 +137,12 @@ Value resolve_and_record_config( | |
| add_entry(ConfigMetadata::Origin::DEFAULT, fallback); | ||
| } | ||
|
|
||
| if (from_user) { | ||
| add_entry(ConfigMetadata::Origin::CODE, *from_user); | ||
| } | ||
|
|
||
| if (from_env) { | ||
| add_entry(ConfigMetadata::Origin::ENVIRONMENT_VARIABLE, *from_env); | ||
| if (programmatic_wins) { | ||
| if (from_env) add_entry(from_env_origin, *from_env, from_env_config_id); | ||
| if (from_user) add_entry(ConfigMetadata::Origin::CODE, *from_user); | ||
| } else { | ||
| if (from_user) add_entry(ConfigMetadata::Origin::CODE, *from_user); | ||
| if (from_env) add_entry(from_env_origin, *from_env, from_env_config_id); | ||
| } | ||
|
|
||
| if (!metadata_entries.empty()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ namespace datadog::tracing { | |
|
|
||
| class EventScheduler; | ||
| class Logger; | ||
| class StableConfig; | ||
|
|
||
| struct DatadogAgentConfig { | ||
| // The `HTTPClient` used to submit traces to the Datadog Agent. If this | ||
|
|
@@ -65,6 +66,9 @@ struct DatadogAgentConfig { | |
| class FinalizedDatadogAgentConfig { | ||
| friend Expected<FinalizedDatadogAgentConfig> finalize_config( | ||
| const DatadogAgentConfig&, const std::shared_ptr<Logger>&, const Clock&); | ||
| friend Expected<FinalizedDatadogAgentConfig> finalize_config( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Here also, rather merge overloads with a default |
||
| const DatadogAgentConfig&, const std::shared_ptr<Logger>&, const Clock&, | ||
| const StableConfig*); | ||
|
|
||
| FinalizedDatadogAgentConfig() = default; | ||
|
|
||
|
|
@@ -94,5 +98,8 @@ class FinalizedDatadogAgentConfig { | |
| Expected<FinalizedDatadogAgentConfig> finalize_config( | ||
| const DatadogAgentConfig& config, const std::shared_ptr<Logger>& logger, | ||
| const Clock& clock); | ||
| Expected<FinalizedDatadogAgentConfig> finalize_config( | ||
| const DatadogAgentConfig& config, const std::shared_ptr<Logger>& logger, | ||
| const Clock& clock, const StableConfig* stable_config); | ||
|
|
||
| } // namespace datadog::tracing | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should try to factorize lines 153-155 and 160-162. Suggestion:
Another option would be to merge the
BuildandTestssteps.