Skip to content

fix(sinks): count every event a failed batch encode discards - #27328

Open
Goldloli wants to merge 1 commit into
vectordotdev:masterfrom
Goldloli:fix/batch-encode-discard-count
Open

Goldloli wants to merge 1 commit into
vectordotdev:masterfrom
Goldloli:fix/batch-encode-discard-count

Conversation

@Goldloli

Copy link
Copy Markdown

Summary

A sink abandons the whole batch when one event fails to encode, but only the failing event was counted as discarded. The remaining events in that batch are never sent and never counted, so they show up in neither component_sent_events_total nor component_discarded_events_total.

This report the events the codec does not: after an encode failure the encoder emits an EventsDropped event for the rest of the batch and then returns the original error.

Fixes #27295

References

Fixes #27295

Vector configuration

The configuration from the issue, which exercises the http sink encoder path:

sinks:
  out:
    type: http
    inputs: [in]
    uri: "https://example/v1/metrics"
    encoding:
      codec: otlp
    batch:
      max_events: 500

How did you test this PR?

Two new unit tests cover the batch encoder in src/sinks/util/encoding.rs and the http sink encoder in src/sinks/http/encoder.rs. Each builds a three-event batch whose third event exceeds the serializer's nesting limit, then asserts the discarded-events counter reaches 3 rather than 1.

cargo test --package vector --features sinks-http --no-default-features --lib -- \
  sinks::http::tests::http_encode_failure_counts_every_discarded_event \
  sinks::util::encoding::tests::test_encode_batch_failure_counts_every_discarded_event
→ test result: ok. 2 passed; 0 failed

cargo test --package vector --features sinks-http --no-default-features --lib -- \
  sinks::util::encoding:: sinks::http::
→ test result: ok. 54 passed; 0 failed

Mutation check: with emit_dropped reduced to a no-op, both tests fail with left: Counter { value: 1.0 } against the expected 3.0 — the behaviour reported in the issue.

cargo clippy --package vector --features sinks-http --no-default-features --all-targets reports no findings in the changed files. It does flag a pre-existing unused_async_trait_impl in src/sinks/http/config.rs, whose only awaits sit behind #[cfg(feature = "aws-core")] and so disappear in that reduced feature set.

vdev check events could not run locally: the crate download for libz-sys returned HTTP 504 from the configured mirror. CI covers it.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
    For a new deprecation announcement, follow the deprecation policy and add a deprecation.d/ notice instead.
  • No. A maintainer will apply the no-changelog label to this PR.

The fragment is changelog.d/27295_batch_encode_discard_count.fix.md.

A sink discards the whole batch when one event fails to encode, but the
codec only reports the failing event as dropped. The remaining events are
never sent and never counted, so they appear in neither
component_sent_events_total nor component_discarded_events_total.

Emit an EventsDropped event for the rest of the batch in both batch
encoders before returning the original error.

Fixes vectordotdev#27295

Generated with DeepSeek V4.1 Flash (per AI_POLICY.md agentic contribution guidance)
@Goldloli
Goldloli requested a review from a team as a code owner November 25, 2026 09:55
@github-actions github-actions Bot added the domain:sinks Anything related to Vector's sinks label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, please sign our Contributor License Agreement.

To sign, copy and post the phrase below as a new comment on this PR.

Note: If the bot says your username was not found, the email used in your git commit may not be linked to your GitHub account. Fix this at github.com/settings/emails, then comment recheck to retry.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@datadog-official datadog-official Bot added domain:internal-observability Anything related to monitoring/observing Vector domain:metrics Anything related to Vector's metrics events sink:http Anything `http` sink related labels Nov 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T09:57:57.602087Z 0e3020e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadoghq-integration datadoghq-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The added discard count complements the codec’s existing single-event count, accounting for the entire abandoned batch while preserving error propagation. Caller inspection found no duplicate discard reporting.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0e3020e

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain:internal-observability Anything related to monitoring/observing Vector domain:metrics Anything related to Vector's metrics events domain:sinks Anything related to Vector's sinks sink:http Anything `http` sink related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sinks: batch encoder aborts remaining events when one event fails to encode, but only counts 1 dropped event

1 participant