statsd-instrument 3.0.0.pre2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +15 -15
- data/CHANGELOG.md +23 -0
- data/benchmark/send-metrics-to-dev-null-log +1 -0
- data/benchmark/send-metrics-to-local-udp-receiver +1 -0
- data/lib/statsd/instrument.rb +53 -86
- data/lib/statsd/instrument/assertions.rb +0 -12
- data/lib/statsd/instrument/client.rb +125 -25
- data/lib/statsd/instrument/expectation.rb +0 -4
- data/lib/statsd/instrument/matchers.rb +0 -1
- data/lib/statsd/instrument/strict.rb +0 -5
- data/lib/statsd/instrument/version.rb +1 -1
- data/test/statsd_test.rb +4 -2
- data/test/test_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e941d77f1b0893b2a919f8c36e902e119c657338e6a4e8b45fc5eaa7b5a05a3
|
4
|
+
data.tar.gz: f80105adf47e4379a59716bd7bb46080db3ed9751edf9ef21ef64689ce39920a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3518393ed260edb75f138168afad1e0f1cbd604bf12511dd73596b84d1721d0008cae138cfdef03291895bd4f8b861dd18b641dcfda093e84976a0d446da5bd3
|
7
|
+
data.tar.gz: 4fd2bc2646b88b497802103eaed1538234e37619ef35363ed061b43ce100dd4d59f03de037b5b766c46e8937b7c926fbba2a0dba7f10d5610fae43e2c31f17f2
|
data/.github/workflows/ci.yml
CHANGED
@@ -20,7 +20,7 @@ Style/Alias:
|
|
20
20
|
- prefer_alias
|
21
21
|
- prefer_alias_method
|
22
22
|
|
23
|
-
Layout/
|
23
|
+
Layout/HashAlignment:
|
24
24
|
EnforcedHashRocketStyle: key
|
25
25
|
EnforcedColonStyle: key
|
26
26
|
EnforcedLastArgumentHashStyle: ignore_implicit
|
@@ -30,7 +30,7 @@ Layout/AlignHash:
|
|
30
30
|
- ignore_implicit
|
31
31
|
- ignore_explicit
|
32
32
|
|
33
|
-
Layout/
|
33
|
+
Layout/ParameterAlignment:
|
34
34
|
EnforcedStyle: with_fixed_indentation
|
35
35
|
SupportedStyles:
|
36
36
|
- with_first_parameter
|
@@ -172,7 +172,7 @@ Naming/FileName:
|
|
172
172
|
Regex:
|
173
173
|
IgnoreExecutableScripts: true
|
174
174
|
|
175
|
-
Layout/
|
175
|
+
Layout/FirstArgumentIndentation:
|
176
176
|
EnforcedStyle: consistent
|
177
177
|
SupportedStyles:
|
178
178
|
- consistent
|
@@ -225,7 +225,7 @@ Layout/IndentationConsistency:
|
|
225
225
|
Layout/IndentationWidth:
|
226
226
|
Width: 2
|
227
227
|
|
228
|
-
Layout/
|
228
|
+
Layout/FirstArrayElementIndentation:
|
229
229
|
EnforcedStyle: consistent
|
230
230
|
SupportedStyles:
|
231
231
|
- special_inside_parentheses
|
@@ -233,10 +233,10 @@ Layout/IndentFirstArrayElement:
|
|
233
233
|
- align_brackets
|
234
234
|
IndentationWidth:
|
235
235
|
|
236
|
-
Layout/
|
236
|
+
Layout/AssignmentIndentation:
|
237
237
|
IndentationWidth:
|
238
238
|
|
239
|
-
Layout/
|
239
|
+
Layout/FirstHashElementIndentation:
|
240
240
|
EnforcedStyle: consistent
|
241
241
|
SupportedStyles:
|
242
242
|
- special_inside_parentheses
|
@@ -340,9 +340,9 @@ Style/PercentQLiterals:
|
|
340
340
|
Naming/PredicateName:
|
341
341
|
NamePrefix:
|
342
342
|
- is_
|
343
|
-
|
343
|
+
ForbiddenPrefixes:
|
344
344
|
- is_
|
345
|
-
|
345
|
+
AllowedMethods:
|
346
346
|
- is_a?
|
347
347
|
Exclude:
|
348
348
|
- 'spec/**/*'
|
@@ -467,7 +467,7 @@ Style/TernaryParentheses:
|
|
467
467
|
- require_no_parentheses
|
468
468
|
AllowSafeAssignment: true
|
469
469
|
|
470
|
-
Layout/
|
470
|
+
Layout/TrailingEmptyLines:
|
471
471
|
EnforcedStyle: final_newline
|
472
472
|
SupportedStyles:
|
473
473
|
- final_newline
|
@@ -478,7 +478,7 @@ Style/TrivialAccessors:
|
|
478
478
|
AllowPredicates: true
|
479
479
|
AllowDSLWriters: false
|
480
480
|
IgnoreClassMethods: false
|
481
|
-
|
481
|
+
AllowedMethods:
|
482
482
|
- to_ary
|
483
483
|
- to_a
|
484
484
|
- to_c
|
@@ -561,7 +561,7 @@ Lint/UnusedMethodArgument:
|
|
561
561
|
Naming/AccessorMethodName:
|
562
562
|
Enabled: true
|
563
563
|
|
564
|
-
Layout/
|
564
|
+
Layout/ArrayAlignment:
|
565
565
|
Enabled: true
|
566
566
|
|
567
567
|
Style/ArrayJoin:
|
@@ -840,7 +840,7 @@ Style/WhileUntilDo:
|
|
840
840
|
Style/ZeroLengthPredicate:
|
841
841
|
Enabled: true
|
842
842
|
|
843
|
-
Layout/
|
843
|
+
Layout/HeredocIndentation:
|
844
844
|
EnforcedStyle: squiggly
|
845
845
|
|
846
846
|
Lint/AmbiguousOperator:
|
@@ -864,7 +864,7 @@ Lint/DeprecatedClassMethods:
|
|
864
864
|
Lint/DuplicateMethods:
|
865
865
|
Enabled: true
|
866
866
|
|
867
|
-
Lint/
|
867
|
+
Lint/DuplicateHashKey:
|
868
868
|
Enabled: true
|
869
869
|
|
870
870
|
Lint/EachWithObjectArgument:
|
@@ -891,7 +891,7 @@ Lint/FloatOutOfRange:
|
|
891
891
|
Lint/FormatParameterMismatch:
|
892
892
|
Enabled: true
|
893
893
|
|
894
|
-
Lint/
|
894
|
+
Lint/SuppressedException:
|
895
895
|
AllowComments: true
|
896
896
|
|
897
897
|
Lint/ImplicitStringConcatenation:
|
@@ -947,7 +947,7 @@ Lint/ShadowedException:
|
|
947
947
|
Lint/ShadowingOuterLocalVariable:
|
948
948
|
Enabled: true
|
949
949
|
|
950
|
-
Lint/
|
950
|
+
Lint/RedundantStringCoercion:
|
951
951
|
Enabled: true
|
952
952
|
|
953
953
|
Lint/UnderscorePrefixedVariableName:
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,29 @@ section below.
|
|
8
8
|
|
9
9
|
_Nothing yet_
|
10
10
|
|
11
|
+
## Version 3.0.0
|
12
|
+
|
13
|
+
This version makes the new client that was added in version 2.6+ the default
|
14
|
+
client, and removes the legacy client.
|
15
|
+
|
16
|
+
- All previously deprecated functionality has been removed (since version 2.5,
|
17
|
+
see below).
|
18
|
+
- Support for the StatSite implementation has been dropped.
|
19
|
+
- Support for Ruby version older than 2.4 has been dropped.
|
20
|
+
- The default implementation has been changed to DataDog. To use the standard
|
21
|
+
StatsD implementation (which was the default in v2), set the
|
22
|
+
`STATSD_IMPLEMENTATION` environment variable to `statsd`.
|
23
|
+
|
24
|
+
To upgrade, follow the following process:
|
25
|
+
|
26
|
+
1. Upgrade to version 2.9.2.
|
27
|
+
2. Switch to the new client by setting the `STATSD_USE_NEW_CLIENT` environment
|
28
|
+
variable to 1.
|
29
|
+
- You may want to use the Rubocop rules that ship with this library, and
|
30
|
+
strict mode to find and fix deprecated usage patterns. See below for more
|
31
|
+
information about strict mode and the available Rubocop rules.
|
32
|
+
3. Upgrade to version 3.0.0, and unset `STATSD_USE_NEW_CLIENT`.
|
33
|
+
|
11
34
|
## Version 2.9.2
|
12
35
|
|
13
36
|
- Allow providing a value as second positional argument to `assert_statsd_*`
|
data/lib/statsd/instrument.rb
CHANGED
@@ -4,86 +4,14 @@ require 'socket'
|
|
4
4
|
require 'logger'
|
5
5
|
require 'forwardable'
|
6
6
|
|
7
|
-
# The StatsD module contains low-level metrics for collecting metrics and
|
7
|
+
# The `StatsD` module contains low-level metrics for collecting metrics and
|
8
|
+
# sending them to the backend.
|
8
9
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @note This new Client implementation is intended to become the new default in
|
13
|
-
# the next major release of this library. While this class may already be functional,
|
14
|
-
# we provide no guarantees about the API and the behavior may change.
|
15
|
-
#
|
16
|
-
# @!attribute backend
|
17
|
-
# The backend that is being used to emit the metrics.
|
18
|
-
# @return [StatsD::Instrument::Backend] the currently active backend. If there is no active backend
|
19
|
-
# yet, it will call {StatsD::Instrument::Environment#default_backend} to obtain a
|
20
|
-
# default backend for the environment.
|
21
|
-
# @see StatsD::Instrument::Environment#default_backend
|
22
|
-
# @deprecated
|
23
|
-
#
|
24
|
-
# @!attribute prefix
|
25
|
-
# The prefix to apply to metric names. This can be useful to group all the metrics
|
26
|
-
# for an application in a shared StatsD server.
|
27
|
-
#
|
28
|
-
# When using a prefix a dot will be included automatically to separate the prefix
|
29
|
-
# from the metric name.
|
30
|
-
#
|
31
|
-
# @return [String, nil] The prefix, or <tt>nil</tt> when no prefix is used
|
32
|
-
# @see StatsD::Instrument::Metric#name
|
33
|
-
# @deprecated
|
34
|
-
#
|
35
|
-
# @!attribute default_sample_rate
|
36
|
-
# The sample rate to use if the sample rate is unspecified for a metric call.
|
37
|
-
# @return [Float] Default is 1.0.
|
38
|
-
# @deprecated
|
39
|
-
#
|
40
|
-
# @!attribute logger
|
41
|
-
# The logger to use in case of any errors. The logger is also used as default logger
|
42
|
-
# for the LoggerBackend (although this can be overwritten).
|
43
|
-
# @see StatsD::Instrument::Backends::LoggerBackend
|
44
|
-
# @return [Logger]
|
45
|
-
#
|
46
|
-
# @!attribute default_tags
|
47
|
-
# The tags to apply to all metrics.
|
48
|
-
# @return [Array<String>, Hash<String, String>, nil] The default tags, or <tt>nil</tt> when no default tags is used
|
49
|
-
# @deprecated
|
50
|
-
#
|
51
|
-
# @!attribute singleton_client
|
52
|
-
# @nodoc
|
53
|
-
# @deprecated
|
54
|
-
#
|
55
|
-
# @!method measure(name, value = nil, sample_rate: nil, tags: nil, &block)
|
56
|
-
# (see StatsD::Instrument::Client#measure)
|
57
|
-
#
|
58
|
-
# @!method increment(name, value = 1, sample_rate: nil, tags: nil)
|
59
|
-
# (see StatsD::Instrument::Client#increment)
|
60
|
-
#
|
61
|
-
# @!method gauge(name, value, sample_rate: nil, tags: nil)
|
62
|
-
# (see StatsD::Instrument::Client#gauge)
|
63
|
-
#
|
64
|
-
# @!method set(name, value, sample_rate: nil, tags: nil)
|
65
|
-
# (see StatsD::Instrument::Client#set)
|
66
|
-
#
|
67
|
-
# @!method histogram(name, value, sample_rate: nil, tags: nil)
|
68
|
-
# (see StatsD::Instrument::Client#histogram)
|
69
|
-
#
|
70
|
-
# @!method distribution(name, value = nil, sample_rate: nil, tags: nil, &block)
|
71
|
-
# (see StatsD::Instrument::Client#distribution)
|
72
|
-
#
|
73
|
-
# @!method key_value(name, value)
|
74
|
-
# (see StatsD::Instrument::Client#key_value)
|
75
|
-
#
|
76
|
-
# @!method event(title, text, tags: nil, hostname: nil, timestamp: nil, aggregation_key: nil, priority: nil, source_type_name: nil, alert_type: nil) # rubocop:disable Metrics/LineLength
|
77
|
-
# (see StatsD::Instrument::Client#event)
|
78
|
-
#
|
79
|
-
# @!method service_check(name, status, tags: nil, hostname: nil, timestamp: nil, message: nil)
|
80
|
-
# (see StatsD::Instrument::Client#service_check)
|
81
|
-
#
|
82
|
-
# @see StatsD::Instrument <tt>StatsD::Instrument</tt> contains module to instrument
|
10
|
+
# @see .singleton_client Metric method calls on the `StatsD` singleton will
|
11
|
+
# be handled by the client assigned to `StatsD.singleton_client`.
|
12
|
+
# @see StatsD::Instrument `StatsD::Instrument` contains module to instrument
|
83
13
|
# existing methods with StatsD metrics
|
84
14
|
module StatsD
|
85
|
-
extend self
|
86
|
-
|
87
15
|
# The StatsD::Instrument module provides metaprogramming methods to instrument your methods with
|
88
16
|
# StatsD metrics. E.g., you can create counters on how often a method is called, how often it is
|
89
17
|
# successful, the duration of the methods call, etc.
|
@@ -99,7 +27,9 @@ module StatsD
|
|
99
27
|
end
|
100
28
|
end
|
101
29
|
|
30
|
+
# Generates a metric name for an instrumented method.
|
102
31
|
# @private
|
32
|
+
# @return [String]
|
103
33
|
def self.generate_metric_name(name, callee, *args)
|
104
34
|
name.respond_to?(:call) ? name.call(callee, args).gsub('::', '.') : name.gsub('::', '.')
|
105
35
|
end
|
@@ -363,18 +293,55 @@ module StatsD
|
|
363
293
|
end
|
364
294
|
end
|
365
295
|
|
366
|
-
|
367
|
-
|
296
|
+
class << self
|
297
|
+
extend Forwardable
|
368
298
|
|
369
|
-
|
299
|
+
# The logger to use in case of any errors.
|
300
|
+
#
|
301
|
+
# @return [Logger]
|
302
|
+
# @see StatsD::Instrument::LogSink
|
303
|
+
attr_accessor :logger
|
370
304
|
|
371
|
-
|
372
|
-
|
373
|
-
|
305
|
+
# The StatsD client that handles method calls on the StatsD singleton.
|
306
|
+
#
|
307
|
+
# E.g. a call to `StatsD.increment` will be handled by this client.
|
308
|
+
#
|
309
|
+
# @return [StatsD::Instrument::Client]
|
310
|
+
attr_writer :singleton_client
|
311
|
+
|
312
|
+
# The StatsD client that handles method calls on the StatsD singleton
|
313
|
+
# @return [StatsD::Instrument::Client]
|
314
|
+
def singleton_client
|
315
|
+
@singleton_client ||= StatsD::Instrument::Environment.current.client
|
316
|
+
end
|
374
317
|
|
375
|
-
|
376
|
-
|
377
|
-
|
318
|
+
# @!method measure(name, value = nil, sample_rate: nil, tags: nil, &block)
|
319
|
+
# (see StatsD::Instrument::Client#measure)
|
320
|
+
#
|
321
|
+
# @!method increment(name, value = 1, sample_rate: nil, tags: nil)
|
322
|
+
# (see StatsD::Instrument::Client#increment)
|
323
|
+
#
|
324
|
+
# @!method gauge(name, value, sample_rate: nil, tags: nil)
|
325
|
+
# (see StatsD::Instrument::Client#gauge)
|
326
|
+
#
|
327
|
+
# @!method set(name, value, sample_rate: nil, tags: nil)
|
328
|
+
# (see StatsD::Instrument::Client#set)
|
329
|
+
#
|
330
|
+
# @!method histogram(name, value, sample_rate: nil, tags: nil)
|
331
|
+
# (see StatsD::Instrument::Client#histogram)
|
332
|
+
#
|
333
|
+
# @!method distribution(name, value = nil, sample_rate: nil, tags: nil, &block)
|
334
|
+
# (see StatsD::Instrument::Client#distribution)
|
335
|
+
#
|
336
|
+
# @!method event(title, text, tags: nil, hostname: nil, timestamp: nil, aggregation_key: nil, priority: nil, source_type_name: nil, alert_type: nil) # rubocop:disable Metrics/LineLength
|
337
|
+
# (see StatsD::Instrument::Client#event)
|
338
|
+
#
|
339
|
+
# @!method service_check(name, status, tags: nil, hostname: nil, timestamp: nil, message: nil)
|
340
|
+
# (see StatsD::Instrument::Client#service_check)
|
341
|
+
|
342
|
+
def_delegators :singleton_client, :increment, :gauge, :set, :measure,
|
343
|
+
:histogram, :distribution, :event, :service_check
|
344
|
+
end
|
378
345
|
end
|
379
346
|
|
380
347
|
require 'statsd/instrument/version'
|
@@ -136,18 +136,6 @@ module StatsD::Instrument::Assertions
|
|
136
136
|
assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
|
137
137
|
end
|
138
138
|
|
139
|
-
# Asserts that a given key/value metric occurred inside the provided block.
|
140
|
-
#
|
141
|
-
# @param metric_name (see #assert_statsd_increment)
|
142
|
-
# @param options (see #assert_statsd_increment)
|
143
|
-
# @yield (see #assert_statsd_increment)
|
144
|
-
# @return [void]
|
145
|
-
# @raise (see #assert_statsd_increment)
|
146
|
-
def assert_statsd_key_value(metric_name, value = nil, datagrams: nil, client: nil, **options, &block)
|
147
|
-
expectation = StatsD::Instrument::Expectation.key_value(metric_name, value, **options)
|
148
|
-
assert_statsd_expectation(expectation, datagrams: datagrams, client: client, &block)
|
149
|
-
end
|
150
|
-
|
151
139
|
# Asserts that the set of provided metric expectations came true.
|
152
140
|
#
|
153
141
|
# Generally, it's recommended to use more specific assertion methods, like
|
@@ -1,12 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The Client is the main interface for using StatsD.
|
3
|
+
# The Client is the main interface for using StatsD. It defines the metric
|
4
|
+
# methods that you would normally call from your application.
|
4
5
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# The client set to {StatsD.singleton_client} will handle all metric calls made
|
7
|
+
# against the StatsD singleton, e.g. `StatsD.increment`.
|
8
|
+
#
|
9
|
+
# We recommend that the configuration of the StatsD setup is provided through
|
10
|
+
# environment variables
|
11
|
+
#
|
12
|
+
# You are encouraged to instantiate multiple clients, and instantiate variants
|
13
|
+
# of an existing clients using {#clone_with_options}. We recommend instantiating
|
14
|
+
# a separate client for every logical component of your application using
|
15
|
+
# `clone_with_options`, and setting a different metric `prefix`.
|
16
|
+
#
|
17
|
+
# @see StatsD.singleton_client
|
18
|
+
# @see #clone_with_options
|
8
19
|
class StatsD::Instrument::Client
|
9
20
|
class << self
|
21
|
+
# Instantiates a StatsD::Instrument::Client using configuration values provided in
|
22
|
+
# environment variables.
|
23
|
+
#
|
24
|
+
# @see StatsD::Instrument::Environment
|
10
25
|
def from_env(
|
11
26
|
env = StatsD::Instrument::Environment.current,
|
12
27
|
prefix: env.statsd_prefix,
|
@@ -26,7 +41,14 @@ class StatsD::Instrument::Client
|
|
26
41
|
)
|
27
42
|
end
|
28
43
|
|
44
|
+
# Finds the right DatagramBuilder class for a given implementation.
|
29
45
|
# @private
|
46
|
+
# @param [Symbol, String] implementation The name of the implementation, e.g.
|
47
|
+
# `"statsd"` or `:datadog`.
|
48
|
+
# @return [Class] The subclass of {StatsD::Instrument::DatagramBuilder}
|
49
|
+
# builder to use to generate UDP datagrams for the given implementation.
|
50
|
+
# @raise `NotImplementedError` if the implementation is not recognized or
|
51
|
+
# supported.
|
30
52
|
def datagram_builder_class_for_implementation(implementation)
|
31
53
|
case implementation.to_s
|
32
54
|
when 'statsd'
|
@@ -39,8 +61,87 @@ class StatsD::Instrument::Client
|
|
39
61
|
end
|
40
62
|
end
|
41
63
|
|
42
|
-
|
64
|
+
# The class to use to build StatsD datagrams. To build the actual datagrams,
|
65
|
+
# the class will be instantiated, potentially multiple times, by the client.
|
66
|
+
#
|
67
|
+
# @return [Class] A subclass of {StatsD::Instrument::DatagramBuilder}
|
68
|
+
# @see .datagram_builder_class_for_implementation
|
69
|
+
attr_reader :datagram_builder_class
|
70
|
+
|
71
|
+
# The sink to send UDP datagrams to.
|
72
|
+
#
|
73
|
+
# This can be set to any object that responds to the following methods:
|
74
|
+
#
|
75
|
+
# - `sample?` which should return true if the metric should be sampled, i.e.
|
76
|
+
# actually sent to the sink.
|
77
|
+
# - `#<<` which takes a UDP datagram as string to emit the datagram. This
|
78
|
+
# method will only be called if `sample?` returned `true`.
|
79
|
+
#
|
80
|
+
# Generally, you should use an instance of one of the following classes that
|
81
|
+
# ship with this library:
|
82
|
+
#
|
83
|
+
# - {StatsD::Instrument::UDPSink} A sink that will actually emit the provided
|
84
|
+
# datagrams over UDP.
|
85
|
+
# - {StatsD::Instrument::NullSink} A sink that will simply swallow every
|
86
|
+
# datagram. This sink is for use when testing your application.
|
87
|
+
# - {StatsD::Instrument::LogSink} A sink that log all provided datagrams to
|
88
|
+
# a Logger, normally {StatsD.logger}.
|
89
|
+
#
|
90
|
+
# @return [#sample?, #<<]
|
91
|
+
attr_reader :sink
|
43
92
|
|
93
|
+
# The prefix to prepend to the metric names that are emitted through this
|
94
|
+
# client, using a dot (`.`) as namespace separator. E.g. when the prefix is
|
95
|
+
# set to `foo`, and you emit a metric named `bar`, the metric name will be
|
96
|
+
# `foo.bar`.
|
97
|
+
#
|
98
|
+
# Generally all the metrics you emit to the same StatsD server will share a
|
99
|
+
# single, global namespace. If you are emitting metrics from multiple
|
100
|
+
# applications, using a prefix is recommended to prevent metric name
|
101
|
+
# collisions.
|
102
|
+
#
|
103
|
+
# You can also leave this value to be `nil` if you don't want to prefix your
|
104
|
+
# metric names.
|
105
|
+
#
|
106
|
+
# @return [String, nil]
|
107
|
+
#
|
108
|
+
# @note The `prefix` can be overriden by any metric call by setting the
|
109
|
+
# `no_prefix` keyword argument to `true`. We recommend against doing this,
|
110
|
+
# but this behavior is retained for backwards compatibility.
|
111
|
+
# Rather, when you feel the need to do this, we recommend instantiating
|
112
|
+
# a new client without prefix (using {#clone_with_options}), and using it
|
113
|
+
# to emit the metric.
|
114
|
+
attr_reader :prefix
|
115
|
+
|
116
|
+
# The tags to apply to all the metrics emitted through this client.
|
117
|
+
#
|
118
|
+
# The tags can be supplied in normal form: an array of strings. You can also
|
119
|
+
# provide a hash, which will be turned into normal form by concatanting the
|
120
|
+
# key and the value using a colon. To not use any default tags, set to `nil`.
|
121
|
+
# Note that other components of your StatsD metric pipeline may also add tags
|
122
|
+
# to metrics. E.g. the DataDog agent may add add tags like `hostname`.
|
123
|
+
#
|
124
|
+
# We generally recommend to not use default tags, or use them sparingly.
|
125
|
+
# Adding tags to every metric easily introduces carninality explosions, which
|
126
|
+
# will make metrics less precise due to the lossy nature of aggregation. It
|
127
|
+
# also makes your infrastructure more expsnive to run, and the user interface
|
128
|
+
# of your metric explorer less responsive.
|
129
|
+
#
|
130
|
+
# @return [Array<String>, Hash, nil]
|
131
|
+
attr_reader :default_tags
|
132
|
+
|
133
|
+
# The default sample rate to use for metrics that are emitted without a
|
134
|
+
# sample rate set. This should be a value between 0 (never emit a metric) and
|
135
|
+
# 1.0 (always emit). If it is not set, the default value 1.0 is used.
|
136
|
+
#
|
137
|
+
# We generally recommend setting sample rates on individual metrics based
|
138
|
+
# on their frequency, rather than changing the default sample rate.
|
139
|
+
#
|
140
|
+
# @return [Float] (default: 1.0) A value between 0.0 and 1.0.
|
141
|
+
attr_reader :default_sample_rate
|
142
|
+
|
143
|
+
# Instantiates a new client.
|
144
|
+
# @see .from_env to instantiate a client using environment variables.
|
44
145
|
def initialize(
|
45
146
|
prefix: nil,
|
46
147
|
default_sample_rate: 1.0,
|
@@ -216,18 +317,15 @@ class StatsD::Instrument::Client
|
|
216
317
|
end
|
217
318
|
end
|
218
319
|
|
219
|
-
# Emits a service check.
|
220
|
-
#
|
221
|
-
#
|
222
|
-
# @param
|
223
|
-
# @param
|
224
|
-
#
|
225
|
-
# @param
|
226
|
-
# @param
|
227
|
-
# @param
|
228
|
-
# @param [String] source_type_name The source type of the event.
|
229
|
-
# @param [String] alert_type Either "error", "warning", "info" (default) or "success".
|
230
|
-
# @param [Array, Hash] tags Tags to associate with the event.
|
320
|
+
# Emits a service check. Services Checks allow you to characterize the status
|
321
|
+
# of a service in order to monitor it within Datadog.
|
322
|
+
#
|
323
|
+
# @param name (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
324
|
+
# @param status (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
325
|
+
# @param timestamp (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
326
|
+
# @param hostname (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
327
|
+
# @param tags (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
328
|
+
# @param message (see StatsD::Instrument::DogStatsDDatagramBuilder#_sc)
|
231
329
|
# @return [void]
|
232
330
|
#
|
233
331
|
# @note Supported by the Datadog implementation only.
|
@@ -236,15 +334,17 @@ class StatsD::Instrument::Client
|
|
236
334
|
timestamp: timestamp, hostname: hostname, tags: tags, message: message))
|
237
335
|
end
|
238
336
|
|
239
|
-
# Emits an event.
|
337
|
+
# Emits an event. An event represents any record of activity noteworthy for engineers.
|
240
338
|
#
|
241
|
-
# @param
|
242
|
-
# @param
|
243
|
-
# @param
|
244
|
-
#
|
245
|
-
# @param
|
246
|
-
# @param
|
247
|
-
# @param
|
339
|
+
# @param title (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
340
|
+
# @param text (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
341
|
+
# @param timestamp (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
342
|
+
# @param hostname (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
343
|
+
# @param aggregation_key (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
344
|
+
# @param priority (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
345
|
+
# @param source_type_name (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
346
|
+
# @param alert_type (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
347
|
+
# @param tags (see StatsD::Instrument::DogStatsDDatagramBuilder#_e)
|
248
348
|
# @return [void]
|
249
349
|
#
|
250
350
|
# @note Supported by the Datadog implementation only.
|
@@ -19,10 +19,6 @@ class StatsD::Instrument::Expectation
|
|
19
19
|
new(type: :s, name: name, value: value, **options)
|
20
20
|
end
|
21
21
|
|
22
|
-
def key_value(name, value = nil, **options)
|
23
|
-
new(type: :kv, name: name, value: value, **options)
|
24
|
-
end
|
25
|
-
|
26
22
|
def distribution(name, value = nil, **options)
|
27
23
|
new(type: :d, name: name, value: value, **options)
|
28
24
|
end
|
data/test/statsd_test.rb
CHANGED
@@ -55,7 +55,8 @@ class StatsDTest < Minitest::Test
|
|
55
55
|
|
56
56
|
begin
|
57
57
|
result = lambda.call
|
58
|
-
rescue
|
58
|
+
rescue
|
59
|
+
# noop
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
@@ -146,7 +147,8 @@ class StatsDTest < Minitest::Test
|
|
146
147
|
|
147
148
|
begin
|
148
149
|
result = lambda.call
|
149
|
-
rescue
|
150
|
+
rescue
|
151
|
+
# noop
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0
|
4
|
+
version: 3.0.0
|
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: 2020-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -211,9 +211,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
211
|
version: '0'
|
212
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
213
|
requirements:
|
214
|
-
- - "
|
214
|
+
- - ">="
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
version:
|
216
|
+
version: '0'
|
217
217
|
requirements: []
|
218
218
|
rubygems_version: 3.0.3
|
219
219
|
signing_key:
|