Module: StatsD::Instrument::Sanitization Private

Defined in:
lib/statsd/instrument/sanitization.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Field-specific wire normalization. Clean strings are returned unchanged; callers retaining a frozen value must take ownership themselves.

Constant Summary collapse

NAME_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Hot serializers use these same rules inline to avoid per-field Ruby calls.

/[:|@\s]/.freeze
NAME_CHARACTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

":|@ \t\r\n\f\v"
TAG_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/[|,\r\n]/.freeze
TAG_CHARACTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"|,\r\n"

Class Method Summary collapse

Class Method Details

.name(string) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Replace each ASCII whitespace or protocol delimiter with one underscore.

Returns:

  • (String) —

    The original string if clean, otherwise a new string.



18
19
20
# File 'lib/statsd/instrument/sanitization.rb', line 18

def name(string)
  NAME_PATTERN.match?(string) ? string.tr(NAME_CHARACTERS, "_") : string
end

.service_check_message(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Keep message whitespace intact; this is not a metric name.



28
29
30
# File 'lib/statsd/instrument/sanitization.rb', line 28

def service_check_message(string)
  /[:|@\r\n]/.match?(string) ? string.tr(":|@\r\n", "_") : string
end

.tag(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Tag components allow spaces and colons, but not field/tag separators.



23
24
25
# File 'lib/statsd/instrument/sanitization.rb', line 23

def tag(string)
  TAG_PATTERN.match?(string) ? string.tr(TAG_CHARACTERS, "") : string
end