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
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/statsd/instrument/compiled_metric.rb', line 241 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}|##{all_tags}" end elsif .empty? "#{prefix}#{normalized_name}:%s|#{type}" else "#{prefix}#{normalized_name}:%s|#{type}|##{all_tags}" end end |
.normalize_name(name) ⇒ String
Normalizes metric names by replacing special characters
269 270 271 |
# File 'lib/statsd/instrument/compiled_metric.rb', line 269 def normalize_name(name) name.tr(":|@", "_") end |