Skip to content

Add redis output congestion_attempts #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
# Zero means to check on every event.
config :congestion_interval, :validate => :number, :default => 1

# How many attempts to make to send to redis while congestion is at
# its threshold. Will try connecting to the next server in the host
# list after attempts is reached. This will take
# time_in_secs = :congestion_interval * :congestion_attempts
config :congestion_attempts, :validate => :number, :default => 0

def register
require 'redis'

Expand Down Expand Up @@ -182,10 +188,16 @@ def receive(event)

def congestion_check(key)
return if @congestion_threshold == 0
tries = 0
if (Time.now.to_i - @congestion_check_times[key]) >= @congestion_interval # Check congestion only if enough time has passed since last check.
while @redis.llen(key) > @congestion_threshold # Don't push event to Redis key which has reached @congestion_threshold.
@logger.warn? and @logger.warn("Redis key size has hit a congestion threshold #{@congestion_threshold} suspending output for #{@congestion_interval} seconds")
sleep @congestion_interval
tries += 1
if tries > @congestion_attempts and @congestion_attempts > 0
@redis = connect
tries = 0
end
end
@congestion_check_times[key] = Time.now.to_i
end
Expand Down