inst_statsd 3.2.0 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inst_statsd/distribution.rb +12 -2
- data/lib/inst_statsd/version.rb +1 -1
- data/spec/inst_statsd/distribution_spec.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7d5fbbb438dc387efee59fe23c96d65d8c6d15b68bf08e3bacfaf1f05c9ac0
|
4
|
+
data.tar.gz: 27f3a13b0e1fe8910a9330b88adac40545e397500dc6d901f8bbcad0014f4cdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09adfd59ec9e74f78a0af260d339f7db562a1e281e8b514650d5259a2f6ac85529cecb73b8b5a8e42f0d9f193c3aec8a1049de813280b5b8b2ceca12df261fad'
|
7
|
+
data.tar.gz: 697e4ef4dcd88dc71c7ff550433992dedf39b942bc21298cc45d623c55f223507370ceb6d8ed465cdc01e7a2c0d1719c5672dc338e1a73b777f8f8cf3c291bf2
|
@@ -18,6 +18,12 @@ module InstStatsd
|
|
18
18
|
def distribution(metric, value, tags: {})
|
19
19
|
return unless instance && data_dog?
|
20
20
|
|
21
|
+
metric = if append_hostname?
|
22
|
+
"#{metric}.#{hostname}"
|
23
|
+
else
|
24
|
+
metric.to_s
|
25
|
+
end
|
26
|
+
|
21
27
|
instance.distribution(metric, value, { tags: tags.merge(dog_tags) }.compact)
|
22
28
|
end
|
23
29
|
|
@@ -25,11 +31,15 @@ module InstStatsd
|
|
25
31
|
#
|
26
32
|
# @param metric [String] The name of the metric to increment.
|
27
33
|
# @param tags [Hash] Optional tags to associate with the metric.
|
34
|
+
# @param short_stat [String, nil] Stat name to use instead of `metric` if backed by DataDog.
|
28
35
|
#
|
29
36
|
# @example Increment the error count:
|
30
37
|
# InstStatsd::Statsd.distributed_increment('client.request.failed', tags: { status: '500' })
|
31
|
-
def distributed_increment(metric, tags: {})
|
32
|
-
distribution
|
38
|
+
def distributed_increment(metric, tags: {}, short_stat: nil)
|
39
|
+
# Non-Datadog clients don't support distribution metrics, so we use fall back to increment
|
40
|
+
return increment(metric, tags: tags, short_stat: short_stat) if instance && !data_dog?
|
41
|
+
|
42
|
+
distribution(short_stat || metric, 1, tags: tags)
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
data/lib/inst_statsd/version.rb
CHANGED
@@ -4,19 +4,19 @@ require "spec_helper"
|
|
4
4
|
require "datadog/statsd"
|
5
5
|
|
6
6
|
RSpec.describe InstStatsd::Distribution do
|
7
|
+
let(:instance) { instance_double(Datadog::Statsd) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(InstStatsd::Statsd).to receive_messages(data_dog?: is_datadog, dog_tags: dog_tags, instance: instance)
|
11
|
+
end
|
12
|
+
|
7
13
|
describe ".distribution" do
|
8
14
|
subject { InstStatsd::Statsd.distribution(metric, value, tags: tags) }
|
9
15
|
|
10
|
-
let(:instance) { instance_double(Datadog::Statsd) }
|
11
|
-
|
12
16
|
let(:metric) { "client.request.failed" }
|
13
17
|
let(:value) { 23 }
|
14
18
|
let(:tags) { { status: "500" } }
|
15
19
|
|
16
|
-
before do
|
17
|
-
allow(InstStatsd::Statsd).to receive_messages(data_dog?: is_datadog, dog_tags: dog_tags, instance: instance)
|
18
|
-
end
|
19
|
-
|
20
20
|
context "when instance and data_dog? are configured" do
|
21
21
|
let(:dog_tags) { { environment: "production" } }
|
22
22
|
let(:is_datadog) { true }
|
@@ -49,6 +49,8 @@ RSpec.describe InstStatsd::Distribution do
|
|
49
49
|
|
50
50
|
let(:metric) { "client.request.failed" }
|
51
51
|
let(:tags) { { status: "500" } }
|
52
|
+
let(:dog_tags) { { status: "401" } }
|
53
|
+
let(:is_datadog) { true }
|
52
54
|
|
53
55
|
before do
|
54
56
|
allow(InstStatsd::Statsd).to receive_messages(distribution: nil)
|
@@ -59,5 +61,16 @@ RSpec.describe InstStatsd::Distribution do
|
|
59
61
|
|
60
62
|
subject
|
61
63
|
end
|
64
|
+
|
65
|
+
context "when the configured instance is not a DataDog instance" do
|
66
|
+
let(:dog_tags) { {} }
|
67
|
+
let(:is_datadog) { false }
|
68
|
+
|
69
|
+
it 'invokes "increment" on InstStatsd::Statsd with metric and tags' do
|
70
|
+
expect(InstStatsd::Statsd).to receive(:increment).with(metric, tags: tags, short_stat: nil)
|
71
|
+
|
72
|
+
subject
|
73
|
+
end
|
74
|
+
end
|
62
75
|
end
|
63
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst_statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Cloward
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aroi
|