datadog-statsd-schema 0.1.1 → 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.
@@ -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 << self
16
- def emitter(...)
17
- ::Datadog::Statsd::Emitter.new(...)
18
- end
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
- def schema(...)
21
- ::Datadog::Statsd::Schema.new(...)
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
- class Statsd
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 the global schema
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
- # Configuration class for global settings
123
+ # Global configuration class for schema settings
124
+ # Manages global StatsD client instance, schema, and tags
60
125
  class Configuration
61
- attr_accessor :statsd, :schema, :tags
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.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-05-31 00:00:00.000000000 Z
10
+ date: 2025-06-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -148,10 +148,12 @@ executables:
148
148
  extensions: []
149
149
  extra_rdoc_files: []
150
150
  files:
151
+ - ".envrc"
151
152
  - ".rspec"
152
153
  - ".rubocop.yml"
153
154
  - ".rubocop_todo.yml"
154
155
  - CHANGELOG.md
156
+ - FUTURE_DIRECTION.md
155
157
  - LICENSE.txt
156
158
  - README.md
157
159
  - Rakefile