Closed LukeWinikates closed 10 months ago
Flush
as of right now, this change does make it so that a 'throttling' LineHandler throttles all flushes, not just the ones that happen in the background.
This is potentially a breaking change, so we could implement a FlushWithThrottle
instead.
update: I did add the FlushWithThrottle
method.
This PR separates the responsibility for background flushing of the SDK's
buffer
channel into a type solely responsible for background flushing.Prior to this PR, the flush ticker goroutine also applied request throttling logic. This behavior is only ever enabled for the
event
handler.The throttling logic used the
RealLineHandler
's mutex to apply throttling. I'm not sure if that's a good idea or a bad idea, but it relied on running inside theRealLineHandler
's ticker goroutine - theSleep
needed to run in a goroutine in order unobtrusively blockFlush
es until the throttling time had ended.No existing tests cover this behavior, so we should backfill some before merging this PR.✅RealLineHandler
tests using the throttling behaviorThis PR doesn't use the mutex, but simply remembers the future time when it will be ok to send requests again, and if ~
Flush
~FlushWithThrottling
is called before that time is up, theFlushWithThrottling
usestime.Sleep
to wait until the cooldown period ends.Other Changes in this PR:
1m
from10m
, which should be enoughlockOnThrottledError
tothrottleRequestsOnBackpressure
FlushWithThrottling()
throttleOnSleepDuration
configurable for testingidea: is the
LineHandlerOption
interface worth it given this API is entirely internal anyway?🟢 the option API allows the
NewLineHandler
factory to have a small number of required fields ❔compare with standard library types likehttp.Client
, which has a lot of fields, but it seems that all of theirzero
values are designed to be appropriate defaults, and no other initialization is required.question: does the throttling logic in flush need to be protected by a mutex or atomic operators?
In practice:
In theory:
WaitGroup
?) might require enabling throttling for all the formats, and might require changes so that theresumeAt
field is atomically read and written.idea: allow opt-out of background flushing in the future
The telegraf output plugin has an awkward line where, if the user has set
immediate_flush = true
it sets the background flush interval to a very large number. Because there is no API for disabling background flushes completely.