inst_statsd 3.3.2 → 3.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b97f7ba19c16e12f36248b86629b16fb1bc2216ba0da3c3ff1da012c08582ee2
4
- data.tar.gz: d7f43c64a477c5e6bf733ede3185b54a692e26440e1ba340886ac6c524f9da5d
3
+ metadata.gz: a043204eb3317894fc4af36b78cff6b0880ac5e1338d9c0959c6628841c87185
4
+ data.tar.gz: f8d212ea7b2a3b70a96fd72e6c280a3d1a8b309148ce0517efee208f65e10276
5
5
  SHA512:
6
- metadata.gz: 825783ba4ef42ff8abc7b97d3a8a387be9c93c30e9b746482c119a905c74de57341ab38d32723bb37e2d28d5b5cbc33bde84e531eaa04067138d96b7b8f1b492
7
- data.tar.gz: 45a3cfbc0e101a1dfdc758155290dbfca30f1c89832b73a6e376010ba8aaecdea55ebca764c023adfbdd4150bf120ca0f2e82eda6ba631d245cead49a25b9850
6
+ metadata.gz: 4c9cbb244b6c2c4d26132a4099b91de59986c66897f832a8ed0c4bcddca1566cc0f842527d0126f4f36bf35cb23408a77f4b4da60e61f6f3f702a35c3a94ced7
7
+ data.tar.gz: afcd0952fa43d151e8ee38a5452aaa588fd07b45d5ff5dd3cdd92ae3c6d027c2501623875f7f3cef168ddcbab9ecac510f00c3df0dbb99033e0bbc53a97d3848
@@ -18,12 +18,8 @@ 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
- tags = tags.merge(dog_tags) if tags.is_a?(Hash)
21
+ metric = stat_name_for(metric)
22
+ tags = prepare_datadog_tags(tags) if data_dog?
27
23
 
28
24
  instance.distribution(metric, value, { tags: tags })
29
25
  end
@@ -37,6 +33,9 @@ module InstStatsd
37
33
  # @example Increment the error count:
38
34
  # InstStatsd::Statsd.distributed_increment('client.request.failed', tags: { status: '500' })
39
35
  def distributed_increment(metric, tags: {}, short_stat: nil)
36
+ metric = stat_name_for(metric)
37
+ tags = prepare_datadog_tags(tags) if data_dog?
38
+
40
39
  # Non-Datadog clients don't support distribution metrics, so we use fall back to increment
41
40
  return increment(metric, tags: tags, short_stat: short_stat) if instance && !data_dog?
42
41
 
@@ -55,17 +55,10 @@ module InstStatsd
55
55
  return # return
56
56
  end # end
57
57
  #
58
- if self.append_hostname? # if self.append_hostname?
59
- stat_name = "\#{stat}.\#{hostname}" # stat_name = "\#{stat}.\#{hostname}"
60
- else # else
61
- stat_name = stat.to_s # stat_name = stat.to_s
62
- end # end
58
+ stat_name = stat_name_for(stat) # stat_name = stat_name_for(stat)
63
59
  #
64
60
  if data_dog? # if data_dog?
65
- tags = tags ? tags.dup : {} # tags ||= {}
66
- tags.merge!(dog_tags) if tags.is_a? Hash # tags.merge!(dog_tags) if tags.is_a? Hash
67
- tags = convert_tags(tags) # tags = convert_tags(tags)
68
- tags << 'host:' unless self.append_hostname? # tags << 'host:' unless self.append_hostname?
61
+ tags = prepare_datadog_tags(tags) # tags = prepare_datadog_tags(tags)
69
62
  short_stat ||= stat_name # short_stat ||= stat_name
70
63
  opts = { tags: tags } # opts = { tags: tags }
71
64
  opts[:sample_rate] = args.pop if args.length == 2 # opts[:sample_rate] = args.pop if args.length == 2
@@ -81,6 +74,21 @@ module InstStatsd
81
74
  RUBY
82
75
  end
83
76
 
