Class: Datadog::Statsd::Schema::MetricDefinition
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Datadog::Statsd::Schema::MetricDefinition
- Defined in:
- lib/datadog/statsd/schema/metric_definition.rb
Overview
Represents a metric definition within a schema namespace Defines the metric type, allowed/required tags, validation rules, and metadata
Defined Under Namespace
Modules: Types
Constant Summary collapse
- VALID_METRIC_TYPES =
Valid metric types supported by StatsD
i[counter gauge histogram distribution timing set].freeze
Instance Method Summary collapse
-
#allowed_tags ⇒ Array<Symbol>
Array of tag names that are allowed for this metric.
-
#allows_tag?(tag_name) ⇒ Boolean
Check if a tag is allowed for this metric.
-
#counting_metric? ⇒ Boolean
Check if this is a counting metric.
-
#description ⇒ String?
Human-readable description of what this metric measures.
-
#effective_allowed_tags(schema_registry = nil) ⇒ Array<Symbol>
Get effective allowed tags by merging with inherited tags if present.
-
#effective_required_tags(schema_registry = nil) ⇒ Array<Symbol>
Get effective required tags by merging with inherited tags if present.
-
#full_name(namespace_path = []) ⇒ String
Get the full metric name including namespace path.
-
#gauge_metric? ⇒ Boolean
Check if this is a gauge metric.
-
#inherit_tags ⇒ String?
Path to another metric to inherit tags from.
-
#invalid_tags(provided_tags) ⇒ Array<Symbol>
Get all invalid tags from a provided tag set.
-
#missing_required_tags(provided_tags) ⇒ Array<Symbol>
Get all missing required tags from a provided tag set.
-
#name ⇒ Symbol
The metric name as a symbol.
-
#namespace ⇒ Symbol?
The namespace this metric belongs to.
-
#required_tags ⇒ Array<Symbol>
Array of tag names that are required for this metric.
-
#requires_tag?(tag_name) ⇒ Boolean
Check if a tag is required for this metric.
-
#set_metric? ⇒ Boolean
Check if this is a set metric.
-
#timing_metric? ⇒ Boolean
Check if this is a timing-based metric.
-
#type ⇒ Symbol
The metric type (counter, gauge, histogram, distribution, timing, set).
-
#units ⇒ String?
Units of measurement for this metric (e.g., “milliseconds”, “bytes”).
-
#valid_tags?(provided_tags) ⇒ Boolean
Validate a complete tag set for this metric.
Instance Method Details
#allowed_tags ⇒ Array<Symbol>
Array of tag names that are allowed for this metric
55 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 55 attribute :allowed_tags, Types::Array.of(Types::Symbol).default([].freeze) |
#allows_tag?(tag_name) ⇒ Boolean
Check if a tag is allowed for this metric
90 91 92 93 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 90 def allows_tag?(tag_name) tag_symbol = tag_name.to_sym .empty? || .include?(tag_symbol) end |
#counting_metric? ⇒ Boolean
Check if this is a counting metric
147 148 149 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 147 def counting_metric? i[counter].include?(type) end |
#description ⇒ String?
Human-readable description of what this metric measures
51 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 51 attribute :description, Types::String.optional.default(nil) |
#effective_allowed_tags(schema_registry = nil) ⇒ Array<Symbol>
Get effective allowed tags by merging with inherited tags if present
166 167 168 169 170 171 172 173 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 166 def (schema_registry = nil) return unless && schema_registry inherited_metric = schema_registry.find_metric() return unless inherited_metric (inherited_metric.(schema_registry) + ).uniq end |
#effective_required_tags(schema_registry = nil) ⇒ Array<Symbol>
Get effective required tags by merging with inherited tags if present
178 179 180 181 182 183 184 185 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 178 def (schema_registry = nil) return unless && schema_registry inherited_metric = schema_registry.find_metric() return unless inherited_metric (inherited_metric.(schema_registry) + ).uniq end |
#full_name(namespace_path = []) ⇒ String
Get the full metric name including namespace path
78 79 80 81 82 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 78 def full_name(namespace_path = []) return name.to_s if namespace_path.empty? "#{namespace_path.join(".")}.#{name}" end |
#gauge_metric? ⇒ Boolean
Check if this is a gauge metric
153 154 155 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 153 def gauge_metric? type == :gauge end |
#inherit_tags ⇒ String?
Path to another metric to inherit tags from
63 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 63 attribute :inherit_tags, Types::String.optional.default(nil) |
#invalid_tags(provided_tags) ⇒ Array<Symbol>
Get all invalid tags from a provided tag set
123 124 125 126 127 128 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 123 def () return [] if .empty? # No restrictions provided_tag_symbols = .keys.map(&:to_sym) provided_tag_symbols - end |
#missing_required_tags(provided_tags) ⇒ Array<Symbol>
Get all missing required tags from a provided tag set
112 113 114 115 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 112 def () provided_tag_symbols = .keys.map(&:to_sym) - provided_tag_symbols end |
#name ⇒ Symbol
The metric name as a symbol
43 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 43 attribute :name, Types::Strict::Symbol |
#namespace ⇒ Symbol?
The namespace this metric belongs to
71 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 71 attribute :namespace, Types::Strict::Symbol.optional.default(nil) |
#required_tags ⇒ Array<Symbol>
Array of tag names that are required for this metric
59 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 59 attribute :required_tags, Types::Array.of(Types::Symbol).default([].freeze) |
#requires_tag?(tag_name) ⇒ Boolean
Check if a tag is required for this metric
101 102 103 104 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 101 def requires_tag?(tag_name) tag_symbol = tag_name.to_sym .include?(tag_symbol) end |
#set_metric? ⇒ Boolean
Check if this is a set metric
159 160 161 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 159 def set_metric? type == :set end |
#timing_metric? ⇒ Boolean
Check if this is a timing-based metric
141 142 143 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 141 def timing_metric? i[timing distribution histogram].include?(type) end |
#type ⇒ Symbol
The metric type (counter, gauge, histogram, distribution, timing, set)
47 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 47 attribute :type, Types::Strict::Symbol.constrained(included_in: VALID_METRIC_TYPES) |
#units ⇒ String?
Units of measurement for this metric (e.g., “milliseconds”, “bytes”)
67 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 67 attribute :units, Types::String.optional.default(nil) |
#valid_tags?(provided_tags) ⇒ Boolean
Validate a complete tag set for this metric
135 136 137 |
# File 'lib/datadog/statsd/schema/metric_definition.rb', line 135 def () ().empty? && ().empty? end |