Skip to content

Commit 0861c8a

Browse files
authored
Merge pull request #53 from buildkite/add-high-resolution-storage-support
Add high resolution storage support
2 parents ea844f8 + 5224c53 commit 0861c8a

File tree

2 files changed

+94
-3
lines changed

2 files changed

+94
-3
lines changed

lib/sidekiq/cloudwatchmetrics.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def initialize(config: default_config, client: Aws::CloudWatch::Client.new, name
6060
@config = config
6161

6262
@client = client
63-
@interval = interval
63+
@interval_s = interval
6464
@namespace = namespace
6565
@process_metrics = process_metrics
6666
@additional_dimensions = additional_dimensions.map { |k, v| {name: k.to_s, value: v.to_s} }
@@ -80,7 +80,7 @@ def running?
8080
def run
8181
logger.info { "Started Sidekiq CloudWatch Metrics Publisher" }
8282

83-
# Publish stats every @interval seconds, sleeping as required between runs
83+
# Publish stats every @interval_s seconds, sleeping as required between runs
8484
now = Time.now.to_f
8585
tick = now
8686
until @stop
@@ -93,7 +93,7 @@ def run
9393
end
9494

9595
now = Time.now.to_f
96-
tick = [tick + @interval, now].max
96+
tick = [tick + @interval_s, now].max
9797
sleep(tick - now) if tick > now
9898
end
9999

@@ -258,6 +258,9 @@ def publish
258258

259259
# We can only put 20 metrics at a time
260260
metrics.each_slice(20) do |some_metrics|
261+
if @interval_s < 60
262+
metrics.each { |metric| metric.merge!(storage_resolution: 1) }
263+
end
261264
@client.put_metric_data(
262265
namespace: @namespace,
263266
metric_data: some_metrics,

spec/sidekiq/cloudwatchmetrics_spec.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,94 @@
262262
end
263263
end
264264

265+
context "with a custom interval of less than 60" do
266+
subject(:publisher) { Sidekiq::CloudWatchMetrics::Publisher.new(client: client, interval: 30) }
267+
268+
it "passes sets a storage resolution of 1" do
269+
Timecop.freeze(now = Time.now) do
270+
publisher.publish
271+
272+
expect(client).to have_received(:put_metric_data).with(
273+
namespace: "Sidekiq",
274+
metric_data: including(
275+
{
276+
metric_name: "ProcessedJobs",
277+
timestamp: now,
278+
value: 123,
279+
unit: "Count",
280+
storage_resolution: 1,
281+
},
282+
{
283+
metric_name: "FailedJobs",
284+
timestamp: now,
285+
value: 456,
286+
unit: "Count",
287+
storage_resolution: 1,
288+
},
289+
{
290+
metric_name: "QueueSize",
291+
dimensions: [{name: "QueueName", value: "bar"}],
292+
timestamp: now,
293+
value: 2,
294+
unit: "Count",
295+
storage_resolution: 1,
296+
},
297+
{
298+
metric_name: "QueueLatency",
299+
dimensions: [{name: "QueueName", value: "bar"}],
300+
timestamp: now,
301+
value: 1.23,
302+
unit: "Seconds",
303+
storage_resolution: 1,
304+
},
305+
)
306+
)
307+
end
308+
end
309+
end
310+
311+
context "with a custom interval of more than 60" do
312+
subject(:publisher) { Sidekiq::CloudWatchMetrics::Publisher.new(client: client, interval: 120) }
313+
314+
it "doesn't pass a storage resolution" do
315+
Timecop.freeze(now = Time.now) do
316+
publisher.publish
317+
318+
expect(client).to have_received(:put_metric_data).with(
319+
namespace: "Sidekiq",
320+
metric_data: including(
321+
{
322+
metric_name: "ProcessedJobs",
323+
timestamp: now,
324+
value: 123,
325+
unit: "Count",
326+
},
327+
{
328+
metric_name: "FailedJobs",
329+
timestamp: now,
330+
value: 456,
331+
unit: "Count",
332+
},
333+
{
334+
metric_name: "QueueSize",
335+
dimensions: [{name: "QueueName", value: "bar"}],
336+
timestamp: now,
337+
value: 2,
338+
unit: "Count",
339+
},
340+
{
341+
metric_name: "QueueLatency",
342+
dimensions: [{name: "QueueName", value: "bar"}],
343+
timestamp: now,
344+
value: 1.23,
345+
unit: "Seconds",
346+
},
347+
)
348+
)
349+
end
350+
end
351+
end
352+
265353
context "with lots of queues" do
266354
let(:queues) { 10.times.each_with_object({}) { |i, hash| hash["queue#{i}"] = double(size: 1, latency: 1.23) } }
267355

0 commit comments

Comments
 (0)