77
+ def self.stat_name_for(metric)
78
+ return "#{metric}.#{hostname}" if append_hostname?
79
+
80
+ metric.to_s
81
+ end
82
+
83
+ def self.prepare_datadog_tags(tags)
84
+ tags = tags ? tags.dup : {}
85
+ tags.merge!(dog_tags) if tags.is_a? Hash
86
+ tags = convert_tags(tags)
87
+ tags << "host:" unless append_hostname?
88
+
89
+ tags
90
+ end
91
+
84
92
  def self.convert_tags(tags)
85
93
  new_tags = []
86
94
  return tags unless tags.is_a? Hash
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstStatsd
4
- VERSION = "3.3.2"
4
+ VERSION = "3.4.0"
5
5
  end
@@ -5,9 +5,15 @@ require "datadog/statsd"
5
5
 
6
6
  RSpec.describe InstStatsd::Distribution do
7
7
  let(:instance) { instance_double(Datadog::Statsd) }
8
+ let(:append_hostname) { false }
8
9
 
9
10
  before do
10
- allow(InstStatsd::Statsd).to receive_messages(data_dog?: is_datadog, dog_tags: dog_tags, instance: instance)
11
+ allow(InstStatsd::Statsd).to receive_messages(
12
+ data_dog?: is_datadog,
13
+ dog_tags: dog_tags,
14
+ instance: instance,
15
+ append_hostname?: append_hostname
16
+ )
11
17
  end
12
18
 
13
19
  describe ".distribution" do
@@ -25,7 +31,7 @@ RSpec.describe InstStatsd::Distribution do
25
31
  expect(instance).to receive(:distribution).with(
26
32
  metric,
27
33
  value,
28
- { tags: { status: "500", environment: "production" } }
34
+ { tags: ["status:500", "environment:production", "host:"] }
29
35
  )
30
36
 
31
37
  subject
@@ -35,10 +41,38 @@ RSpec.describe InstStatsd::Distribution do
35
41
  expect(instance).to receive(:distribution).with(
36
42
  metric,
37
43
  value,
38
- { tags: ["status:500"] }
44
+ { tags: ["status:500", "host:"] }
39
45
  )
40
46
  InstStatsd::Statsd.distribution(metric, value, tags: ["status:500"])
41
47
  end
48
+
49
+ context "when the tags are nil" do
50
+ let(:tags) { nil }
51
+
52
+ it "handles nil tags" do
53
+ expect(instance).to receive(:distribution).with(
54
+ metric,
55
+ value,
56
+ { tags: ["environment:production", "host:"] }
57
+ )
58
+
59
+ subject
60
+ end
61
+ end
62
+
63
+ context "when append_hostname? is true" do
64
+ let(:append_hostname) { true }
65
+
66
+ it "appends the hostname to the metric and excludes a host tag" do
67
+ expect(instance).to receive(:distribution).with(
68
+ "#{metric}.#{Socket.gethostname}",
69
+ value,
70
+ { tags: ["status:500", "environment:production"] }
71
+ )
72
+
73
+ subject
74
+ end
75
+ end
42
76
  end
43
77
 
44
78
  context "when instance and data_dog? are not configured" do
@@ -66,11 +100,25 @@ RSpec.describe InstStatsd::Distribution do
66
100
  end
67
101
 
68
102
  it 'invokes "distribution" on InstStatsd::Statsd with metric, 1, and tags' do
69
- expect(InstStatsd::Statsd).to receive(:distribution).with(metric, 1, tags: tags)
103
+ expect(InstStatsd::Statsd).to receive(:distribution).with(metric, 1, tags: ["status:401", "host:"])
70
104
 
71
105
  subject
72
106
  end
73
107
 
108
+ context "when append_hostname? is true" do
109
+ let(:append_hostname) { true }
110
+
111
+ it "appends the hostname to the metric and excludes a host tag" do
112
+ expect(InstStatsd::Statsd).to receive(:distribution).with(
113
+ "#{metric}.#{Socket.gethostname}",
114
+ 1,
115
+ { tags: ["status:401"] }
116
+ )
117
+
118
+ subject
119
+ end
120
+ end
121
+
74
122
  context "when the configured instance is not a DataDog instance" do
75
123
  let(:dog_tags) { {} }
76
124
  let(:is_datadog) { false }
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.3.2
4
+ version: 3.4.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: 2025-02-03 00:00:00.000000000 Z
12
+ date: 2025-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aroi