← Back to Pull requests

feat(aggregate transform): Add `set_interval_ms` option #26597

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 08, 2026 18:32 UTC
Author

Summary

This PR adds an opt-in set_interval_ms option (default false) to the aggregate transform. When the option is on, each incremental metric that a flush emits gets interval_ms set to the configured flush interval_ms. Downstream components can then read an aggregated counter as a rate over the window. For example, datadog_metrics sends counters that have an interval as Datadog rates.

Today, users get this behavior with a lua or remap step after aggregate that sets interval_ms by hand. The value in that step must match the aggregate interval, and nothing checks that.

Behavior when enabled:

  • The interval is set on metrics from the system-time flush, the event-time bucket flush, and the final flush on shutdown.

  • Only Incremental metrics are changed. Absolute metrics are not changed, because MetricData::into_absolute already clears the interval. Metrics that pass through unchanged are not changed either, because they are not aggregated over the window.

  • An interval_ms that already exists on input is overwritten with the flush interval.

  • Aggregate::new requires interval_ms to be a whole number of seconds (a multiple of 1000) when the option is on, because Datadog sends the interval as whole seconds. So this option never creates sub-second rate windows.

  • Aggregate::new rejects interval_ms > u32::MAX when the option is on, because MetricTime::interval_ms is NonZeroU32. Configs that do not turn on the option get no new limit.
  • The option is applied once, after the flush, on the slice of output that the flush added. Events that are already in the caller's buffer are not changed.

    datadog_metrics sink: fractional-second intervals

    From review: both series encoders (series_to_proto_message for v2, encode_metric_to_v3 for v3) converted interval_ms to seconds with integer division. With interval_ms < 1000 the divisor was 0, so the rate was inf (or NaN for a zero counter). Intervals that are not whole seconds overstated the rate (1500 ms was divided by 1).

    Both encoders now share one series_interval() helper:

  • The rate value is divided by the exact interval in seconds (interval_ms as f64 / 1000.0).

  • The wire interval field is whole seconds in both protocols (int64 interval in v2, uint64 intervals in v3), so it is sent as max(1, round(secs)) instead of being truncated to 0.
  • Tradeoff: for a non-whole-second interval the rate is exact, but as_count() (rate × interval) uses the rounded field. Whole-second intervals are not affected. A gauge with a sub-second interval now gets interval field 1 instead of 0, and its value does not change.

    Not in this PR

    Review found more edge cases in rate windows. They touch shared code, so they move to a follow-up PR:

  • The sink's counter collapse (sort_and_collapse_counters_by_series_and_timestamp) adds values but keeps one interval. Two sub-second windows of one series in the same second are sent at about twice the rate. set_interval_ms cannot produce this (it requires whole seconds); other sources with sub-second intervals can. Before this PR, those were sent as inf.

  • Flushed metrics keep their latest sample timestamp, not the window start, so a rate can be placed up to one interval late. The value is correct.

  • The first flush after startup and the final flush on shutdown or reload can cover a partial window but carry the full interval. No counts are lost: as_count() (rate × interval) returns the true total.
  • References

    Closes: #15659
    Related: #23762
    Related: #24686. That draft sets the interval on counters unconditionally. This PR makes it opt-in, as @pront suggested on #15659, so existing datadog_metrics output does not change unless a user turns the option on.

    Vector configuration

    sources:
      demo:
        type: demo_logs
        format: shuffle
        lines: ["hello"]
        interval: 0.1
    transforms:
      to_metric:
        type: log_to_metric
        inputs: [demo]
        metrics:
          - type: counter
            field: message
            name: demo_lines
      agg:
        type: aggregate
        inputs: [to_metric]
        interval_ms: 2000
        set_interval_ms: true
    sinks:
      out:
        type: console
        inputs: [agg]
        encoding:
          codec: json
    

    Output with set_interval_ms: true:

    {"name":"demo_lines","timestamp":"...","interval_ms":2000,"kind":"incremental","counter":{"value":18.0}}
    

    Output with set_interval_ms: false (unchanged from today):

    {"name":"demo_lines","timestamp":"...","kind":"incremental","counter":{"value":18.0}}
    

    How did you test this PR?

  • Added unit tests in src/transforms/aggregate/tests.rs: config parsing and default, the u32 limit, flag off, system-time flush and final flush, overwrite of an existing interval, passthrough and existing output buffer not changed, event-time buckets

  • cargo test --lib --no-default-features --features transforms-aggregate transforms::aggregate: 38 passed

  • Mutation check: with the interval logic disabled, the 3 tests that check the interval is set fail

  • cargo fmt --all -- --check

  • cargo clippy --lib --tests --no-default-features --features transforms-aggregate -- -D warnings

  • End-to-end run of the config above with the flag on and off (output shown above)

  • Regenerated website/cue/reference/components/transforms/generated/aggregate.cue with vdev build component-docs

  • vdev check changelog-fragments

  • Added unit tests in src/sinks/datadog/metrics/encoder.rs and encoder_v3.rs: series_interval() from 1 ms to u32::MAX, decoded v2 payload for 500 ms and 1500 ms intervals, and a v3 payload-equality check (0.5 over 500 ms encodes the same as 1.0 over 1000 ms)

  • Mutation check: with the old integer division restored, the 3 new sink tests fail and the existing whole-second rate test still passes

  • cargo test --lib --no-default-features --features sinks-datadog_metrics,transforms-aggregate -- sinks::datadog::metrics transforms::aggregate: 120 passed

  • cargo clippy --lib --tests --no-default-features --features sinks-datadog_metrics -- -D warnings

  • Datadog metrics integration tests (not run locally, I can generate a test key for this if needed)

  • make check-generated-docs / full-feature clippy (not run locally, because it needs the full default-feature build; CI covers these)

  • Added set_interval_ms_requires_whole_seconds (1, 500, 1500, 10001 ms rejected with the option and accepted without it; 1000, 2000, 60000 ms accepted). Mutation check: with the validation removed, it fails

  • End-to-end: interval_ms: 1500 with set_interval_ms: true is rejected at startup with the new error

  • Mock-server Datadog metrics integration tests (all_series_metric_types, smoke, default_series_version_uses_the_v3_intake): 3 passed

  • Regenerated website/generated/example-configs/transforms/aggregate/advanced.yaml
  • Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.

  • No. A maintainer will apply the no-changelog label to this PR.
  • Changelog fragments:

  • changelog.d/15659_aggregate_set_interval_ms.enhancement.md

  • changelog.d/26597_datadog_metrics_fractional_interval.fix.md
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: clreaume Review duration: 6844m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #26597"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%