Commit 09f10a9f authored by Andrew Newdigate's avatar Andrew Newdigate Committed by Kamil Trzciński
Browse files

Relax redis dependency requirements and fix NPE in Redis tracing

parent 5772636e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
  spec.add_runtime_dependency "grpc", "~> 1.19" # Be sure to update the "grpc-tools" dev_depenency too
  spec.add_runtime_dependency "jaeger-client", "~> 0.10"
  spec.add_runtime_dependency "opentracing", "~> 0.4"
  spec.add_runtime_dependency "redis", "~> 3.2"
  spec.add_runtime_dependency "redis", ">3.0.0", "<5.0.0"

  # Please maintain alphabetical order for dev dependencies
  spec.add_development_dependency "grpc-tools", "~> 1.19"
+16 −7
Original line number Diff line number Diff line
@@ -42,12 +42,14 @@ module Labkit
        end

        def self.command_serialized(command)
          return "" unless command.is_a?(Array)
          return "" if command.empty?

          command_name, *arguments = command
          command_name ||= "nil"

          info = [command_name]
          info << sanitize_argument_for_command(command_name, arguments.first) unless arguments.empty?

          # Additional arguments? Only include the number
          info << "...#{arguments.size - 1} more value(s)" if arguments.size > 1

          info.join(" ")
@@ -70,7 +72,7 @@ module Labkit
        # get_first_argument_for_command returns a masked value representing the first argument
        # from a redis command, taking care of certain sensitive commands
        def self.sanitize_argument_for_command(command_name, first_argument)
          return "*****" if command_is_sensitive(command_name)
          return "*****" if command_is_sensitive?(command_name)

          return "nil" if first_argument.nil?
          return first if first_argument.is_a?(Numeric)
@@ -79,11 +81,18 @@ module Labkit
          mask_redis_arg(first_argument)
        end

        def self.command_is_sensitive(command_name)
          return true if command_name == :auth || "auth".casecmp(command_name).zero?
          return true if command_name == :eval || "eval".casecmp(command_name).zero?
        # Returns true if the arguments for the command should be masked
        def self.command_is_sensitive?(command_name)
          command_is?(command_name, :auth) || command_is?(command_name, :eval)
        end

          false
        # Returns true if the command is equivalent to the command_symbol symbol
        def self.command_is?(command_name, command_symbol)
          if command_name.is_a?(Symbol)
            command_name == command_symbol
          else
            command_name.to_s.casecmp(command_symbol.to_s).zero?
          end
        end

        def self.mask_redis_arg(argument)
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ describe Labkit::Tracing::Redis::RedisInterceptorHelper do
      %w(GET project_#123_metrics_dashboard_/dashboards) | "GET project_#123_metrics_dashboard_/dashboards"
      %w(GET project_#123_metrics_dashboard_/dashboards/123) | "GET project_#123_metrics_dashboard_/dashboards/*****"
      %w(MGET 1 2 3) | "MGET 1 ...2 more value(s)"
      [nil, "value"] | "nil value"
      nil | ""
      false | ""
    end

    with_them do