Skip to content

refactor: replace deprecated serde_yaml with serde_saphyr#2492

Merged
DavSanchez merged 7 commits into
mainfrom
refactor/use-serde-saphyr
May 14, 2026
Merged

refactor: replace deprecated serde_yaml with serde_saphyr#2492
DavSanchez merged 7 commits into
mainfrom
refactor/use-serde-saphyr

Conversation

@DavSanchez

@DavSanchez DavSanchez commented May 6, 2026

Copy link
Copy Markdown
Contributor

In preparation for the incoming kube-rs v4, we can start working to remove our dependency on serde_yaml!

Summary

This PR replaces the deprecated serde_yaml dependency with serde_saphyr across the entire workspace, while migrating abstract YAML DOM manipulations from serde_yaml::Value/Mapping/Number to serde_json::Value/Map/Number.

Motivation

The serde_yaml crate is officially deprecated and no longer maintained. serde_saphyr is the recommended modern replacement that provides YAML 1.2 serialization/deserialization via serde.

However, serde_saphyr intentionally does not provide Value/Mapping/Number types. All abstract YAML tree manipulations must be expressed through serde_json::Value/Map/Number instead.

Changes

Dependencies

  • Removed serde_yaml from workspace Cargo.toml, agent-control/Cargo.toml, and test/e2e-runner/Cargo.toml
  • Added serde-saphyr as the replacement for serde operations (from_str, to_string, from_reader, etc.)
  • Relied on existing serde_json for abstract DOM types (Value, Map<String, Value>, Number)

Source Migration (~66 files)

Before (serde_yaml) After (serde_saphyr / serde_json)
serde_yaml::Value serde_json::Value
serde_yaml::Mapping serde_json::Map<String, serde_json::Value>
serde_yaml::Number serde_json::Number
serde_yaml::from_str serde_saphyr::from_str
serde_yaml::to_string serde_saphyr::to_string
serde_yaml::from_reader serde_saphyr::from_reader
serde_yaml::to_value serde_json::to_value
serde_yaml::from_value serde_json::from_value

Behavioral Differences Handled

serde_saphyr has stricter defaults than serde_yaml. The following adjustments were made to preserve existing behavior:

  1. Duplicate YAML keys: serde_saphyr errors by default on duplicate mapping keys, while serde_yaml silently accepted them. Production code paths (FileStore::get, YAMLConfig::try_from) now use serde_saphyr::from_str_with_options with DuplicateKeyPolicy::LastWins to match the previous behavior.

  2. Null → String deserialization: serde_yaml deserialized name: (null value) into an empty String. serde_saphyr rejects this. The AgentTypeID deserialization was updated to use Option<String> fields with .unwrap_or_default() to handle this gracefully.

  3. Error message formats: Several unit tests that asserted on exact serde_yaml error strings were updated to assert on the equivalent serde_saphyr error format.

  4. Block scalar serialization: serde_saphyr::to_string emits multiline strings as quoted strings with \n escapes rather than YAML literal block scalars (|). One integration test's expected output was updated accordingly.

Error Enum Refactoring

Error variants were renamed to generic names not coupled to the old dependency:

  • serde_yaml::Error variants → serde_json::Error and serde_saphyr::ser::Error variants with names like Serialization / Deserialization
  • Affected files: agent_type/error.rs, k8s/error.rs, effective_agents_assembler.rs, config_migrate/migration/converter.rs, and others

Test Fixes

  • 7 lib tests updated to match serde_saphyr error message formats
  • 1 integration test (test_store_remote_no_mocks) updated expected YAML serialization format
  • Turbofish syntax fixed in custom_agent_type.rs (Map<String, Value>::newMap::<String, Value>::new)

Verification

  • cargo check --workspace passes
  • cargo test -p newrelic_agent_control --lib863 tests pass
  • cargo test -p newrelic_agent_control --test integration_tests54 tests pass (76 ignored)
  • cargo test --workspace --lib — all workspace lib tests pass
  • cargo clippy -p newrelic_agent_control — clean (1 pre-existing warning fixed)
  • No remaining serde_yaml references in source code or tests

Backward Compatibility

This change is intended to be behaviorally transparent to end users. All serialization/deserialization round-trips produce the same semantic results. The only user-visible difference is that YAML files with duplicate keys (which were previously silently accepted) are now also accepted via the LastWins policy.

Related

@DavSanchez DavSanchez force-pushed the refactor/use-serde-saphyr branch 3 times, most recently from 49db8ec to c1b6c13 Compare May 7, 2026 12:39
@DavSanchez DavSanchez marked this pull request as ready for review May 7, 2026 12:42
@DavSanchez DavSanchez requested a review from a team as a code owner May 7, 2026 12:42
@DavSanchez DavSanchez added k8s-extended-e2e Trigger extended k8s e2e on a PR onhost-extended-e2e Execution of on host e2e in the current branch labels May 7, 2026
Comment thread agent-control/src/agent_control/config.rs Outdated
Comment thread agent-control/src/agent_control/config.rs
Comment thread agent-control/src/agent_control/config.rs Outdated
Comment thread agent-control/tests/on_host/cli.rs Outdated
Comment thread agent-control/tests/on_host/config_repository.rs
@danielorihuela

Copy link
Copy Markdown
Contributor

From my side we could merge it. Should we mention that on a Tech Talk just in case? I mean before merging.

@DavSanchez

Copy link
Copy Markdown
Contributor Author

From my side we could merge it. Should we mention that on a Tech Talk just in case? I mean before merging.

Added item for next tech meeting

@sigilioso

Copy link
Copy Markdown
Contributor

Maybe we should also remove it from the renovate rule:

{
"enabled": false,
"matchPackageNames": [
"/serde_yaml/"
]
},

@DavSanchez

Copy link
Copy Markdown
Contributor Author

Maybe we should also remove it from the renovate rule:

{
"enabled": false,
"matchPackageNames": [
"/serde_yaml/"
]
},

Good catch! 54c8240

@DavSanchez DavSanchez force-pushed the refactor/use-serde-saphyr branch from 54c8240 to 6ca57c9 Compare May 13, 2026 08:07

@sigilioso sigilioso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@DavSanchez DavSanchez merged commit 81bf81b into main May 14, 2026
76 of 80 checks passed
@DavSanchez DavSanchez deleted the refactor/use-serde-saphyr branch May 14, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k8s-extended-e2e Trigger extended k8s e2e on a PR onhost-extended-e2e Execution of on host e2e in the current branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants