-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52997f0
commit e7f2e71
Showing
13 changed files
with
129 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sidekiq-logstash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.2 | ||
- 2.3.0 | ||
- 2.4.0 | ||
before_install: gem install bundler -v 1.11.2 | ||
|
||
gemfile: | ||
- gemfiles/sidekiq4.gemfile | ||
- gemfiles/sidekiq5.gemfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in sidekiq-logstash.gemspec | ||
# Specify your gem's dependencies in sidekiq-logstash.gemspec | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem sidekiq '~> 4.0' | ||
|
||
gemspec :path => ''../' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem sidekiq '~> 5.0' | ||
|
||
gemspec :path => ''../' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Sidekiq | ||
module Logging | ||
module Shared | ||
def log_job(payload, started_at, exc = nil) | ||
# Create a copy of the payload using JSON | ||
# This should always be possible since Sidekiq store it in Redis | ||
payload = JSON.parse(JSON.unparse(payload)) | ||
|
||
# Convert timestamps into Time instances | ||
%w( created_at enqueued_at retried_at failed_at completed_at ).each do |key| | ||
payload[key] = parse_time(payload[key]) if payload[key] | ||
end | ||
|
||
# Add process id params | ||
payload['pid'] = ::Process.pid | ||
payload['duration'] = elapsed(started_at) | ||
|
||
message = "#{payload['class']} JID-#{payload['jid']}" | ||
|
||
if exc | ||
payload['message'] = "#{message}: fail: #{payload['duration']} sec" | ||
payload['job_status'] = 'fail' | ||
payload['error_message'] = exc.message | ||
payload['error'] = exc.class | ||
payload['error_backtrace'] = %('#{exc.backtrace.join("\n")}') | ||
else | ||
payload['message'] = "#{message}: done: #{payload['duration']} sec" | ||
payload['job_status'] = 'done' | ||
payload['completed_at'] = Time.now.utc | ||
end | ||
|
||
# Filter sensitive parameters | ||
unless filter_args.empty? | ||
args_filter = Sidekiq::Logging::ArgumentFilter.new(filter_args) | ||
payload['args'] = args_filter.filter({ args: payload['args'] })[:args] | ||
end | ||
|
||
# Needs to map all args to strings for ElasticSearch compatibility | ||
payload['args'].map!(&:to_s) | ||
|
||
payload | ||
end | ||
|
||
def elapsed(start) | ||
(Time.now.utc - start).round(3) | ||
end | ||
|
||
def parse_time(timestamp) | ||
return timestamp if timestamp.is_a? Time | ||
timestamp.is_a?(Float) ? | ||
Time.at(timestamp).utc : | ||
Time.parse(timestamp) | ||
rescue | ||
timestamp | ||
end | ||
|
||
def filter_args | ||
Sidekiq::Logstash.configuration.filter_args | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'sidekiq/logging/shared' | ||
|
||
module Sidekiq | ||
class LogstashJobLogger | ||
include Sidekiq::Logging::Shared | ||
|
||
def call(job, _queue) | ||
started_at = Time.now.utc | ||
yield | ||
Sidekiq.logger.info log_job(job, started_at) | ||
rescue => exc | ||
begin | ||
Sidekiq.logger.warn log_job(job, started_at, exc) | ||
rescue => ex | ||
Sidekiq.logger.error 'Error logging the job execution!' | ||
Sidekiq.logger.error "Job: #{job}" | ||
Sidekiq.logger.error "Job Exception: #{exc}" | ||
Sidekiq.logger.error "Log Exception: #{ex}" | ||
end | ||
raise | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters