From 713c66740162f9e59bc5a24b118210aa7171c049 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Fri, 4 Oct 2019 14:29:50 +0800 Subject: [PATCH] filters/sql: ignore more irrelevant queries from Postgres --- CHANGELOG.md | 3 +++ lib/airbrake-ruby/filters/sql_filter.rb | 5 ++++- spec/filters/sql_filter_spec.rb | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca6832d..75825fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Airbrake Ruby Changelog ### master +* Added more irrelevant SQL queries to the query stats ignore list + ([#507](https://github.com/airbrake/airbrake-ruby/pull/507)) + ### [v4.7.0][v4.7.0] (October 3, 2019) * Improved grouping of some SQL queries diff --git a/lib/airbrake-ruby/filters/sql_filter.rb b/lib/airbrake-ruby/filters/sql_filter.rb index 4153bba2..d28fd09c 100644 --- a/lib/airbrake-ruby/filters/sql_filter.rb +++ b/lib/airbrake-ruby/filters/sql_filter.rb @@ -86,7 +86,10 @@ class SqlFilter /\ASET/i, /\ASHOW/i, /\AWITH/i, - /FROM pg_attribute/i + /FROM pg_attribute/i, + /FROM pg_index/i, + /FROM pg_class/i, + /FROM pg_type/i ].freeze def initialize(dialect) diff --git a/spec/filters/sql_filter_spec.rb b/spec/filters/sql_filter_spec.rb index 3a77d8f5..06b4c99a 100644 --- a/spec/filters/sql_filter_spec.rb +++ b/spec/filters/sql_filter_spec.rb @@ -248,8 +248,22 @@ 'cons AS ( SELECT conrelid, connum, row_number() OVER() AS rownum FROM ' \ 'pk_constraint ) SELECT attr.attname FROM pg_attribute attr INNER JOIN ' \ 'cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.connum ' \ - 'ORDER BY cons.rownum' + 'ORDER BY cons.rownum', + 'SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON ' \ + 'n.oid = c.relnamespace WHERE n.nspname = ANY (?)', + + 'SELECT a.attname FROM ( SELECT indrelid, indkey, generate_subscripts(?) ' \ + 'idx FROM pg_index WHERE indrelid = ?::regclass AND indisprimary ) i ' \ + 'JOIN pg_attribute a ON a.attrelid = i.indrelid AND ' \ + 'a.attnum = i.indkey[i.idx] ORDER BY i.idx', + + 'SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, ' \ + 't.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON ' \ + 'oid = rngtypid WHERE t.typname IN (?) OR t.typtype IN (?) OR t.typinput ' \ + '= ?::regprocedure OR t.typelem != ?', + + 'SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN (?)' ].each do |query| include_examples 'query blacklisting', query, should_ignore: true end