inst_statsd 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/inst_statsd/distribution.rb +38 -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 +76 -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: 70725525a856b43a9d37075d6bdf74fdeac3a7c3a306545bca25e41e3011ca9a
|
4
|
+
data.tar.gz: e7fcf1593bf7186c877be71fbd38f86c285fa852294ee08e00d90049076cb0b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '02963b466ff709d44a2e7ed69f8a060263d0a66b87cf856d1bf9a8f75814441dda10692fb7184096c36e7365865e94d2d322cc2a04863fe66183a21e97085e0e'
|
7
|
+
data.tar.gz: f24f390b747d2a86e81a45bde5e9160e86375dd565798da7e9bd037977b6be4cc71c4c29621fe3c87bade029c2884ee74b02382f2a100770563811edd3171ac8
|
@@ -0,0 +1,38 @@
|
|
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
|
+
# Non-Datadog clients don't support distribution metrics, so we use fall back to increment
|
33
|
+
return increment(metric, tags: tags) if instance && !data_dog?
|
34
|
+
|
35
|
+
distribution(metric, 1, tags: tags)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/inst_statsd/statsd.rb
CHANGED
data/lib/inst_statsd/version.rb
CHANGED
data/lib/inst_statsd.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "datadog/statsd"
|
5
|
+
|
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
|
+
|
13
|
+
describe ".distribution" do
|
14
|
+
subject { InstStatsd::Statsd.distribution(metric, value, tags: tags) }
|
15
|
+
|
16
|
+
let(:metric) { "client.request.failed" }
|
17
|
+
let(:value) { 23 }
|
18
|
+
let(:tags) { { status: "500" } }
|
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
|
+
let(:dog_tags) { { status: "401" } }
|
53
|
+
let(:is_datadog) { true }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(InstStatsd::Statsd).to receive_messages(distribution: nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'invokes "distribution" on InstStatsd::Statsd with metric, 1, and tags' do
|
60
|
+
expect(InstStatsd::Statsd).to receive(:distribution).with(metric, 1, tags: tags)
|
61
|
+
|
62
|
+
subject
|
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)
|
71
|
+
|
72
|
+
subject
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
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.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
|