Skip to content

Commit

Permalink
changed the base value we use for the increments
Browse files Browse the repository at this point in the history
  • Loading branch information
Athishpranav2003 committed Jun 14, 2024
1 parent 004c413 commit 82f9ff6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/fluent/plugin/filter_throttle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ 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
if since_last_rate_reset >= 1
# 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

Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit 82f9ff6

Please sign in to comment.