fix(config): graceful failure fallback to default#98
Open
duncanista wants to merge 5 commits intomainfrom
Open
fix(config): graceful failure fallback to default#98duncanista wants to merge 5 commits intomainfrom
duncanista wants to merge 5 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the resilience of datadog-agent-config config loading by making deserialization failures non-fatal at the field level, so that a single mistyped YAML/env value no longer causes the entire source to fall back to Config::default().
Changes:
- Introduces a generic
deserialize_with_default<T: Deserialize + Default>helper and applies it broadly via#[serde(deserialize_with)]on YAML/env config fields. - Hardens several existing deserializers to catch and ignore serde/type errors instead of propagating them.
- Adds “canary” regression tests ensuring YAML/env loads succeed even when many fields have wrong types.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/datadog-agent-config/yaml.rs |
Applies per-field graceful deserialization across YAML structs and adds a comprehensive wrong-type YAML regression test. |
crates/datadog-agent-config/env.rs |
Applies graceful deserialization for select env fields and adds a comprehensive wrong-type env regression test. |
crates/datadog-agent-config/mod.rs |
Adds deserialize_with_default and hardens multiple deserializers to ignore type/serde errors. |
crates/datadog-agent-config/service_mapping.rs |
Makes service mapping deserialization ignore type errors (returns empty map). |
crates/datadog-agent-config/apm_replace_rule.rs |
Makes APM replace rules deserialization ignore type errors (returns None). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Contributor
apiarian-datadog
left a comment
There was a problem hiding this comment.
some notes and questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds per-field graceful deserialization to the datadog-agent-config crate. Previously, if a single config field had the wrong type (e.g., DD_FLUSH_TIMEOUT=abc or flush_timeout: [1,2,3] in YAML), the entire config
source would fail and fall back to Config::default() — losing every valid field alongside the bad one. Now, only the invalid field falls back to its default while all other correctly-typed fields are preserved.
The fix introduces one generic deserializer function, deserialize_with_default<T: Deserialize + Default>, which catches serde errors at the field level and returns T::default(). This is applied via
#[serde(deserialize_with)] to all previously-unprotected fields across EnvConfig, YamlConfig, and their nested structs. Several existing deserializers (deserialize_optional_duration_from_seconds,
deserialize_optional_duration_from_microseconds, deserialize_trace_propagation_style, deserialize_key_value_pair_array_to_hashmap, deserialize_service_mapping, deserialize_apm_replace_rules) were also hardened to
catch errors instead of propagating them.
Motivation
In production, a single misconfigured environment variable or YAML field should not wipe out the entire agent configuration. The agent should log a warning for the bad field and continue with defaults for that
field only, while respecting all other valid configuration.
Additional Notes
deserializer functions.
Describe how to test/QA your changes
Two comprehensive regression tests were added:
Config::default().
equals its default.
Both tests serve as canaries: when adding a new field, adding it to the test YAML/env with a wrong type will immediately fail if the field lacks a graceful deserializer.
All 78 tests pass (cargo test -p datadog-agent-config --lib).