Sha256: 81c1b3926827b14ff7ec536af9c5cc94c241d943fda5a5b395aae5db34858fd4

Contents?: true

Size: 1.69 KB

Versions: 37

Compression:

Stored size: 1.69 KB

Contents

# encoding: utf-8

require 'one_apm/agent/database'
require 'one_apm/agent/database/obfuscation_helpers'

module OneApm
  module Agent
    module Database
      module PostgresExplainObfuscator
        extend self

        # Note that this regex can't be shared with the ones in the
        # Database::Obfuscator class because here we don't look for
        # backslash-escaped strings (and those regexes are backwards).
        QUOTED_STRINGS_REGEX = /'(?:[^']|'')*'|"(?:[^"]|"")*"/
        LABEL_LINE_REGEX     = /^([^:\n]*:\s+).*$/.freeze

        def obfuscate(explain)
          # First, we replace all single-quoted strings.
          # This is necessary in order to deal with multi-line string constants
          # embedded in the explain output.
          #
          # Note that we look for both single or double quotes but do not
          # replace double quotes in order to avoid accidentally latching onto a
          # single quote character embedded within a quoted identifier (such as
          # a table name).
          #
          # Note also that we make no special provisions for backslash-escaped
          # single quotes (\') because these are canonicalized to two single
          # quotes ('') in the explain output.
          explain.gsub!(QUOTED_STRINGS_REGEX) do |match|
            match.start_with?('"') ? match : '?'
          end

          # Now, mask anything after the first colon (:).
          # All parts of the query that can appear in the explain output are
          # prefixed with "<label>: ", so we want to preserve the label, but
          # remove the rest of the line.
          explain.gsub!(LABEL_LINE_REGEX,   '\1?')
          explain
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
oneapm_rpm-1.3.6 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.5 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.4 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.3 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.2 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.0 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.9 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.9.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.8 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.8.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.7 lib/one_apm/agent/database/postgres_explain_obfuscator.rb
oneapm_rpm-1.2.7.rc1 lib/one_apm/agent/database/postgres_explain_obfuscator.rb