Skip to content

Addition of a resend_attempts counter to prevent output worker blocking. #21

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
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.0
- Preventing output blocking when the graphite server is down by introducing a resend_attempts counter.

## 2.0.3
- Fixed empty/nil messages handling

Expand All @@ -10,4 +13,4 @@
- Added support for sprintf in field formatting

## 1.0.1
- Added support for nested hashes as values
- Added support for nested hashes as values
11 changes: 9 additions & 2 deletions lib/logstash/outputs/graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class LogStash::Outputs::Graphite < LogStash::Outputs::Base
# Interval between reconnect attempts to Carbon.
config :reconnect_interval, :validate => :number, :default => 2

# Number of attempts to be made resending metrics before abandoning
config :resend_attempts, :validate => :number, :default => 3

# Should metrics be resent on failure?
config :resend_on_failure, :validate => :boolean, :default => false

Expand Down Expand Up @@ -94,12 +97,14 @@ def register

def connect
# TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. Retire to yak farm.
numattempts = 0
begin
numattempts += 1
@socket = TCPSocket.new(@host, @port)
rescue Errno::ECONNREFUSED => e
@logger.warn("Connection refused to graphite server, sleeping...", :host => @host, :port => @port)
sleep(@reconnect_interval)
retry
retry if numattempts < @resend_attempts
end
end

Expand Down Expand Up @@ -130,13 +135,15 @@ def receive(event)

# Catch exceptions like ECONNRESET and friends, reconnect on failure.
# TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory.
numattempts = 0
begin
numattempts += 1
@socket.puts(message)
rescue Errno::EPIPE, Errno::ECONNRESET, IOError => e
@logger.warn("Connection to graphite server died", :exception => e, :host => @host, :port => @port)
sleep(@reconnect_interval)
connect
retry if @resend_on_failure
retry if @resend_on_failure || numattempts < @resend_attempts
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-output-graphite.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-output-graphite'
s.version = '2.0.3'
s.version = '2.1.0'
s.licenses = ['Apache License (2.0)']
s.summary = "This output allows you to pull metrics from your logs and ship them to Graphite"
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
Expand Down