summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile6
-rw-r--r--Gemfile.lock15
-rw-r--r--lib/gitlab/error_tracking.rb3
-rw-r--r--spec/lib/gitlab/error_tracking_spec.rb17
4 files changed, 30 insertions, 11 deletions
diff --git a/Gemfile b/Gemfile
index cc7d59ef732..3aee2845eae 100644
--- a/Gemfile
+++ b/Gemfile
@@ -309,12 +309,12 @@ gem 'rack-attack', '~> 6.3.0'
gem 'sentry-raven', '~> 3.0'
# PostgreSQL query parsing
-gem 'pg_query', '~> 2.0.3'
+gem 'pg_query', '~> 1.3.0'
gem 'premailer-rails', '~> 1.10.3'
# LabKit: Tracing and Correlation
-gem 'gitlab-labkit', '~> 0.17.1'
+gem 'gitlab-labkit', '~> 0.16.2'
# Thrift is a dependency of gitlab-labkit, we want a version higher than 0.14.0
# because of https://gitlab.com/gitlab-org/gitlab/-/issues/321900
gem 'thrift', '>= 0.14.0'
@@ -485,7 +485,7 @@ gem 'gitaly', '~> 13.12.0.pre.rc1'
gem 'grpc', '~> 1.30.2'
-gem 'google-protobuf', '~> 3.15.8'
+gem 'google-protobuf', '~> 3.14.0'
gem 'toml-rb', '~> 1.0.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 3bf70170a73..23876a9ecc9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -467,13 +467,13 @@ GEM
fog-xml (~> 0.1.0)
google-api-client (>= 0.44.2, < 0.51)
google-cloud-env (~> 1.2)
- gitlab-labkit (0.17.1)
+ gitlab-labkit (0.16.2)
actionpack (>= 5.0.0, < 7.0.0)
activesupport (>= 5.0.0, < 7.0.0)
grpc (~> 1.19)
jaeger-client (~> 1.1)
opentracing (~> 0.4)
- pg_query (~> 2.0)
+ pg_query (~> 1.3)
redis (> 3.0.0, < 5.0.0)
gitlab-license (1.5.0)
gitlab-mail_room (0.0.9)
@@ -516,7 +516,7 @@ GEM
signet (~> 0.12)
google-cloud-env (1.4.0)
faraday (>= 0.17.3, < 2.0)
- google-protobuf (3.15.8)
+ google-protobuf (3.14.0)
googleapis-common-protos-types (1.0.6)
google-protobuf (~> 3.14)
googleauth (0.14.0)
@@ -903,8 +903,7 @@ GEM
peek (1.1.0)
railties (>= 4.0.0)
pg (1.2.3)
- pg_query (2.0.3)
- google-protobuf (~> 3.15.5)
+ pg_query (1.3.0)
plist (3.6.0)
png_quantizator (0.2.1)
po_to_json (1.0.1)
@@ -1480,7 +1479,7 @@ DEPENDENCIES
gitlab-experiment (~> 0.5.4)
gitlab-fog-azure-rm (~> 1.0.1)
gitlab-fog-google (~> 1.13)
- gitlab-labkit (~> 0.17.1)
+ gitlab-labkit (~> 0.16.2)
gitlab-license (~> 1.5)
gitlab-mail_room (~> 0.0.9)
gitlab-markup (~> 1.7.1)
@@ -1492,7 +1491,7 @@ DEPENDENCIES
gitlab_omniauth-ldap (~> 2.1.1)
gon (~> 6.4.0)
google-api-client (~> 0.33)
- google-protobuf (~> 3.15.8)
+ google-protobuf (~> 3.14.0)
gpgme (~> 2.0.19)
grape (~> 1.5.2)
grape-entity (~> 0.9.0)
@@ -1573,7 +1572,7 @@ DEPENDENCIES
parslet (~> 1.8)
peek (~> 1.1)
pg (~> 1.1)
- pg_query (~> 2.0.3)
+ pg_query (~> 1.3.0)
png_quantizator (~> 0.2.1)
premailer-rails (~> 1.10.3)
prometheus-client-mmap (~> 0.12.0)
diff --git a/lib/gitlab/error_tracking.rb b/lib/gitlab/error_tracking.rb
index 38ac5d9af74..e91488c7c27 100644
--- a/lib/gitlab/error_tracking.rb
+++ b/lib/gitlab/error_tracking.rb
@@ -146,6 +146,9 @@ module Gitlab
else
inject_context_for_exception(event, ex.cause) if ex.cause.present?
end
+ # This should only happen on PostgreSQL v12 queries
+ rescue PgQuery::ParseError
+ event.extra[:sql] = ex.sql.to_s
end
end
end
diff --git a/spec/lib/gitlab/error_tracking_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb
index 7ad1f52780a..b3293e6473c 100644
--- a/spec/lib/gitlab/error_tracking_spec.rb
+++ b/spec/lib/gitlab/error_tracking_spec.rb
@@ -204,6 +204,23 @@ RSpec.describe Gitlab::ErrorTracking do
expect(sentry_event.dig('extra', 'sql')).to eq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1')
end
+
+ context 'when SQL cannot be parsed' do
+ let(:pg12_query) do
+ <<-SQL
+ CREATE INDEX CONCURRENTLY my_index ON merge_requests
+ USING btree (target_project_id) INCLUDE (id, latest_merge_request_diff_id)
+ SQL
+ end
+
+ let(:exception) { ActiveRecord::StatementInvalid.new(sql: pg12_query) }
+
+ it 'injects the raw sql query into extra' do
+ track_exception
+
+ expect(sentry_event.dig('extra', 'sql')).to eq(pg12_query)
+ end
+ end
end
context 'when the `ActiveRecord::StatementInvalid` is wrapped in another exception' do