Skip to content

Commit b1061ea

Browse files
committed
Upgrade to ruby 2.4.0 and added datadog metrics to alert on
1 parent 83079ef commit b1061ea

13 files changed

+51
-9
lines changed

Dockerfile_enqueuer

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitnotifier/ruby:latest
1+
FROM gitnotifier/ruby:2.4.0
22

33
# Set proper locale
44
ENV APP_ENV=development \
@@ -10,6 +10,9 @@ APP_CONFIG_REDIS_PORT=6379 \
1010
APP_CONFIG_REDIS_DB=1 \
1111
APP_CONFIG_REDIS_NAMESPACE=ghntfr \
1212

13+
APP_CONFIG_STATSD_HOST=localhost \
14+
APP_CONFIG_STATSD_PORT=8125 \
15+
1316
APP_CONFIG_DOMAIN=gitnotifier.local \
1417

1518
APP_CONFIG_SECRET=somesecret \

Dockerfile_puma

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitnotifier/ruby:latest
1+
FROM gitnotifier/ruby:2.4.0
22

33
# Set proper locale
44
ENV APP_ENV=development \
@@ -10,6 +10,9 @@ APP_CONFIG_REDIS_PORT=6379 \
1010
APP_CONFIG_REDIS_DB=1 \
1111
APP_CONFIG_REDIS_NAMESPACE=ghntfr \
1212

13+
APP_CONFIG_STATSD_HOST=localhost \
14+
APP_CONFIG_STATSD_PORT=8125 \
15+
1316
APP_CONFIG_DOMAIN=gitnotifier.local \
1417

1518
APP_CONFIG_SECRET=somesecret \

Dockerfile_sidekiq

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitnotifier/ruby:latest
1+
FROM gitnotifier/ruby:2.4.0
22

33
# Set proper locale
44
ENV APP_ENV=development \
@@ -10,6 +10,9 @@ APP_CONFIG_REDIS_PORT=6379 \
1010
APP_CONFIG_REDIS_DB=1 \
1111
APP_CONFIG_REDIS_NAMESPACE=ghntfr \
1212

13+
APP_CONFIG_STATSD_HOST=localhost \
14+
APP_CONFIG_STATSD_PORT=8125 \
15+
1316
APP_CONFIG_DOMAIN=gitnotifier.local \
1417

1518
APP_CONFIG_SECRET=somesecret \

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gem 'github_api', '~> 0.13.0'
55
gem "redis", "~> 3.2.1"
66
gem 'hiredis', '~> 0.6.0'
77
gem 'haml', '~> 4.0.6'
8-
gem 'json', '~> 1.8.1'
8+
gem 'json', '~> 2.0'
99
gem 'sidekiq', '~> 4.1.0'
1010
gem 'mail', '~> 2.6.3'
1111
gem 'puma', '~> 2.16.0'
@@ -14,3 +14,4 @@ gem 'rack_csrf', '~> 2.5.0'
1414
gem 'rack-flash3', '~> 1.0.5'
1515
gem 'newrelic-redis', '~> 2.0.0'
1616
gem 'sinatra-contrib', '~> 1.4.2'
17+
gem 'dogstatsd-ruby', '~> 2.2.0'

Gemfile.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ GEM
77
connection_pool (2.2.0)
88
descendants_tracker (0.0.4)
99
thread_safe (~> 0.3, >= 0.3.1)
10+
dogstatsd-ruby (2.2.0)
1011
faraday (0.9.2)
1112
multipart-post (>= 1.2, < 3)
1213
github_api (0.13.1)
@@ -20,7 +21,7 @@ GEM
2021
tilt
2122
hashie (3.4.3)
2223
hiredis (0.6.1)
23-
json (1.8.3)
24+
json (2.0.3)
2425
jwt (1.5.2)
2526
mail (2.6.3)
2627
mime-types (>= 1.16, < 3)
@@ -71,10 +72,11 @@ PLATFORMS
7172
ruby
7273

7374
DEPENDENCIES
75+
dogstatsd-ruby (~> 2.2.0)
7476
github_api (~> 0.13.0)
7577
haml (~> 4.0.6)
7678
hiredis (~> 0.6.0)
77-
json (~> 1.8.1)
79+
json (~> 2.0)
7880
mail (~> 2.6.3)
7981
newrelic-redis (~> 2.0.0)
8082
newrelic_rpm (~> 3.14.2)
@@ -87,4 +89,4 @@ DEPENDENCIES
8789
sinatra-contrib (~> 1.4.2)
8890

8991
BUNDLED WITH
90-
1.11.2
92+
1.12.5

app.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'haml'
44
require 'json'
55
require 'github_api'
6-
require 'pp'
6+
require 'datadog/statsd'
77

88
class GitNotifier < Sinatra::Base
99

@@ -22,6 +22,8 @@ class GitNotifier < Sinatra::Base
2222
fail "Configuration file " + config_file + " missing!" unless File.exist?(config_file)
2323
config = YAML.load_file(config_file)
2424

