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

Defined in:
lib/ddtrace/contrib/redis/quantize.rb

Overview

Quantize contains Redis-specific resource quantization tools.

Constant Summary collapse

PLACEHOLDER =
'?'.freeze
TOO_LONG_MARK =
'...'.freeze
VALUE_MAX_LEN =
50
CMD_MAX_LEN =
500
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



29
30
31
32
33
34
35
36
# File 'lib/ddtrace/contrib/redis/quantize.rb', line 29

def format_arg(arg)
  str = arg.is_a?(Symbol) ? arg.to_s.upcase : arg.to_s
  str = Utils.utf8_encode(str, binary: true, placeholder: PLACEHOLDER)
  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



38
39
40
41
42
43
44
# File 'lib/ddtrace/contrib/redis/quantize.rb', line 38

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

  cmd = command_args.map { |x| format_arg(x) }.join(' ')
  Utils.truncate(cmd, CMD_MAX_LEN, TOO_LONG_MARK)
end

.get_verb(command_args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ddtrace/contrib/redis/quantize.rb', line 46

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)

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

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