diff --git a/notifier/query.rb b/notifier/query.rb index 57186dade3605ea35b45021b2f0fac49e888e89d..35a38635e636731667f15089d5352c3f1cd056ac 100644 --- a/notifier/query.rb +++ b/notifier/query.rb @@ -4,6 +4,7 @@ require 'pg_query' class Query QUERY_GUIDANCE_MILLISECONDS = 100 + CONCURRENT_QUERY_GUIDANCE_MILLISECONDS = 5 * 60 * 1000 TIMING_GUIDELINES = 'https://docs.gitlab.com/ee/development/query_performance.html#timing-guidelines-for-queries' # rubocop:disable Layout/LineLength @@ -44,8 +45,18 @@ class Query query end + def concurrent? + query.downcase.include?('create index concurrently') + end + + def time_guidance + return CONCURRENT_QUERY_GUIDANCE_MILLISECONDS if concurrent? + + QUERY_GUIDANCE_MILLISECONDS + end + def exceeds_time_guidance? - max_time > QUERY_GUIDANCE_MILLISECONDS + max_time > time_guidance end def timing @@ -58,7 +69,7 @@ class Query def warning(migration_name) "#{migration_name} had a query that [exceeded timing guidelines](#{TIMING_GUIDELINES}). Run time "\ - "should not exceed 100ms, but #{timing}
#{formatted_query}
" + "should not exceed #{time_guidance}ms, but #{timing}
#{formatted_query}
" end def excluded? diff --git a/notifier/spec/query_spec.rb b/notifier/spec/query_spec.rb index 9a604f544413288ed9a0179ff9365d254a3d9d71..9e438b1ff37ea454da5c5b0acd1634b95dd8296f 100644 --- a/notifier/spec/query_spec.rb +++ b/notifier/spec/query_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper' describe Query do let(:pg_pass) do { - "query": "select pg_database_size(current_database()) /*application:test*/", - "calls": 1, - "total_time": 269.888734, - "max_time": 269.888734, - "mean_time": 269.888734, - "rows": 0 + "query" => "select pg_database_size(current_database()) /*application:test*/", + "calls" => 1, + "total_time" => 269.888734, + "max_time" => 269.888734, + "mean_time" => 269.888734, + "rows" => 0 } end @@ -58,6 +58,13 @@ describe Query do expect(subject.exceeds_time_guidance?).to be true end + it 'returns false if concurrent operations are below 5 minutes' do + pg_pass['query'] = 'CREATE INDEX CONCURRENTLY index_ci_runners_on_token_lower '\ + 'ON ci_runners (LOWER(token)) /*application:test*/' + + expect(subject.exceeds_time_guidance?).to be false + end + it 'returns false if max time less than QUERY_GUIDANCE_MILLISECONDS' do subject.max_time = described_class::QUERY_GUIDANCE_MILLISECONDS / 2