datadog-statsd-schema 0.1.0 → 0.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 +4 -4
- data/.envrc +2 -0
- data/.rspec +2 -1
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +10 -30
- data/CHANGELOG.md +11 -3
- data/FUTURE_DIRECTION.md +32 -0
- data/README.md +529 -250
- data/Rakefile +7 -7
- data/examples/shared.rb +1 -1
- data/lib/datadog/statsd/emitter.rb +102 -21
- data/lib/datadog/statsd/schema/errors.rb +54 -1
- data/lib/datadog/statsd/schema/metric_definition.rb +86 -3
- data/lib/datadog/statsd/schema/namespace.rb +91 -5
- data/lib/datadog/statsd/schema/schema_builder.rb +162 -4
- data/lib/datadog/statsd/schema/tag_definition.rb +66 -6
- data/lib/datadog/statsd/schema/version.rb +6 -1
- data/lib/datadog/statsd/schema.rb +89 -13
- metadata +12 -4
@@ -11,55 +11,131 @@ require_relative "schema/namespace"
|
|
11
11
|
require_relative "schema/schema_builder"
|
12
12
|
require_relative "emitter"
|
13
13
|
|
14
|
+
# @author Konstantin Gredeskoul @ https://github.com/kigster
|
15
|
+
# @since 0.1.0
|
16
|
+
# @see https://github.com/DataDog/dogstatsd-ruby
|
14
17
|
module Datadog
|
15
|
-
class
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
# Main StatsD client class that provides factory methods for creating emitters and schemas
|
19
|
+
# @see Datadog::Statsd::Emitter
|
20
|
+
# @see Datadog::Statsd::Schema
|
21
|
+
class Statsd
|
22
|
+
class << self
|
23
|
+
# Factory method to create a new Emitter instance
|
24
|
+
# @param args [Array] Arguments passed to Emitter.new
|
25
|
+
# @return [Datadog::Statsd::Emitter] A new emitter instance
|
26
|
+
# @see Datadog::Statsd::Emitter#initialize
|
27
|
+
def emitter(...)
|
28
|
+
::Datadog::Statsd::Emitter.new(...)
|
29
|
+
end
|
19
30
|
|
20
|
-
|
21
|
-
|
31
|
+
# Factory method to create a new Schema instance
|
32
|
+
# @param block [Proc] Block to define the schema structure
|
33
|
+
# @return [Datadog::Statsd::Schema::Namespace] A new schema namespace
|
34
|
+
# @see Datadog::Statsd::Schema.new
|
35
|
+
def schema(...)
|
36
|
+
::Datadog::Statsd::Schema.new(...)
|
37
|
+
end
|
22
38
|
end
|
23
|
-
end
|
24
39
|
|
25
|
-
|
40
|
+
# Schema definition and validation module for StatsD metrics
|
41
|
+
# Provides a DSL for defining metric schemas with type safety and validation
|
42
|
+
# @example Basic schema definition
|
43
|
+
# schema = Datadog::Statsd::Schema.new do
|
44
|
+
# namespace :web do
|
45
|
+
# tags do
|
46
|
+
# tag :environment, values: [:production, :staging, :development]
|
47
|
+
# tag :service, type: :string
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# metrics do
|
51
|
+
# counter :requests_total, tags: { required: [:environment, :service] }
|
52
|
+
# gauge :memory_usage, tags: { allowed: [:environment] }
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# @author Datadog Team
|
57
|
+
# @since 0.1.0
|
26
58
|
module Schema
|
59
|
+
# Base error class for all schema-related errors
|
60
|
+
# @see Datadog::Statsd::Schema::SchemaError
|
27
61
|
class Error < StandardError
|
28
62
|
end
|
29
63
|
|
30
64
|
class << self
|
65
|
+
# Controls whether the schema is in test mode
|
66
|
+
# When true, colored output is disabled for test environments
|
67
|
+
# @return [Boolean] Test mode flag
|
31
68
|
attr_accessor :in_test
|
32
69
|
end
|
33
70
|
|
34
71
|
self.in_test = false
|
35
72
|
|
36
|
-
# Create a new schema definition
|
73
|
+
# Create a new schema definition using the provided block
|
74
|
+
# @param block [Proc] Block containing schema definition DSL
|
75
|
+
# @return [Datadog::Statsd::Schema::Namespace] Root namespace of the schema
|
76
|
+
# @example
|
77
|
+
# schema = Datadog::Statsd::Schema.new do
|
78
|
+
# namespace :app do
|
79
|
+
# tags do
|
80
|
+
# tag :env, values: [:prod, :dev]
|
81
|
+
# end
|
82
|
+
# metrics do
|
83
|
+
# counter :requests
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
# end
|
37
87
|
def self.new(&)
|
38
88
|
builder = SchemaBuilder.new
|
39
89
|
builder.instance_eval(&) if block_given?
|
40
90
|
builder.build
|
41
91
|
end
|
42
92
|
|
43
|
-
# Load schema from a file
|
93
|
+
# Load schema definition from a file
|
94
|
+
# @param path [String] Path to the schema definition file
|
95
|
+
# @return [Datadog::Statsd::Schema::Namespace] Root namespace of the loaded schema
|
96
|
+
# @raise [Errno::ENOENT] If the file doesn't exist
|
97
|
+
# @example
|
98
|
+
# schema = Datadog::Statsd::Schema.load_file("config/metrics_schema.rb")
|
44
99
|
def self.load_file(path)
|
45
100
|
builder = SchemaBuilder.new
|
46
101
|
builder.instance_eval(File.read(path), path)
|
47
102
|
builder.build
|
48
103
|
end
|
49
104
|
|
50
|
-
# Configure
|
105
|
+
# Configure global schema settings
|
106
|
+
# @param block [Proc] Configuration block
|
107
|
+
# @yield [Configuration] Configuration object for setting global options
|
108
|
+
# @example
|
109
|
+
# Datadog::Statsd::Schema.configure do |config|
|
110
|
+
# config.statsd = Datadog::Statsd.new('localhost', 8125)
|
111
|
+
# config.tags = { environment: 'production' }
|
112
|
+
# end
|
51
113
|
def self.configure
|
52
114
|
yield configuration
|
53
115
|
end
|
54
116
|
|
117
|
+
# Get the global configuration object
|
118
|
+
# @return [Datadog::Statsd::Schema::Configuration] Global configuration instance
|
55
119
|
def self.configuration
|
56
120
|
@configuration ||= Configuration.new
|
57
121
|
end
|
58
122
|
|
59
|
-
#
|
123
|
+
# Global configuration class for schema settings
|
124
|
+
# Manages global StatsD client instance, schema, and tags
|
60
125
|
class Configuration
|
61
|
-
|
126
|
+
# Global StatsD client instance
|
127
|
+
# @return [Datadog::Statsd, nil] StatsD client or nil if not configured
|
128
|
+
attr_accessor :statsd
|
129
|
+
|
130
|
+
# Global schema instance
|
131
|
+
# @return [Datadog::Statsd::Schema::Namespace, nil] Schema or nil if not configured
|
132
|
+
attr_accessor :schema
|
133
|
+
|
134
|
+
# Global tags to be applied to all metrics
|
135
|
+
# @return [Hash] Hash of global tags
|
136
|
+
attr_accessor :tags
|
62
137
|
|
138
|
+
# Initialize a new configuration with default values
|
63
139
|
def initialize
|
64
140
|
@statsd = nil
|
65
141
|
@schema = nil
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog-statsd-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Gredeskoul
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-06 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -135,7 +135,12 @@ dependencies:
|
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
|
-
description:
|
138
|
+
description: This gem is an adapter for the dogstatsd-ruby gem. Unlike the Datadog::Statsd
|
139
|
+
metric sender, this gem supports pre-declaring schemas defining allowed metrics
|
140
|
+
and their types, the tags that apply to them, and tag values that must be validated
|
141
|
+
before streamed to Datadog. This approach allows for a more robust and consistent
|
142
|
+
way to ensure that metrics follow a well-thought-out naming scheme and are validated
|
143
|
+
before being sent to Datadog.
|
139
144
|
email:
|
140
145
|
- kigster@gmail.com
|
141
146
|
executables:
|
@@ -143,10 +148,12 @@ executables:
|
|
143
148
|
extensions: []
|
144
149
|
extra_rdoc_files: []
|
145
150
|
files:
|
151
|
+
- ".envrc"
|
146
152
|
- ".rspec"
|
147
153
|
- ".rubocop.yml"
|
148
154
|
- ".rubocop_todo.yml"
|
149
155
|
- CHANGELOG.md
|
156
|
+
- FUTURE_DIRECTION.md
|
150
157
|
- LICENSE.txt
|
151
158
|
- README.md
|
152
159
|
- Rakefile
|
@@ -188,5 +195,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
195
|
requirements: []
|
189
196
|
rubygems_version: 3.6.6
|
190
197
|
specification_version: 4
|
191
|
-
summary:
|
198
|
+
summary: An adapter or wrapper for Datadog Statsd that allows pre-declaring of metrics,
|
199
|
+
tags and tag values and validating them against the schema.
|
192
200
|
test_files: []
|