Skip to content

Commit 447825b

Browse files
changed the base value we use for the increments
1 parent 004c413 commit 447825b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ the delay between every repetition.
137137

138138
Default: `false`.
139139

140-
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. \\
140+
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. \\
141141
Metrics for the filter is
142142
- `fluentd_throttle_rate_limit_exceeded`
143143

lib/fluent/plugin/filter_throttle.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ def filter(tag, time, record)
117117

118118
# Ruby hashes are ordered by insertion.
119119
# Deleting and inserting moves the item to the end of the hash (most recently used)
120-
counter = @counters[group] = @counters.delete(group) || Group.new(0, now, 0, 0, now, nil, @group_bucket_limit)
120+
counter = @counters[group] = @counters.delete(group) || Group.new(0, now, 0, 0, now, nil, 0)
121121

122122
counter.rate_count += 1
123123
since_last_rate_reset = now - counter.rate_last_reset
124124
if since_last_rate_reset >= 1
125125
# compute and store rate/s at most every second
126126
counter.aprox_rate = (counter.rate_count / since_last_rate_reset).round()
127127
counter.rate_count = 0
128-
counter.rate_count_last = @group_bucket_limit
128+
counter.rate_count_last = 0
129129
counter.rate_last_reset = now
130130
end
131131

@@ -186,8 +186,8 @@ def log_rate_limit_exceeded(now, group, counter)
186186
groupped_label = @group_key_symbols.zip(group).to_h
187187
metric = @metrics[:throttle_rate_limit_exceeded]
188188
log.debug("current rate",counter.rate_count,"current metric",metric.get(labels: @base_labels.merge(groupped_label)))
189-
metric.increment(by: counter.rate_count - counter.rate_count_last, labels: @base_labels.merge(groupped_label))
190-
counter.rate_count_last = counter.rate_count
189+
metric.increment(by: counter.rate_count - counter.rate_count_last - @group_bucket_limit, labels: @base_labels.merge(groupped_label))
190+
counter.rate_count_last = counter.rate_count - @group_bucket_limit
191191
end
192192

193193
emit = counter.last_warning == nil ? true \

0 commit comments

Comments
 (0)