inst_statsd 2.1.1 → 2.1.2

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: f7eba72a497efc7967daa2dd99d270703bb6e513d34aa2a2c90b88ac7fe15ee6
4
- data.tar.gz: ce9c3026304050075016db7fb959afdf2c574287b0e7ec6b0c2484db3e8429d7
3
+ metadata.gz: e4a37b143fb7348450535523a0a5f6d8f5b1817b26a71f65accd0f44f2b6c020
4
+ data.tar.gz: 4ec4d4b5b82305d3d6604fc4a1824b07ede89fb2da5d52f444f28dc4eb483f91
5
5
  SHA512:
6
- metadata.gz: 64aaa60431ec40f7cf7296778c96744438f76129ca7737683b5a5d8528d0b06d8e2a6a092e3dfefee13696fd0968dfa894016b3cdd947cf26f4134c090655413
7
- data.tar.gz: ac9f462c401b1162924c769c0189bf5676eb5eede8d668233468b27e375fae65c5e466110cd8a869d92edef2eef46701854edd29ef7474c1778f4a15b81b219a
6
+ metadata.gz: 0b5fd970e6f6424c4065bf6baaf64bcd77d1d5211f2f8c6a990377f2534f9272e28a293279a58f726e40c95df2918c61fbda43dc260a7db93f610d021b2d190c
7
+ data.tar.gz: 93448febe5f6cb62d05fad68978dbe597503b0724f65f3f48618a6ca74808860c19a5fc11d8d823d788b6fc870257517b770463c0b2ac7470fe398d6fc926960
@@ -42,12 +42,13 @@ module InstStatsd
42
42
  end
43
43
 
44
44
  def env_settings(env = ENV)
45
+ dog_tags = JSON.load(env['INST_DOG_TAGS']).to_h if env['INST_DOG_TAGS']
45
46
  config = {
46
47
  host: env.fetch('INST_STATSD_HOST', nil),
47
48
  port: env.fetch('INST_STATSD_PORT', nil),
48
49
  namespace: env.fetch('INST_STATSD_NAMESPACE', nil),
49
50
  append_hostname: env.fetch('INST_STATSD_APPEND_HOSTNAME', nil),
50
- dog_tags: env.fetch('INST_DOG_TAGS', nil)
51
+ dog_tags: dog_tags
51
52
  }
52
53
  config.delete_if { |_k, v| v.nil? }
53
54
  convert_bool(config, :append_hostname)
@@ -58,7 +58,10 @@ module InstStatsd
58
58
  tags = convert_tags(tags)
59
59
  tags << 'host:' unless self.append_hostname?
60
60
  short_stat ||= stat_name
61
- self.instance.#{method}(short_stat, *args, tags: tags)
61
+ opts = { tags: tags }
62
+ opts[:sample_rate] = args.pop if args.length == 2
63
+ args << opts
64
+ self.instance.#{method}(short_stat, *args)
62
65
  else
63
66
  self.instance.#{method}(stat_name, *args)
64
67
  end
@@ -108,8 +111,9 @@ module InstStatsd
108
111
  @data_dog = true
109
112
  host = statsd_settings[:host] || 'localhost'
110
113
  port = statsd_settings[:port] || 8125
114
+ require 'datadog/statsd'
111
115
  @statsd = ::Datadog::Statsd.new(host, port)
112
- @statsd.dog_tags = statsd_settings[:dog_tags] || {}
116
+ self.dog_tags.replace(statsd_settings[:dog_tags] || {})
113
117
  @append_hostname = !statsd_settings.key?(:append_hostname) || !!statsd_settings[:append_hostname]
114
118
  elsif statsd_settings && statsd_settings[:host]
115
119
  @statsd = ::Statsd.new(statsd_settings[:host])
@@ -121,10 +121,10 @@ describe InstStatsd do
121
121
 
122
122
  it 'builds settings hash with dog environment vars' do
123
123
  env = {
124
- 'INST_DOG_TAGS' => {app: 'canvas', env: 'prod'},
124
+ 'INST_DOG_TAGS' => '{"app": "canvas", "env": "prod"}',
125
125
  }
126
126
  expected = {
127
- dog_tags: {app: 'canvas', env: 'prod'},
127
+ dog_tags: {"app" => "canvas", "env" => "prod"},
128
128
  }
129
129
  expect(InstStatsd.env_settings(env)).to eq(expected)
130
130
  end
@@ -24,8 +24,11 @@ describe InstStatsd::Statsd do
24
24
  it 'sending tags should not break statsd' do
25
25
  default_tags = {app: 'canvas', env: 'prod'}
26
26
  short_stat = 'test2'
27
+ env = {
28
+ 'INST_DOG_TAGS' => '{"app": "canvas", "env": "prod"}',
29
+ }
30
+ InstStatsd.env_settings(env)
27
31
  allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
28
- allow(InstStatsd::Statsd).to receive(:dog_tags).and_return(default_tags)
29
32
  allow(InstStatsd::Statsd).to receive(:short_stat).and_return(short_stat)
30
33
  statsd = double
31
34
  allow(InstStatsd::Statsd).to receive(:instance).and_return(statsd)
@@ -53,7 +56,7 @@ describe InstStatsd::Statsd do
53
56
  expect(statsd).to receive(method).with(short_stat, 'test', tags: converted_tags)
54
57
  InstStatsd::Statsd.send(method, 'test.name', 'test', short_stat: short_stat)
55
58
  end
56
- expect(statsd).to receive('timing').with(short_stat, anything, anything, tags: converted_tags)
59
+ expect(statsd).to receive('timing').with(short_stat, anything, sample_rate: anything, tags: converted_tags)
57
60
  expect(InstStatsd::Statsd.time('test.name', short_stat: short_stat) {'test'}).to eq 'test'
58
61
  end
59
62
 
@@ -69,7 +72,7 @@ describe InstStatsd::Statsd do
69
72
  expect(statsd).to receive(method).with('test.name', 'test', tags: converted_tags)
70
73
  InstStatsd::Statsd.send(method, 'test.name', 'test')
71
74
  end
72
- expect(statsd).to receive('timing').with('test.name', anything, anything, tags: converted_tags)
75
+ expect(statsd).to receive('timing').with('test.name', anything, sample_rate: anything, tags: converted_tags)
73
76
  expect(InstStatsd::Statsd.time('test.name') {'test'}).to eq 'test'
74
77
  end
75
78
 
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: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Cloward