qubole-statsd-instrument 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e129fa9743846586c8eb56fa80a81505498e04c8
|
4
|
+
data.tar.gz: f26f51980c279bd2445bd01759f42a51e255e7fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1fe84cd8f8cad7c43719a471417429a5300906212d1df933f740460871eb658432d683d49ecd58154f29065a5881d5d9189ea35d0cf5bd5e56df33b83682692
|
7
|
+
data.tar.gz: 76f425d63f063edf641a00f6f6ddf2eaae65df97e7efcecac88c4640ca66361d365d1de2b4bb0d5570c49f6ca647239f832f5d0e13c1576e6230ee439991c5b3
|
@@ -8,12 +8,13 @@ module StatsD::Instrument::Backends
|
|
8
8
|
include MonitorMixin
|
9
9
|
|
10
10
|
attr_reader :host, :port
|
11
|
-
attr_accessor :implementation
|
11
|
+
attr_accessor :implementation, :default_metric_tags
|
12
12
|
|
13
|
-
def initialize(server = nil, implementation = nil)
|
13
|
+
def initialize(server = nil, implementation = nil, default_metric_tags = {})
|
14
14
|
super()
|
15
15
|
self.server = server || "localhost:8125"
|
16
16
|
self.implementation = (implementation || DEFAULT_IMPLEMENTATION).to_sym
|
17
|
+
self.default_metric_tags = default_metric_tags
|
17
18
|
end
|
18
19
|
|
19
20
|
def collect_metric(metric)
|
@@ -64,13 +65,30 @@ module StatsD::Instrument::Backends
|
|
64
65
|
def generate_packet(metric)
|
65
66
|
command = "#{metric.name}:#{metric.value}|#{metric.type}"
|
66
67
|
command << "|@#{metric.sample_rate}" if metric.sample_rate < 1 || (implementation == :statsite && metric.sample_rate > 1)
|
68
|
+
|
69
|
+
metric_tags_map = self.default_metric_tags
|
67
70
|
if metric.tags
|
71
|
+
metric.tags.each do |tag|
|
72
|
+
key, value = tag.split(":") rescue nil
|
73
|
+
metric_tags_map[key] = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
metric_tags = []
|
78
|
+
metric_tags_map.each do |k ,v|
|
79
|
+
if v.nil?
|
80
|
+
metric_tags << "#{k}"
|
81
|
+
else
|
82
|
+
metric_tags << "#{k}:#{v}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if metric_tags.size > 0
|
68
87
|
if tags_supported?
|
69
88
|
if implementation == :datadog
|
70
|
-
command << "|##{
|
89
|
+
command << "|##{metric_tags.join(',')}"
|
71
90
|
elsif implementation == :collectd
|
72
|
-
metric_tags = "#{
|
73
|
-
metric_tags = metric_tags.prepend("[") << "]"
|
91
|
+
metric_tags = "[#{metric_tags.join(',')}]"
|
74
92
|
command.prepend(metric_tags.gsub(":", "="))
|
75
93
|
end
|
76
94
|
else
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UDPBackendTestWithDefaultTags < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@backend = StatsD::Instrument::Backends::UDPBackend.new("localhost:8125", :collectd, {pod_ip: "10.0.0.42"})
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def test_constructor_must_create_default_tags
|
10
|
+
default_tags = @backend.instance_eval { self.default_metric_tags }
|
11
|
+
|
12
|
+
assert_equal default_tags.class, Hash
|
13
|
+
assert_includes default_tags.keys, :pod_ip
|
14
|
+
assert_equal default_tags[:pod_ip], "10.0.0.42"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_metric_with_no_tags_must_have_default_tags
|
18
|
+
metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5)
|
19
|
+
command = @backend.generate_packet(metric)
|
20
|
+
assert command.include?("pod_ip=10.0.0.42")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_metric_with_other_tags_must_have_default_tags
|
24
|
+
metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5, tags: ["conduit:0.0"])
|
25
|
+
command = @backend.generate_packet(metric)
|
26
|
+
assert command.include?("pod_ip=10.0.0.42")
|
27
|
+
assert command.include?("conduit=0.0")
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_metric_with_same_tag_must_override_default_tags
|
32
|
+
metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5, tags: ["pod_ip:10.0.0.43", "conduit=0.0"])
|
33
|
+
command = @backend.generate_packet(metric)
|
34
|
+
assert command.include?("conduit=0.0")
|
35
|
+
assert command.include?("pod_ip=10.0.0.43")
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qubole-statsd-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Storimer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- test/statsd_test.rb
|
143
143
|
- test/test_helper.rb
|
144
144
|
- test/udp_backend_test.rb
|
145
|
+
- test/udp_backend_with_default_tags.rb
|
145
146
|
homepage: https://github.com/Shopify/statsd-instrument
|
146
147
|
licenses:
|
147
148
|
- MIT
|
@@ -180,3 +181,4 @@ test_files:
|
|
180
181
|
- test/statsd_test.rb
|
181
182
|
- test/test_helper.rb
|
182
183
|
- test/udp_backend_test.rb
|
184
|
+
- test/udp_backend_with_default_tags.rb
|