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

partition_monitoring.rb « partitioning « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5b561fc4470c5716de9e49d08b549ee69f3ae3d (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
# frozen_string_literal: true

module Gitlab
  module Database
    module Partitioning
      class PartitionMonitoring
        attr_reader :models

        def initialize(models = Gitlab::Database::Partitioning.registered_models)
          @models = models
        end

        def report_metrics
          models.each do |model|
            strategy = model.partitioning_strategy

            gauge_present.set({ table: model.table_name }, strategy.current_partitions.size)
            gauge_missing.set({ table: model.table_name }, strategy.missing_partitions.size)
            gauge_extra.set({ table: model.table_name }, strategy.extra_partitions.size)
          end
        end

        private

        def gauge_present
          @gauge_present ||= Gitlab::Metrics.gauge(:db_partitions_present, 'Number of database partitions present')
        end

        def gauge_missing
          @gauge_missing ||= Gitlab::Metrics.gauge(:db_partitions_missing, 'Number of database partitions currently expected, but not present')
        end

        def gauge_extra
          @gauge_extra ||= Gitlab::Metrics.gauge(:db_partitions_extra, 'Number of database partitions currently attached to tables, but outside of their retention window and scheduled to be dropped')
        end
      end
    end
  end
end