Skip to content

feat(agent): Continue flushing for outputs rejecting metrics - #20033

Merged
skartikey merged 4 commits into
influxdata:masterfrom
srebhan:partial_write_error
Nov 16, 2026
Merged

skartikey merged 4 commits into
influxdata:masterfrom
srebhan:partial_write_error

Conversation

@srebhan

@srebhan srebhan commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Currently, the output model stops flushing filled buffers if not at least one metric was accepted to prevent flush storms on outputs which cannot handle metrics e.g. if the endpoint is not reachable. However, this neglects cases where metrics in a batch are permanently rejected, e.g. if they cannot be serialized or because the output cannot send those metrics because they are too old. In those cases we could continue flushing minimizing the chance of buffer overflows.

This PR forces the model to continue flushing for partial-write-errors if the buffer is modified i.e. at least one metric was accepted or rejected.

Checklist

Related issues

resolves #20015
superseeds #20016
related to #19945
related to #19953

@telegraf-tiger telegraf-tiger Bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Nov 2, 2026
@srebhan srebhan added area/agent ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Nov 2, 2026
Comment thread internal/errors.go Resolved
Comment thread models/running_output_test.go Outdated
require.Len(t, plugin.Metrics(), totalMetrics)
}

func TestRunningOutputNoRetriggerOnStopFlushingPartialWriteError(t *testing.T) {

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.

[nit] Same scenario as TestRunningOutputNoRetriggerOnUnsuccessfulPartialWriteError above, since false is the zero value. Could we fold the extra assertions into that test instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted to make this explicit to keep the symmetry, i.e. to have an explicit test for both cases...

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.

Fair enough, keep both.

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.

With the flag gone this is the same case as TestRunningOutputNoRetriggerOnUnsuccessfulPartialWriteError again, and StopFlushing in the name points at a field that no longer exists. Could we fold its stronger asserts into the older test, or at least rename it?

@skartikey

Copy link
Copy Markdown
Contributor

One question outside the diff. azure_monitor already rejects too-old metrics, and when the whole batch is outside the window the len(azmetrics) == 0 branch returns nothing accepted, so after an outage a stale buffer still drains one batch per interval. Set ContinueFlushing there in this PR, or leave it to #19953 and a follow-up?

@srebhan

srebhan commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

One question outside the diff. azure_monitor already rejects too-old metrics, and when the whole batch is outside the window the len(azmetrics) == 0 branch returns nothing accepted, so after an outage a stale buffer still drains one batch per interval. Set ContinueFlushing there in this PR, or leave it to #19953 and a follow-up?

I prefer a separate PR. The same might happen to other plugins where none of the metrics sent is valid...

@JoeGadd-BBC

Copy link
Copy Markdown

@srebhan I'm guessing I should wait until this PR is merged in and then I should update my PR: #19953
to add the ContinueFlushing flag?

Comment thread models/running_output.go Resolved
Comment thread models/running_output_test.go Resolved
Comment thread internal/errors.go Resolved
@srebhan
srebhan force-pushed the partial_write_error branch from 9501cde to c747f58 Compare November 16, 2026 14:18
@srebhan srebhan changed the title feat(agent): Allow plugin to signal to continue flushing feat(agent): Continue flushing for outputs rejecting metrics Nov 16, 2026
@srebhan

srebhan commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

@skartikey and @JoeGadd-BBC iterating on this problem I found that we should start without an additional flag in the PartialWriteError struct and instead continue flushing as long as the buffer is modified by the output to eliminate metrics from the buffer. If really necessary, we can later add back a StopFlushing flag.

@telegraf-tiger

Copy link
Copy Markdown
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

⚠️ This pull request increases the Telegraf binary size by 7.42 % for linux amd64 (new size: 331.1 MB, nightly size 308.2 MB)

📦 Click here to get additional PR build artifacts

Artifact URLs

. DEB . RPM . TAR . GZ . ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip
armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip
armhf.deb i386.rpm freebsd_armv7.tar.gz
i386.deb ppc64le.rpm freebsd_i386.tar.gz
mips.deb riscv64.rpm linux_amd64.tar.gz
mipsel.deb s390x.rpm linux_arm64.tar.gz
ppc64el.deb x86_64.rpm linux_armel.tar.gz
riscv64.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz

@skartikey

Copy link
Copy Markdown
Contributor

@srebhan Agreed. That also means the all-stale azure_monitor branch drains without any change there, so I'll drop the follow-up I mentioned.

@JoeGadd-BBC that answers your question too. No flag needed on #19953, rejecting the expired metrics is enough once this lands.

Comment thread models/running_output.go
// was modified, i.e. at least one metric was accepted or rejected, in order
// to avoid flush storms hammering the plugin's endpoint with requests while
// it potentially cannot accept any.
r.continueFlushing.Store(len(writeErr.MetricsAccept) > 0 || len(writeErr.MetricsReject) > 0)

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.

[question] Are we ok with this for outputs that reject on a server answer, like influxdb_v2 on a transient 404 (it rejects any unlisted 4xx)? With an all-reject mock the buffer now empties back to back, 5000 metrics gone in under 500ms, where master drops one batch per flush interval.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think we should rather fix the plugin here as it might be correct to drop the whole buffer or not but the previous behavior is certainly bad either. What do you think?

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.

Agreed, fixing the plugin is the right place. I'll open a PR for influxdb_v2 to keep 404 as a plain retry error like 401 and 403, so only real permanent rejects drain the buffer.

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.

Correction on the influxdb_v2 404 idea. A 404 there is mostly bucket not found with bucket_tag, and TestStatusCodeNonRetryable4xx pins that those metrics get dropped. Retrying them would keep them in the buffer until overflow and push out metrics for the good buckets, so I'll leave 404 as it is. Draining a missing bucket quickly is fine.

Comment thread models/running_output_test.go Outdated
require.Len(t, plugin.Metrics(), totalMetrics)
}

func TestRunningOutputNoRetriggerOnStopFlushingPartialWriteError(t *testing.T) {

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.

With the flag gone this is the same case as TestRunningOutputNoRetriggerOnUnsuccessfulPartialWriteError again, and StopFlushing in the name points at a field that no longer exists. Could we fold its stronger asserts into the older test, or at least rename it?

@skartikey
skartikey merged commit a3780d0 into influxdata:master Nov 16, 2026
23 of 24 checks passed
@skartikey
skartikey deleted the partial_write_error branch November 16, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RunningOutput stops flushing after the first batch with a PartialWriteError, even when all its metrics are rejected

3 participants