Commit f932b781 authored by Yorick Peterse's avatar Yorick Peterse

Replace double quotes when obfuscating SQL

InfluxDB escapes double quotes upon output which makes it a pain to deal
with. This ensures that if we're using PostgreSQL we don't store any
queries containing double quotes in InfluxDB, solving the escaping
problem.
parent 09a31156
......@@ -30,9 +30,17 @@ module Gitlab
regex = Regexp.union(regex, MYSQL_REPLACEMENTS)
end
@sql.gsub(regex, '?').gsub(CONSECUTIVE) do |match|
sql = @sql.gsub(regex, '?').gsub(CONSECUTIVE) do |match|
"#{match.count(',') + 1} values"
end
# InfluxDB escapes double quotes upon output, so lets get rid of them
# whenever we can.
if Gitlab::Database.postgresql?
sql = sql.gsub('"', '')
end
sql
end
end
end
......
......@@ -75,5 +75,13 @@ describe Gitlab::Metrics::ObfuscatedSQL do
expect(sql.to_s).to eq('SELECT x FROM y WHERE z IN (2 values)')
end
end
if Gitlab::Database.postgresql?
it 'replaces double quotes' do
sql = described_class.new('SELECT "x" FROM "y"')
expect(sql.to_s).to eq('SELECT x FROM y')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment