Sha256: 4745cf3b931fbed900b166d4a888ba0d5ca1f6747f21f0bf6fc9dacbde624a72

Contents?: true

Size: 1.71 KB

Versions: 41

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  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.
        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

41 entries across 41 versions & 2 rubygems

Version Path
newrelic_rpm-6.11.0.365 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.10.0.364 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.9.0.363 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.8.0.360 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.7.0.359 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.6.0.358 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.5.0.357 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.4.0.356 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.3.0.355 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.2.0.354 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.1.0.352 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-6.0.0.351 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.7.0.350 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/database/postgres_explain_obfuscator.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/database/postgres_explain_obfuscator.rb