Skip to content

Commit

Permalink
statsd instrumentation for animated gif shrinker
Browse files Browse the repository at this point in the history
  • Loading branch information
mmb committed Feb 3, 2016
1 parent 118f6e9 commit fec9b01
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/initializers/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
GendImageProcessJob.statsd_count_success(:perform, 'job.gend_image.process')
GendImageProcessJob.statsd_measure(:perform, 'job.gend_image.process.time')

MemeCaptainWeb::AnimatedGifShrinker.extend(StatsD::Instrument)
MemeCaptainWeb::AnimatedGifShrinker.statsd_count_success(
:shrink, 'animated_gif_shrinker.shrink')
MemeCaptainWeb::AnimatedGifShrinker.statsd_measure(
:shrink, 'animated_gif_shrinker.shrink.runtime')

SrcImageNameJob.extend(StatsD::Instrument)
SrcImageNameJob.statsd_measure(:perform, 'job.src_image.name.time')

Expand Down
42 changes: 42 additions & 0 deletions spec/classes/meme_captain_web/animated_gif_shrinker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rails_helper'

describe MemeCaptainWeb::AnimatedGifShrinker do
include StatsD::Instrument::Matchers

subject(:animated_gif_shrinker) do
MemeCaptainWeb::AnimatedGifShrinker.new(coalescer, trimmer)
end
Expand Down Expand Up @@ -55,6 +57,26 @@
animated_gif_shrinker.shrink(image_data, max_size) {}
).to be_nil
end

it 'increments the statsd success counter' do
allow(coalescer).to receive(:coalesce).with('GIFdata').and_return(
'GIFdatacoalesced')
allow(trimmer).to receive(:trim).with('GIFdatacoalesced').and_return(
'x')
expect do
animated_gif_shrinker.shrink(image_data, max_size) {}
end.to trigger_statsd_increment('animated_gif_shrinker.shrink.success')
end

it 'sends a statsd time measurement' do
allow(coalescer).to receive(:coalesce).with('GIFdata').and_return(
'GIFdatacoalesced')
allow(trimmer).to receive(:trim).with('GIFdatacoalesced').and_return(
'x')
expect do
animated_gif_shrinker.shrink(image_data, max_size) {}
end.to trigger_statsd_measure('animated_gif_shrinker.shrink.runtime')
end
end

context 'when multiple passes are required' do
Expand Down Expand Up @@ -83,5 +105,25 @@
). to be_nil
end
end

context 'when shrinking raises an exception' do
let(:image_data) { 'GIFdata' }
let(:max_size) { 4 }

before do
expect(coalescer).to receive(:coalesce).with('GIFdata').and_raise(
'error')
end

it 'increments the statsd failure counter' do
expect do
begin
animated_gif_shrinker.shrink(image_data, max_size) {}
rescue StandardError => e
e
end
end.to trigger_statsd_increment('animated_gif_shrinker.shrink.failure')
end
end
end
end

0 comments on commit fec9b01

Please sign in to comment.