Welcome to mirror list, hosted at ThFree Co, Russian Federation.

partitioning_analyzer.rb « ci « query_analyzers « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c2d5dfc1a15dda24de497439e003d088d543315c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module Gitlab
  module Database
    module QueryAnalyzers
      module Ci
        # The purpose of this analyzer is to detect queries not going through a partitioning routing table
        class PartitioningAnalyzer < Database::QueryAnalyzers::Base
          RoutingTableNotUsedError = Class.new(QueryAnalyzerError)

          ENABLED_TABLES = %w[
            ci_builds_metadata
          ].freeze

          class << self
            def enabled?
              ::Feature::FlipperFeature.table_exists? &&
                ::Feature.enabled?(:ci_partitioning_analyze_queries, type: :ops)
            end

            def analyze(parsed)
              analyze_legacy_tables_usage(parsed)
            end

            private

            def analyze_legacy_tables_usage(parsed)
              detected = ENABLED_TABLES & (parsed.pg.dml_tables + parsed.pg.select_tables)

              return if detected.none?

              ::Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
                RoutingTableNotUsedError.new("Detected non-partitioned table use #{detected.inspect}: #{parsed.sql}")
              )
            end
          end
        end
      end
    end
  end
end