Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 7e71d7e

Browse files
bosawtTrevor Bosaw
andauthored
[56520] Monkeypatching StatsD::Instrument functions to replace StatsD key strings, dots with underscores (#12392)
Co-authored-by: Trevor Bosaw <trevor.bosaw@oddball.io>
1 parent 74f0f17 commit 7e71d7e

5 files changed

Lines changed: 225 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'statsd-instrument' unless Object.const_defined?(:StatsD)
4+
5+
# This monkeypatch is used to fix StatsD metrics that were breaking following the vets-api EKS transition.
6+
# Prior to the transition, there was a service that substituted dots in StatsD keys with underscores.
7+
# After the EKS transition, StatsD keys were being reported with dots, breaking existing metrics expecting underscores.
8+
# For example, this monkeypatch will take the key: 'api.service.total', and transform it to: 'api_service_total'
9+
module StatsD
10+
module Instrument
11+
module Underscore
12+
def increment(key, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
13+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
14+
end
15+
16+
def gauge(key, value, sample_rate: nil, tags: nil, no_prefix: false)
17+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
18+
end
19+
20+
def histogram(key, value, sample_rate: nil, tags: nil, no_prefix: false)
21+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
22+
end
23+
24+
def set(key, value, sample_rate: nil, tags: nil, no_prefix: false)
25+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
26+
end
27+
28+
def measure(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
29+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
30+
end
31+
32+
def distribution(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
33+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
34+
end
35+
36+
private
37+
38+
def substitute_dots_for_underscores(key)
39+
key.gsub('.', '_')
40+
end
41+
end
42+
end
43+
end
44+
45+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Underscore) unless Rails.env.test?
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'statsd-instrument' unless Object.const_defined?(:StatsD)
4+
5+
# This monkeypatch is used to fix StatsD metrics that were breaking following the vets-api EKS transition.
6+
# Prior to the transition, there was a service that substituted dots in StatsD keys with underscores.
7+
# After the EKS transition, StatsD keys were being reported with dots, breaking existing metrics expecting underscores.
8+
# For example, this monkeypatch will take the key: 'api.service.total', and transform it to: 'api_service_total'
9+
module StatsD
10+
module Instrument
11+
module Underscore
12+
def increment(key, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
13+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
14+
end
15+
16+
def gauge(key, value, sample_rate: nil, tags: nil, no_prefix: false)
17+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
18+
end
19+
20+
def histogram(key, value, sample_rate: nil, tags: nil, no_prefix: false)
21+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
22+
end
23+
24+
def set(key, value, sample_rate: nil, tags: nil, no_prefix: false)
25+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
26+
end
27+
28+
def measure(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
29+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
30+
end
31+
32+
def distribution(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
33+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
34+
end
35+
36+
private
37+
38+
def substitute_dots_for_underscores(key)
39+
key.gsub('.', '_')
40+
end
41+
end
42+
end
43+
end
44+
45+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Underscore) unless Rails.env.test?
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'statsd-instrument' unless Object.const_defined?(:StatsD)
4+
5+
# This monkeypatch is used to fix StatsD metrics that were breaking following the vets-api EKS transition.
6+
# Prior to the transition, there was a service that substituted dots in StatsD keys with underscores.
7+
# After the EKS transition, StatsD keys were being reported with dots, breaking existing metrics expecting underscores.
8+
# For example, this monkeypatch will take the key: 'api.service.total', and transform it to: 'api_service_total'
9+
module StatsD
10+
module Instrument
11+
module Underscore
12+
def increment(key, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
13+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
14+
end
15+
16+
def gauge(key, value, sample_rate: nil, tags: nil, no_prefix: false)
17+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
18+
end
19+
20+
def histogram(key, value, sample_rate: nil, tags: nil, no_prefix: false)
21+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
22+
end
23+
24+
def set(key, value, sample_rate: nil, tags: nil, no_prefix: false)
25+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
26+
end
27+
28+
def measure(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
29+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
30+
end
31+
32+
def distribution(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
33+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
34+
end
35+
36+
private
37+
38+
def substitute_dots_for_underscores(key)
39+
key.gsub('.', '_')
40+
end
41+
end
42+
end
43+
end
44+
45+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Underscore) unless Rails.env.test?
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'statsd-instrument' unless Object.const_defined?(:StatsD)
4+
5+
# This monkeypatch is used to fix StatsD metrics that were breaking following the vets-api EKS transition.
6+
# Prior to the transition, there was a service that substituted dots in StatsD keys with underscores.
7+
# After the EKS transition, StatsD keys were being reported with dots, breaking existing metrics expecting underscores.
8+
# For example, this monkeypatch will take the key: 'api.service.total', and transform it to: 'api_service_total'
9+
module StatsD
10+
module Instrument
11+
module Underscore
12+
def increment(key, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
13+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
14+
end
15+
16+
def gauge(key, value, sample_rate: nil, tags: nil, no_prefix: false)
17+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
18+
end
19+
20+
def histogram(key, value, sample_rate: nil, tags: nil, no_prefix: false)
21+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
22+
end
23+
24+
def set(key, value, sample_rate: nil, tags: nil, no_prefix: false)
25+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
26+
end
27+
28+
def measure(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
29+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
30+
end
31+
32+
def distribution(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
33+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
34+
end
35+
36+
private
37+
38+
def substitute_dots_for_underscores(key)
39+
key.gsub('.', '_')
40+
end
41+
end
42+
end
43+
end
44+
45+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Underscore) unless Rails.env.test?
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'statsd-instrument' unless Object.const_defined?(:StatsD)
4+
5+
# This monkeypatch is used to fix StatsD metrics that were breaking following the vets-api EKS transition.
6+
# Prior to the transition, there was a service that substituted dots in StatsD keys with underscores.
7+
# After the EKS transition, StatsD keys were being reported with dots, breaking existing metrics expecting underscores.
8+
# For example, this monkeypatch will take the key: 'api.service.total', and transform it to: 'api_service_total'
9+
module StatsD
10+
module Instrument
11+
module Underscore
12+
def increment(key, value = 1, sample_rate: nil, tags: nil, no_prefix: false)
13+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
14+
end
15+
16+
def gauge(key, value, sample_rate: nil, tags: nil, no_prefix: false)
17+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
18+
end
19+
20+
def histogram(key, value, sample_rate: nil, tags: nil, no_prefix: false)
21+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
22+
end
23+
24+
def set(key, value, sample_rate: nil, tags: nil, no_prefix: false)
25+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:)
26+
end
27+
28+
def measure(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
29+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
30+
end
31+
32+
def distribution(key, value = nil, sample_rate: nil, tags: nil, no_prefix: false, &block)
33+
super(substitute_dots_for_underscores(key), value, sample_rate:, tags:, no_prefix:, &block)
34+
end
35+
36+
private
37+
38+
def substitute_dots_for_underscores(key)
39+
key.gsub('.', '_')
40+
end
41+
end
42+
end
43+
end
44+
45+
StatsD::Instrument::Client.prepend(StatsD::Instrument::Underscore) unless Rails.env.test?

0 commit comments

Comments
 (0)