Skip to content

Commit 5fff944

Browse files
cosmo0920edsiper
authored andcommitted
in_winevtlog: Apply backoff settings effectively
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 088fdfe commit 5fff944

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

plugins/in_winevtlog/winevtlog.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,23 @@ static int winevtlog_next(struct winevtlog_channel *ch, int hit_threshold)
707707
return FLB_FALSE;
708708
}
709709

710-
static inline void backoff_defaults(struct winevtlog_backoff *dst, const struct winevtlog_backoff *src)
710+
static const struct winevtlog_backoff WINEVTLOG_BACKOFF_DEFAULTS = {
711+
500, /* base_ms */
712+
30000, /* max_ms */
713+
2000, /* multiplier_x1000 == x2.0 */
714+
20, /* jitter_pct */
715+
8 /* max_retries */
716+
};
717+
718+
static inline void backoff_effective(struct winevtlog_backoff *dst,
719+
const struct winevtlog_backoff *src)
711720
{
712-
dst->base_ms = (src && src->base_ms) ? src->base_ms : 500;
713-
dst->max_ms = (src && src->max_ms) ? src->max_ms : 30000;
714-
dst->multiplier_x1000 = (src && src->multiplier_x1000) ? src->multiplier_x1000 : 2000; /* x2.0 */
715-
dst->jitter_pct = (src && src->jitter_pct) ? src->jitter_pct : 20;
716-
dst->max_retries = (src && src->max_retries) ? src->max_retries : 8;
721+
if (src) {
722+
*dst = *src;
723+
}
724+
else {
725+
*dst = WINEVTLOG_BACKOFF_DEFAULTS;
726+
}
717727
}
718728

719729
static inline DWORD prng16(ULONGLONG *state)
@@ -753,7 +763,7 @@ void winevtlog_schedule_retry(struct winevtlog_channel *ch, struct winevtlog_con
753763
{
754764
struct winevtlog_backoff cfg;
755765
DWORD delay = 0;
756-
backoff_defaults(&cfg, ctx ? &ctx->backoff : NULL);
766+
backoff_effective(&cfg, ctx ? &ctx->backoff : NULL);
757767
delay = calc_backoff_ms(ch, &cfg, ch->retry_attempts);
758768
ch->next_retry_deadline = GetTickCount64() + (ULONGLONG)delay;
759769
}
@@ -958,7 +968,7 @@ int winevtlog_read(struct winevtlog_channel *ch, struct winevtlog_config *ctx,
958968
int rc = winevtlog_try_reconnect(ch, ctx);
959969
if (rc != 0) {
960970
struct winevtlog_backoff eff;
961-
backoff_defaults(&eff, ctx ? &ctx->backoff : NULL);
971+
backoff_effective(&eff, ctx ? &ctx->backoff : NULL);
962972
if (ch->retry_attempts < eff.max_retries) {
963973
ch->retry_attempts++;
964974
winevtlog_schedule_retry(ch, ctx);

0 commit comments

Comments
 (0)