From c21dfe3cc75cf7d75882cc855761e1ef6f2681ce Mon Sep 17 00:00:00 2001 From: Marc-Andre Giroux Date: Tue, 5 Feb 2019 16:01:49 -0500 Subject: [PATCH 1/2] Add `distribution` method --- lib/github/statsd.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/github/statsd.rb b/lib/github/statsd.rb index 56730e8..fe7430b 100644 --- a/lib/github/statsd.rb +++ b/lib/github/statsd.rb @@ -91,6 +91,7 @@ def namespace=(namespace) TIMING_TYPE = "ms".freeze GAUGE_TYPE = "g".freeze HISTOGRAM_TYPE = "h".freeze + DISTRIBUTION_TYPE = "d".freeze def initialize(client_class = nil) @shards = [] @@ -187,6 +188,11 @@ def time(stat, sample_rate=1) # statsd server then uses the sample_rate to correctly track the average # for the stat. def histogram(stat, value, sample_rate=1); send stat, value, HISTOGRAM_TYPE, sample_rate end + + # A modified gauge that submits a distribution of values over a sample period. + # Arithmetic and statistical calculations (percetiles, average, etc.) on the data set + # are peformed server side rather than client side like a histogram. + def distribution(stat, value, sample_rate=1); send stat, value, DISTRIBUTION_TYPE, sample_rate end private def sampled(sample_rate) From ec47a3e07a8ddf77d9c59489dda66096cd5f561b Mon Sep 17 00:00:00 2001 From: Marc-Andre Giroux Date: Tue, 5 Feb 2019 16:09:30 -0500 Subject: [PATCH 2/2] add test --- spec/statsd_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index 14d0b21..30bbc9e 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -68,6 +68,13 @@ class << @statsd end end + describe "#distribution" do + it "should format the message according to the statsd spec" do + @statsd.distribution('foobar', 500) + @statsd.shards.first.recv.must_equal ["foobar:500|d"] + end + end + describe "#time" do it "should format the message according to the statsd spec" do @statsd.time('foobar') { sleep(0.001); 'test' }