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 447825b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
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 447825b

Please sign in to comment.