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

click_house.rb « views « peek « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cc109ccea5111ecb3e79752c0095387884649db9 (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
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module Peek
  module Views
    class ClickHouse < DetailedView
      DEFAULT_THRESHOLDS = {
        calls: 5,
        duration: 1000,
        individual_call: 1000
      }.freeze

      THRESHOLDS = {
        production: {
          calls: 5,
          duration: 1000,
          individual_call: 1000
        }
      }.freeze

      def key
        'ch'
      end

      def self.thresholds
        @thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
      end

      private

      def setup_subscribers
        super

        subscribe('sql.click_house') do |_, start, finish, _, data|
          detail_store << generate_detail(start, finish, data) if Gitlab::PerformanceBar.enabled_for_request?
        end
      end

      def generate_detail(start, finish, data)
        {
          start: start,
          duration: finish - start,
          sql: data[:query].strip,
          backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller),
          database: "database: #{data[:database]}",
          statistics: "query stats: #{data[:statistics]}"
        }
      end
    end
  end
end