Skip to content
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

feat(statsd source): add convert_to option for controlling timing unit conversion #22716

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

devkoriel
Copy link

@devkoriel devkoriel commented Mar 24, 2025

Summary

This PR introduces a new configuration option to the StatsD source: convert_to, which allows users to explicitly control how incoming timing values in milliseconds (ms) are handled.

By default, StatsD timing values are emitted as distributions and converted from milliseconds to seconds. This behavior was previously hardcoded. With this change, users can choose:

  • convert_to = "seconds" (default): preserves current behavior — ms values are converted to s.
  • convert_to = "milliseconds": disables conversion — values remain in ms.

This is a new feature; there was no convert_timers_to_seconds in the base branch. The addition of the ConversionUnit enum makes the configuration more descriptive, future-proof, and avoids implicit behavior.

Key highlights:

  • ✅ Introduced ConversionUnit enum with variants: Seconds (default) and Milliseconds.
  • ✅ Added a new convert_to field to all StatsD source configs (UdpConfig, TcpConfig, UnixConfig).
  • ✅ Updated the parser to apply conversion logic to all applicable StatsD metric types: ms, h, d.
  • ✅ Implemented Configurable, ToValue, Serialize, Deserialize, and Default for the enum.
  • ✅ Generated schema properly reflects the enum as a string with allowed values.
  • ✅ Fully updated user-facing documentation (in .cue and how_it_works) to reflect the new option.
  • ✅ Addressed all Clippy and formatting issues:
    • Removed manual Default impl in favor of #[derive(Default)] + #[default] on enum variant.
    • Rewrote schema generation to avoid field reassignments (field_reassign_with_default).

This feature was inspired by Discussion #22656, where it was suggested to replace implicit ms → s conversion with an explicit, configurable option.

Change Type

  • Bug fix
  • New feature
  • Non-functional (docs, formatting, refactor)

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

  • Added unit and integration tests verifying that:
    • convert_to = "milliseconds" preserves original values.
    • convert_to = "seconds" applies the expected conversion.
  • Confirmed downstream metrics (in glork, timer, etc.) reflect expected sampling behavior.
  • Ran cargo vdev test, cargo nextest run, cargo clippy --all-targets -- -D warnings, and make check-all.
  • Confirmed config schema is generated with correct enum values.
  • Verified docs and .cue updates render as expected.

Does this PR include user-facing changes?

  • Yes. Please add a changelog fragment in changelog.d/ per guidelines.
  • No. A maintainer will apply the no-changelog label.

Checklist

  • I’ve read the Vector contributor docs
  • I ran:
    • cargo fmt --all
    • cargo clippy --workspace --all-targets -- -D warnings
    • cargo nextest run --workspace
    • make check-all
  • N/A — This PR modifies dependencies (if it does, I’ll run dd-rust-license-tool write)
  • I’ve updated .cue docs and how_it_works blocks to reflect user-facing config changes.

References

Please let me know if further changes are required.

This commit introduces a new boolean configuration option,
convert_timers_to_seconds, in the StatsD source configuration. By
default, this option is set to true (the current behavior) so that
timing values in milliseconds are converted to seconds. Setting it to
false disables the conversion, preserving the original millisecond
values.

Changes include:

Adding the convert_timers_to_seconds field (with a default of true) in
UDP and TCP source configurations and, where applicable, in the Unix
configuration.

Updating the StatsD parser to conditionally convert ms values based on
the new option.

Adjusting unit and integration tests to account for the new behavior. In
particular, when conversion is disabled, the sample value for a timer
metric reflects the original ms value multiplied by the sample rate.

Updating the documentation to describe the new configuration option and
its effects on downstream systems.

This change improves flexibility for users integrating with sinks that
expect timing values in their original units, without breaking the
existing behavior by default.
…sion option

This commit updates the StatsD source configuration documentation to
include the new
convert_timers_to_seconds field. This option controls whether incoming
timing values in
milliseconds are converted to seconds. By default, it is set to true
(preserving current behavior);
when set to false, the original millisecond values remain unchanged.

Additionally, the "how_it_works.timings" section has been revised to
clearly explain this behavior,
ensuring that users understand the impact of this configuration on
downstream metric processing.
…ption

This commit adds a new changelog fragment file,
"22656_statsd_timer_conversion.feature.md", to document the introduction
of a configurable option in the StatsD source. With this change, users
can control whether timing values in milliseconds (`ms`) are converted
to seconds (`s`). By default, the conversion is enabled; however,
setting `convert_timers_to_seconds` to `false` preserves the original
millisecond values.

This enhancement provides greater flexibility for users whose downstream
systems expect timer metrics in their original units and was inspired by
the discussion in GitHub Discussion
[vectordotdev#22656](vectordotdev#22656).

authors: devkoriel
This commit changes the implementation of
`default_convert_timers_to_seconds` from a regular function to a `const
fn` in the StatsD source. This update resolves compilation issues in
constant contexts, ensuring that the default value for the new
`convert_timers_to_seconds` configuration field is usable in const
initializations.

The function's behavior remains unchanged, as it continues to return
`true`.
@devkoriel devkoriel requested review from a team as code owners March 24, 2025 13:21
@bits-bot
Copy link

bits-bot commented Mar 24, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added domain: sources Anything related to the Vector's sources domain: sinks Anything related to the Vector's sinks domain: external docs Anything related to Vector's external, public documentation labels Mar 24, 2025
Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

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

Thank you @devkoriel

…licit `convert_to` unit

This commit replaces the previous `convert_timers_to_seconds` boolean
configuration
with a new enum-based `convert_to` field of type `ConversionUnit`. This
change allows
users to explicitly specify the target unit for StatsD timing values.

Key changes include:
- Introduced the `ConversionUnit` enum with variants: `Seconds`
(default) and `Milliseconds`.
- Updated all relevant config structures (UDP, TCP, and Unix) to use
`convert_to` instead of a boolean.
- Updated the `Parser` logic to conditionally convert `ms` based on the
`convert_to` value.
- Implemented the `Configurable`, `Default`, `ToValue`, `Deserialize`,
and `Serialize` traits for `ConversionUnit`.
- Updated `generate_schema` to properly generate a string enum schema
for the new option.
- Updated docs (`*.cue`) and help text to reflect the new `convert_to`
configuration.
- Cleaned up old usage of `convert_timers_to_seconds` and fixed Clippy
lints (`derivable_impls`, `field_reassign_with_default`, etc).

This change provides users with more precise control over timing
conversions while maintaining backward-compatible behavior by default.

authors: devkoriel
@devkoriel devkoriel changed the title feat(statsd source): add configurable option to disable ms→s conversion feat(statsd source): add convert_to option for controlling timing unit conversion Mar 25, 2025
@devkoriel
Copy link
Author

@pront Thank you for your support! Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: external docs Anything related to Vector's external, public documentation domain: sinks Anything related to the Vector's sinks domain: sources Anything related to the Vector's sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants