inst_statsd 3.1.0 → 3.2.0
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 +35 -0
- data/lib/inst_statsd/statsd.rb +1 -0
- data/lib/inst_statsd/version.rb +1 -1
- data/lib/inst_statsd.rb +1 -0
- data/spec/inst_statsd/distribution_spec.rb +63 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 705acd8e1a6b843e6f4e54ec0e1525f1165022547c22649d4b0c60c2c1fc83fa
|
4
|
+
data.tar.gz: 1d0daad7330f761a6ea4642bd52c85a0a4bf5a6856e7bd967750670a7f08832e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a23712f36838b2fd9afd2fe15430c9239e14b212aa6a05ed3358c81ff9799a2d11345dc1170915de903d6a73eed0a0dce05c183c75661693296ab5511b2cdb8
|
7
|
+
data.tar.gz: d5a2406ba15f33196527a9d24cb7d52d6eb5d0aea387f7a80d9382e389777e0c375473d50282af0841f9832adc8f27d8c89b3f07c249764de3170aa8b033303e
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InstStatsd
|
4
|
+
# Mix-in methods for supporting DataDog events
|
5
|
+
# See https://docs.datadoghq.com/metrics/types/?tab=distribution#metric-types
|
6
|
+
module Distribution
|
7
|
+
# Sends a distribution metric to DataDog if the instance and DataDog are configured.
|
8
|
+
#
|
9
|
+
# Distributions are aggregated globally and are appropriate when a metric sourced from
|
10
|
+
# multiple hosts need to be considered in a global statistical distribution.
|
11
|
+
#
|
12
|
+
# @param metric [String] The name of the metric to send.
|
13
|
+
# @param value [Numeric] The value of the metric.
|
14
|
+
# @param tags [Hash] Optional tags to associate with the metric. Defaults to an empty hash.
|
15
|
+
#
|
16
|
+
# @example Record an error occurrence:
|
17
|
+
# InstStatsd::Statsd.distribution('client.request.failed', 1, tags: { status: '500' })
|
18
|
+
def distribution(metric, value, tags: {})
|
19
|
+
return unless instance && data_dog?
|
20
|
+
|
21
|
+
instance.distribution(metric, value, { tags: tags.merge(dog_tags) }.compact)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Increments the specified distribution metric by 1.
|
25
|
+
#
|
26
|
+
# @param metric [String] The name of the metric to increment.
|
27
|
+
# @param tags [Hash] Optional tags to associate with the metric.
|
28
|
+
#
|
29
|
+
# @example Increment the error count:
|
30
|
+
# InstStatsd::Statsd.distributed_increment('client.request.failed', tags: { status: '500' })
|
31
|
+
def distributed_increment(metric, tags: {})
|
32
|
+
distribution(metric, 1, tags: tags)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/inst_statsd/statsd.rb
CHANGED
data/lib/inst_statsd/version.rb
CHANGED
data/lib/inst_statsd.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "datadog/statsd"
|
5
|
+
|
6
|
+
RSpec.describe InstStatsd::Distribution do
|
7
|
+
describe ".distribution" do
|
8
|
+
subject { InstStatsd::Statsd.distribution(metric, value, tags: tags) }
|
9
|
+
|
10
|
+
let(:instance) { instance_double(Datadog::Statsd) }
|
11
|
+
|
12
|
+
let(:metric) { "client.request.failed" }
|
13
|
+
let(:value) { 23 }
|
14
|
+
let(:tags) { { status: "500" } }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(InstStatsd::Statsd).to receive_messages(data_dog?: is_datadog, dog_tags: dog_tags, instance: instance)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when instance and data_dog? are configured" do
|
21
|
+
let(:dog_tags) { { environment: "production" } }
|
22
|
+
let(:is_datadog) { true }
|
23
|
+
|
24
|
+
it 'invokes "distribution" on the instance with metric, value, and tags' do
|
25
|
+
expect(instance).to receive(:distribution).with(
|
26
|
+
metric,
|
27
|
+
value,
|
28
|
+
{ tags: { status: "500", environment: "production" } }
|
29
|
+
)
|
30
|
+
|
31
|
+
subject
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when instance and data_dog? are not configured" do
|
36
|
+
let(:dog_tags) { {} }
|
37
|
+
let(:is_datadog) { false }
|
38
|
+
|
39
|
+
it "does nothing" do
|
40
|
+
expect(instance).not_to receive(:distribution)
|
41
|
+
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".distributed_increment" do
|
48
|
+
subject { InstStatsd::Statsd.distributed_increment(metric, tags: tags) }
|
49
|
+
|
50
|
+
let(:metric) { "client.request.failed" }
|
51
|
+
let(:tags) { { status: "500" } }
|
52
|
+
|
53
|
+
before do
|
54
|
+
allow(InstStatsd::Statsd).to receive_messages(distribution: nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'invokes "distribution" on InstStatsd::Statsd with metric, 1, and tags' do
|
58
|
+
expect(InstStatsd::Statsd).to receive(:distribution).with(metric, 1, tags: tags)
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
end
|
63
|
+
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.2.0
|
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: 2024-
|
12
|
+
date: 2024-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aroi
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/inst_statsd/block_tracking.rb
|
177
177
|
- lib/inst_statsd/counter.rb
|
178
178
|
- lib/inst_statsd/default_tracking.rb
|
179
|
+
- lib/inst_statsd/distribution.rb
|
179
180
|
- lib/inst_statsd/event.rb
|
180
181
|
- lib/inst_statsd/null_logger.rb
|
181
182
|
- lib/inst_statsd/request_logger.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- spec/inst_statsd/block_stat_spec.rb
|
188
189
|
- spec/inst_statsd/block_tracking_spec.rb
|
189
190
|
- spec/inst_statsd/counter_spec.rb
|
191
|
+
- spec/inst_statsd/distribution_spec.rb
|
190
192
|
- spec/inst_statsd/event_spec.rb
|
191
193
|
- spec/inst_statsd/inst_statsd_spec.rb
|
192
194
|
- spec/inst_statsd/null_logger_spec.rb
|