Module: Datadog::Tracing::Contrib::Redis::Quantize

Defined in:
lib/datadog/tracing/contrib/redis/quantize.rb

Overview

Quantize contains Redis-specific resource quantization tools.

Constant Summary collapse

PLACEHOLDER =
'?'
TOO_LONG_MARK =
'...'
VALUE_MAX_LEN =
50
CMD_MAX_LEN =
500
AUTH_COMMANDS =
%w[AUTH auth].freeze
MULTI_VERB_COMMANDS =
Set.new(
  %w[
    ACL
    CLIENT
    CLUSTER
    COMMAND
    CONFIG
    DEBUG
    LATENCY
    MEMORY
  ]
).freeze

Class Method Summary collapse

Class Method Details

.format_arg(arg) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/datadog/tracing/contrib/redis/quantize.rb', line 33

def format_arg(arg)
  str = Core::Utils.utf8_encode(arg, binary: true, placeholder: PLACEHOLDER)
  Core::Utils.truncate(str, VALUE_MAX_LEN, TOO_LONG_MARK)
rescue => e
  Datadog.logger.debug("non formattable Redis arg #{str}: #{e}")
  PLACEHOLDER
end

.format_command_args(command_args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/datadog/tracing/contrib/redis/quantize.rb', line 41

def format_command_args(command_args)
  command_args = resolve_command_args(command_args)
  return 'AUTH ?' if auth_command?(command_args)

  verb, *args = command_args.map { |x| format_arg(x) }
  Core::Utils.truncate("#{verb.upcase} #{args.join(' ')}", CMD_MAX_LEN, TOO_LONG_MARK)
end

.get_verb(command_args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/tracing/contrib/redis/quantize.rb', line 49

def get_verb(command_args)
  return unless command_args.is_a?(Array)

  return get_verb(command_args.first) if command_args.first.is_a?(Array)

  verb = command_args.first.to_s.upcase
  return verb unless MULTI_VERB_COMMANDS.include?(verb) && command_args[1]

  "#{verb} #{command_args[1]}"
end