Class: StatsD::Instrument::CompiledMetric::DatagramBlueprintBuilder
- Inherits:
-
Object
- Object
- StatsD::Instrument::CompiledMetric::DatagramBlueprintBuilder
- Defined in:
- lib/statsd/instrument/compiled_metric.rb
Overview
Helper class to build datagram blueprints at definition time. Handles prefix building, tag compilation, and blueprint construction.
Class Method Summary collapse
-
.build(name:, type:, client_prefix:, no_prefix:, default_tags:, static_tags:, dynamic_tags:, sample_rate:) ⇒ String
Builds a datagram blueprint string.
-
.normalize_name(name) ⇒ String
Normalizes metric names by replacing special characters.
Class Method Details
.build(name:, type:, client_prefix:, no_prefix:, default_tags:, static_tags:, dynamic_tags:, sample_rate:) ⇒ String
Builds a datagram blueprint string
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/statsd/instrument/compiled_metric.rb', line 273 def build(name:, type:, client_prefix:, no_prefix:, default_tags:, static_tags:, dynamic_tags:, sample_rate:) # Normalize and build prefix normalized_name = normalize_name(name) prefix = build_prefix(client_prefix, no_prefix) # Compile all tags (default, static, dynamic) = (, , ) # Build the datagram blueprint # Format: "<prefix><name>:<value_format>|<type>|@<sample_rate>|#<tags>" # Note: When aggregation is enabled, sample_rate is applied before aggregation if sample_rate && sample_rate < 1 # Include sample_rate in the blueprint (only when not aggregating) if .empty? "#{prefix}#{normalized_name}:%s|#{type}|@#{sample_rate}" else "#{prefix}#{normalized_name}:%s|#{type}|@#{sample_rate}|##{}" end elsif .empty? "#{prefix}#{normalized_name}:%s|#{type}" else "#{prefix}#{normalized_name}:%s|#{type}|##{}" end end |
.normalize_name(name) ⇒ String
Normalizes metric names by replacing special characters
301 302 303 |
# File 'lib/statsd/instrument/compiled_metric.rb', line 301 def normalize_name(name) name.tr(":|@", "_") end |