Repository navigation
Conversation
…metrics Track per-message delivery results using PartialWriteError. Keep transient failures for retry and add an opt-in drop policy for unknown topics or partitions. Cover mixed failures, serialization gaps, buffer draining and topic recovery. Co-Authored-By: OpenAI Codex (GPT-6) <noreply@openai.com>
|
Thanks so much for the pull request! |
|
!signed-cla |
skartikey
left a comment
There was a problem hiding this comment.
@kVinsom Thanks, the client-side size and header case is covered now.
I checked sarama v1.61.1 only returns a per-message ConfigurationError for those two, so rejecting it is safe, and the MockBroker tests show the buffer draining past a full batch of them.
There was a problem hiding this comment.
Please merge this file into kafka_test.go!
| plugin := &Kafka{ | ||
| Topic: "existing", | ||
| Headers: tt.headers, | ||
| Log: testutil.Logger{}, | ||
| producerFunc: sarama.NewSyncProducer, | ||
| serializer: serializer, | ||
| } | ||
| plugin.Version = tt.version | ||
| plugin.MaxMessageBytes = 256 | ||
| plugin.RequiredAcks = 1 |
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
Summary
When only part of a Kafka batch fails, retrying the entire batch duplicates messages that were already delivered.
Conversely, treating one permanent error as success for the entire batch can discard unrelated failed messages.
Return
internal.PartialWriteErrorwith the original metric indices: acknowledge successful deliveries, reject individual permanent failures, and retain transient failures for retry.The indices remain correct when serialization skips metrics or Sarama reports errors out of order.
An error without per-message delivery results retains every submitted metric because its delivery status is unknown.
Permanent failures include serialization errors, broker size/timestamp errors, and per-message
sarama.ConfigurationErrorvalues, including wrapped errors.Sarama uses the latter for messages exceeding the local
max_message_byteslimit and headers unsupported by the configured Kafka version.These metrics are rejected individually instead of being retried on every flush.
Following review, this PR contains no new configuration option:
topic_error_behavior, drop-mode tests, and the associated sample configuration/documentation have been removed for a separate feature change.Unknown-topic-or-partition errors retain the existing retry behavior because they can be temporary.
A batch filled entirely with unavailable-topic messages can still block newer metrics until the topic or partition recovers; this PR does not introduce an opt-in data-dropping policy.
Regression coverage includes mixed permanent/transient errors, wrapped errors, original indices across serialization gaps, and unclassified batch errors.
Tests using a real Sarama producer against
MockBrokerexercise Telegraf's buffer and delivery tracking, including oversized messages in mixed/full batches, unsupported headers, later-batch progress, and recovery of a temporarily missing topic.No dependency, delivery-timeout, or build-configuration changes are included.
#19735 addresses stalled deliveries separately; both changes touch
Write()and may need reconciliation depending on merge order.Validation
go test -short ./plugins/outputs/kafka ./plugins/common/kafka ./models -count=1 -timeout=180spasses.go test -race -short ./plugins/outputs/kafka ./plugins/common/kafka ./models -count=1 -timeout=180spasses. The mock broker starts only after plugin initialization to avoid racing Sarama's global logger setup.go vet ./plugins/outputs/kafka ./plugins/common/kafka ./modelspasses.golangci-lintv2.15.0 on./plugins/outputs/kafka/...: 0 issues.gofmt, Markdown lint, the project's README linter, andgit diff --checkpass.The Kafka README was regenerated using the project's config includer.
The real-producer
MockBrokertests ran without Docker.The repository-wide test suite was not run locally; fresh CI is required for this revision.
Checklist
AI-assisted implementation and validation using OpenAI Codex.
Related issues
Part of #10864.
Review follow-up (4 November 2026)
Merged the configuration-error regression tests into
kafka_test.goand combined the plugin configuration into one struct initializer, as requested. The logger is still initialized before starting the mock broker.Merged current
master(f6d5b919a). The Kafka output, common Kafka code and models pass Linux race tests; the project-pinned Kafka linter reports zero issues. The Docker-backed integration test remains unrun locally.