From 447825b09006133c0673b8917f17cd307282446f Mon Sep 17 00:00:00 2001 From: Athish Pranav Date: Fri, 14 Jun 2024 12:33:01 +0530 Subject: [PATCH] changed the base value we use for the increments --- README.md | 2 +- lib/fluent/plugin/filter_throttle.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 85545c9..9e45f0e 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ the delay between every repetition. Default: `false`. -When a group reaches its limit, metrics will be emitted for the logs being dropped if this value is true . This metrics can be scraped like any other metrics emitted in prometheus format. `podname` is a additional label available to identify the throttled groups. \\ +When a group reaches its limit, metrics will be emitted for the logs being dropped if this value is true . This metrics can be scraped like any other metrics emitted in prometheus format. Group keys are available to identify the throttled groups as additional labels. \\ Metrics for the filter is - `fluentd_throttle_rate_limit_exceeded` diff --git a/lib/fluent/plugin/filter_throttle.rb b/lib/fluent/plugin/filter_throttle.rb index 9923e1b..8181cca 100644 --- a/lib/fluent/plugin/filter_throttle.rb +++ b/lib/fluent/plugin/filter_throttle.rb @@ -117,7 +117,7 @@ def filter(tag, time, record) # Ruby hashes are ordered by insertion. # Deleting and inserting moves the item to the end of the hash (most recently used) - counter = @counters[group] = @counters.delete(group) || Group.new(0, now, 0, 0, now, nil, @group_bucket_limit) + counter = @counters[group] = @counters.delete(group) || Group.new(0, now, 0, 0, now, nil, 0) counter.rate_count += 1 since_last_rate_reset = now - counter.rate_last_reset @@ -125,7 +125,7 @@ def filter(tag, time, record) # compute and store rate/s at most every second counter.aprox_rate = (counter.rate_count / since_last_rate_reset).round() counter.rate_count = 0 - counter.rate_count_last = @group_bucket_limit + counter.rate_count_last = 0 counter.rate_last_reset = now end @@ -186,8 +186,8 @@ def log_rate_limit_exceeded(now, group, counter) groupped_label = @group_key_symbols.zip(group).to_h metric = @metrics[:throttle_rate_limit_exceeded] log.debug("current rate",counter.rate_count,"current metric",metric.get(labels: @base_labels.merge(groupped_label))) - metric.increment(by: counter.rate_count - counter.rate_count_last, labels: @base_labels.merge(groupped_label)) - counter.rate_count_last = counter.rate_count + metric.increment(by: counter.rate_count - counter.rate_count_last - @group_bucket_limit, labels: @base_labels.merge(groupped_label)) + counter.rate_count_last = counter.rate_count - @group_bucket_limit end emit = counter.last_warning == nil ? true \