diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-12-14 12:31:56 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-12-17 17:25:48 +0100 |
commit | f932b781a79d9b829001c39bc214372b7efd8610 (patch) | |
tree | b3bcd0307c6a1a0048c379ae7242fd610889d754 | |
parent | 09a311568abee739fae0c2577a9cf6aa01516977 (diff) | |
download | gitlab-ce-f932b781a79d9b829001c39bc214372b7efd8610.tar.gz |
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.
-rw-r--r-- | lib/gitlab/metrics/obfuscated_sql.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/obfuscated_sql_spec.rb | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/gitlab/metrics/obfuscated_sql.rb b/lib/gitlab/metrics/obfuscated_sql.rb index 45f2e2bc62a..7b15670aa6b 100644 --- a/lib/gitlab/metrics/obfuscated_sql.rb +++ b/lib/gitlab/metrics/obfuscated_sql.rb @@ -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 diff --git a/spec/lib/gitlab/metrics/obfuscated_sql_spec.rb b/spec/lib/gitlab/metrics/obfuscated_sql_spec.rb index 6e9b62016d6..0f01ee588c9 100644 --- a/spec/lib/gitlab/metrics/obfuscated_sql_spec.rb +++ b/spec/lib/gitlab/metrics/obfuscated_sql_spec.rb @@ -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 |