25+
statsd = Datadog::Statsd.new(config['statsd']['host'], config['statsd']['port'])
26+
2527
redis_conn = proc {
2628
Redis.new(
2729
:driver => :hiredis,
@@ -37,6 +39,7 @@ class GitNotifier < Sinatra::Base
3739
end
3840

3941
set :CONFIG, config
42+
set :STATSD, statsd
4043

4144
use Rack::Session::Cookie, :expire_after => 2592000, :secret => config['secret'] # 30 days
4245

@@ -231,6 +234,7 @@ class GitNotifier < Sinatra::Base
231234
'class' => SendEmail,
232235
'args' => [email, 'Confirm your Git Notifier email address!', 'html', 'confirm', {:confirm_link => link, :username => user['login']}]
233236
)
237+
settigs.STATSD.increment('ghntfr.business.signup')
234238

235239
flash.now[:success] = "We have sent an email to #{email}, please open it and click on the link inside to activate your account."
236240
end

config.yml.example

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ redis:
99
db: APP_CONFIG_REDIS_DB # 0
1010
namespace: APP_CONFIG_REDIS_NAMESPACE # ghntfr
1111

12+
statsd:
13+
host: APP_CONFIG_STATSD_HOST # localhost
14+
port: APP_CONFIG_STATSD_PORT # 8125
15+
1216
mail:
1317
enabled: APP_CONFIG_MAIL_ENABLE # true
1418
method: APP_CONFIG_MAIL_METHOD # smtp

config/docker.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ APP_CONFIG_REDIS_HOST=redis
77
APP_CONFIG_REDIS_PORT=6379
88
APP_CONFIG_REDIS_DB=1
99
APP_CONFIG_REDIS_NAMESPACE=ghntfr
10+
APP_CONFIG_STATSD_HOST=localhost
11+
APP_CONFIG_STATSD_PORT=8125
1012
APP_CONFIG_DOMAIN=gitnotifier.local
1113
APP_CONFIG_SECRET=somesecret
1214
APP_CONFIG_MAIL_ENABLE=true

scripts/job_enqueuer.rb

+6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
require 'redis'
55
require_relative '../workers/notifications_checker'
66
require_relative '../workers/email_builder'
7+
require 'datadog/statsd'
78
require 'newrelic_rpm' # it should be the last entry in the require list
89

910
config_file = File.dirname(__FILE__) + '/../config.yml'
1011
fail "Configuration file " + config_file + " missing!" unless File.exist?(config_file)
1112
CONFIG = YAML.load_file(config_file)
1213

14+
statsd = Datadog::Statsd.new(CONFIG['statsd']['host'], CONFIG['statsd']['port'])
15+
statsd.increment('ghntfr.scripts.job_enqueuer.start')
16+
1317
users_keys = nil
1418

1519
redis_conn = proc {
@@ -97,3 +101,5 @@
97101
Sidekiq::Client.push_bulk('queue' => 'email_builder', 'class' => EmailBuilder, 'args' => jobs_args)
98102
end
99103
end
104+
105+
statsd.increment('ghntfr.scripts.job_enqueuer.finish')

workers/email_builder.rb

+3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
class EmailBuilder
77
include Sidekiq::Worker
88
sidekiq_options :queue => :email_builder
9+
STATSD = Datadog::Statsd.new() unless defined? STATSD
910
def perform(events_list_key)
11+
STATSD.increment('ghntfr.workers.email_builder.start')
1012

1113
events = nil
1214
user = nil
@@ -96,6 +98,7 @@ def perform(events_list_key)
9698
conn.hset("#{CONFIG['redis']['namespace']}:users:" + events_list_key.split(':').last, :last_email_queued_on, Time.now.to_i)
9799
end
98100

101+
STATSD.increment('ghntfr.workers.email_builder.finish')
99102
end
100103

101104
def inject_day(events)

workers/init.rb

+4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# encoding: utf-8
22

3+
require 'datadog/statsd'
4+
35
GC::Profiler.enable
46

57
config_file = File.dirname(__FILE__) + '/../config.yml'
68
fail "Configuration file " + config_file + " missing!" unless File.exist?(config_file)
79
CONFIG = YAML.load_file(config_file)
810

11+
STATSD = Datadog::Statsd.new(CONFIG['statsd']['host'], CONFIG['statsd']['port'])
12+
913
redis_conn = proc {
1014
Redis.new(
1115
:driver => :hiredis,

workers/notifications_checker.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
require 'pp'
33
require 'json'
44
require 'net/http'
5+
require 'datadog/statsd'
56

67
class NotificationsChecker
78
include Sidekiq::Worker
89
sidekiq_options :queue => :notifications_checker, :retry => false, :dead => false
910
@first_time = nil
1011
@new_events = nil
12+
STATSD = Datadog::Statsd.new() unless defined? STATSD
1113
def perform(user_key, first_time = false)
14+
STATSD.increment('ghntfr.workers.notifications_checker.start')
1215
@new_events = []
1316
puts 'Started processing ' + user_key
1417
@first_time = first_time
@@ -137,7 +140,7 @@ def perform(user_key, first_time = false)
137140
end
138141
enqueue_email_builder(user) unless @first_time
139142
end
140-
143+
STATSD.increment('ghntfr.workers.notifications_checker.finish')
141144
end
142145

143146
def on_new_event(type, entity)

workers/send_email.rb

+4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# This is merely a workaround since
1616
# it should fixed by not using the `autoload`
1717
require "mail/parsers/content_type_parser"
18+
require 'datadog/statsd'
1819

1920
class SendEmail
2021
include Sidekiq::Worker
2122
sidekiq_options :queue => :send_email
23+
STATSD = Datadog::Statsd.new() unless defined? STATSD
2224
def perform(to, subject, content_type = 'text', template = nil, locals = {}, delete_key = nil, lock_key = nil, lock_id = nil, user_id = nil)
25+
STATSD.increment('ghntfr.workers.send_email.start')
2326

2427
raise "Missing template!" unless template
2528

@@ -74,6 +77,7 @@ def perform(to, subject, content_type = 'text', template = nil, locals = {}, del
7477
conn.zadd(lock_key, Time.now.to_i, JSON.generate(lock_id)) if lock_id
7578
end
7679
end
80+
STATSD.increment('ghntfr.workers.send_email.finish')
7781
end
7882

7983
def strip_html(string)

0 commit comments

Comments
 (0)