module Datadog::Contrib::Redis::Quantize

Quantize contains Redis-specific resource quantization tools.

Constants

CMD_MAX_LEN
PLACEHOLDER
TOO_LONG_MARK
VALUE_MAX_LEN

Public Instance Methods

auth_command?(command_args) click to toggle source
# File lib/ddtrace/contrib/redis/quantize.rb, line 30
def auth_command?(command_args)
  return false unless command_args.is_a?(Array) && !command_args.empty?
  command_args.first.to_sym == :auth
end
format_arg(arg) click to toggle source
# File lib/ddtrace/contrib/redis/quantize.rb, line 13
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) click to toggle source
# File lib/ddtrace/contrib/redis/quantize.rb, line 22
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
resolve_command_args(command_args) click to toggle source

Unwraps command array when Redis is called with the following syntax:

redis.call([:cmd, 'arg1', ...])
# File lib/ddtrace/contrib/redis/quantize.rb, line 37
def resolve_command_args(command_args)
  return command_args.first if command_args.is_a?(Array) && command_args.first.is_a?(Array)

  command_args
end