gitlab-exporter 16.1.0 → 16.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8f9e18ad6f1758709b718bb67c3491f654a01078aa7835462a0e346731adff9
4
- data.tar.gz: affa763080262ed9621f7d51f8342aaebb2ca8cd5f6296b730a02a042d62b816
3
+ metadata.gz: 60e275e1cea2b8841c1c8471f44d851a49b552ede909c91aca462ad60efcd3ab
4
+ data.tar.gz: 59c1f60fc4caed54da0048db13c3dd1566fd70bbb744f3260c16cca78012c018
5
5
  SHA512:
6
- metadata.gz: 7148d67304d3605314d65ce4c33a4450f33853a086da26150ee19532353db76d05d43326de068894f5d88ee879496ead866917ca2753e37623affab5e9b02292
7
- data.tar.gz: 8d677307d6a128a01c695ce1cec716f31673032ad744bb600a89e713e9ae32ffa39e93ab22790d4e09fca6f485c1664e000ddf627d1bab31ad49e18d5e6f3891
6
+ metadata.gz: e790d3ec4ebb7e07546d5565dc14fdc62f1131b3b23cf367c502eb12e7d7ed55051dd79fed6e8c865af464d1b120eaf2fe6f4f72f3a6a581915adc342b446ad2
7
+ data.tar.gz: 829b42af76274c5ff4b25c9094545ea42491fc41f16bae2dec96cd3a76450beb7cca40496bbc10f926f75b0bcaa509fb9a4001a3f83b2e7dc3f1031b7554d0d3
data/.gitlab-ci.yml CHANGED
@@ -62,7 +62,7 @@ rspec_integration:
62
62
  services:
63
63
  - name: redis:${REDIS_VERSION}
64
64
  alias: redis-master
65
- - name: bitnami/redis-sentinel:${REDIS_SENTINEL_VERSION}
65
+ - name: bitnamilegacy/redis-sentinel:${REDIS_SENTINEL_VERSION}
66
66
  alias: redis-sentinel
67
67
  command:
68
68
  - /bin/sh
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (16.1.0)
5
- connection_pool (= 2.5.3)
4
+ gitlab-exporter (16.2.0)
5
+ connection_pool (= 2.5.4)
6
6
  deep_merge (~> 1.2.2)
7
- faraday (= 2.13.4)
8
- pg (= 1.6.1)
7
+ faraday (= 2.14.0)
8
+ pg (= 1.6.2)
9
9
  puma (= 6.6.1)
10
10
  quantile (= 0.2.1)
11
11
  redis (= 4.8.1)
@@ -19,10 +19,10 @@ GEM
19
19
  specs:
20
20
  ast (2.4.3)
21
21
  base64 (0.2.0)
22
- connection_pool (2.5.3)
22
+ connection_pool (2.5.4)
23
23
  deep_merge (1.2.2)
24
24
  diff-lcs (1.5.0)
25
- faraday (2.13.4)
25
+ faraday (2.14.0)
26
26
  faraday-net_http (>= 2.0, < 3.5)
27
27
  json
28
28
  logger
@@ -38,7 +38,7 @@ GEM
38
38
  parser (3.3.9.0)
39
39
  ast (~> 2.4.1)
40
40
  racc
41
- pg (1.6.1)
41
+ pg (1.6.2)
42
42
  prism (1.4.0)
43
43
  puma (6.6.1)
44
44
  nio4r (~> 2.0)
@@ -66,7 +66,7 @@ GEM
66
66
  diff-lcs (>= 1.2.0, < 2.0)
67
67
  rspec-support (~> 3.12.0)
68
68
  rspec-support (3.12.0)
69
- rubocop (1.79.1)
69
+ rubocop (1.81.1)
70
70
  json (~> 2.3)
71
71
  language_server-protocol (~> 3.17.0.2)
72
72
  lint_roller (~> 1.1.0)
@@ -74,10 +74,10 @@ GEM
74
74
  parser (>= 3.3.0.2)
75
75
  rainbow (>= 2.2.2, < 4.0)
76
76
  regexp_parser (>= 2.9.3, < 3.0)
77
- rubocop-ast (>= 1.46.0, < 2.0)
77
+ rubocop-ast (>= 1.47.1, < 2.0)
78
78
  ruby-progressbar (~> 1.7)
79
79
  unicode-display_width (>= 2.4.0, < 4.0)
80
- rubocop-ast (1.46.0)
80
+ rubocop-ast (1.47.1)
81
81
  parser (>= 3.3.7.2)
82
82
  prism (~> 1.4)
83
83
  ruby-progressbar (1.13.0)
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_ruby_version = Gem::Requirement.new(">= 3.0")
24
24
 
25
- s.add_runtime_dependency "connection_pool", "2.5.3"
25
+ s.add_runtime_dependency "connection_pool", "2.5.4"
26
26
  s.add_runtime_dependency "deep_merge", "~> 1.2.2"
27
- s.add_runtime_dependency "faraday", "2.13.4"
28
- s.add_runtime_dependency "pg", "1.6.1"
27
+ s.add_runtime_dependency "faraday", "2.14.0"
28
+ s.add_runtime_dependency "pg", "1.6.2"
29
29
  s.add_runtime_dependency "puma", "6.6.1"
30
30
  s.add_runtime_dependency "quantile", "0.2.1"
31
31
  s.add_runtime_dependency "redis", "4.8.1"
@@ -3,7 +3,8 @@ module GitLab
3
3
  module Database
4
4
  # A helper class to collect zoekt metrics.
5
5
  class ZoektCollector < Base
6
- QUERY = <<~SQL.freeze
6
+ # Query to get processing zoekt_tasks distribution by zoekt_node_id
7
+ ZOEKT_TASKS_PROCESSING_QUERY = <<~SQL.freeze
7
8
  WITH task_counts AS (
8
9
  SELECT
9
10
  zoekt_node_id,
@@ -26,6 +27,24 @@ module GitLab
26
27
  task_counts tc ON n.id = tc.zoekt_node_id
27
28
  SQL
28
29
 
30
+ ZOEKT_NODES_QUERY = <<~SQL.freeze
31
+ SELECT schema_version, id FROM zoekt_nodes
32
+ SQL
33
+
34
+ ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY = <<~SQL.freeze
35
+ SELECT
36
+ COUNT(*)
37
+ FROM
38
+ zoekt_repositories
39
+ INNER JOIN
40
+ zoekt_indices
41
+ ON zoekt_repositories.zoekt_index_id = zoekt_indices.id
42
+ WHERE
43
+ zoekt_indices.zoekt_node_id = $1
44
+ AND zoekt_repositories.schema_version < $2
45
+ AND zoekt_repositories.state = 10;
46
+ SQL
47
+
29
48
  ZOEKT_ENABLED_QUERY = <<~SQL.freeze
30
49
  SELECT
31
50
  zoekt_settings ->> 'zoekt_indexing_enabled' AS zoekt_indexing_enabled
@@ -35,13 +54,49 @@ module GitLab
35
54
  SQL
36
55
 
37
56
  def run
38
- return unless zoekt_indexing_enabled?
57
+ return {} unless zoekt_indexing_enabled?
39
58
 
40
- execute(QUERY, [Time.now.utc])
59
+ {
60
+ task_processing_query_result: execute(ZOEKT_TASKS_PROCESSING_QUERY, [Time.now.utc]),
61
+ repositories_schema_version_query_result: repositories_schema_version_query_result
62
+ }.compact
41
63
  end
42
64
 
43
65
  private
44
66
 
67
+ def repositories_schema_version_query_result
68
+ hash = zoekt_node_schema_version_hash
69
+ return if hash.nil?
70
+
71
+ zoekt_repository_schema_version_result(hash)
72
+ end
73
+
74
+ def zoekt_node_schema_version_hash
75
+ zoekt_nodes = execute(ZOEKT_NODES_QUERY)
76
+ return if zoekt_nodes.nil?
77
+
78
+ hash = {}
79
+ zoekt_nodes.each do |row|
80
+ hash[row["id"]] = row["schema_version"]
81
+ end
82
+ hash
83
+ end
84
+
85
+ def zoekt_repository_schema_version_result(hash)
86
+ result = Set.new
87
+ hash.each do |id, schema_version|
88
+ query_result = execute(ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY, [id, schema_version])
89
+ if query_result.nil?
90
+ result = nil
91
+ break
92
+ end
93
+
94
+ count = query_result[0]["count"].to_i
95
+ result.add({ target_schema_version: schema_version, zoekt_node_id: id, unfinished_repository_count: count })
96
+ end
97
+ result
98
+ end
99
+
45
100
  def zoekt_indexing_enabled?
46
101
  @zoekt_indexing_enabled ||=
47
102
  begin
@@ -53,7 +108,7 @@ module GitLab
53
108
  end
54
109
  end
55
110
 
56
- def execute(query, params)
111
+ def execute(query, params = [])
57
112
  with_connection_pool do |conn|
58
113
  conn.exec_params(query, params)
59
114
  end
@@ -68,6 +123,10 @@ module GitLab
68
123
  "Number of tasks waiting to be processed by Zoekt",
69
124
  "gauge")
70
125
 
126
+ PrometheusMetrics.describe("search_zoekt_repositories_schema_version_count",
127
+ "Number of zoekt_repositories which do not have the latest schema version",
128
+ "gauge")
129
+
71
130
  def initialize(metrics: PrometheusMetrics.new, **opts)
72
131
  @metrics = metrics
73
132
  @collector = opts[:collector] || ZoektCollector.new(**opts)
@@ -75,13 +134,11 @@ module GitLab
75
134
 
76
135
  def probe_db
77
136
  results = @collector.run
78
- results.to_a.each do |row|
79
- @metrics.add(
80
- "search_zoekt_task_processing_queue_size",
81
- row["task_count"].to_i,
82
- node_name: row["node_name"],
83
- node_id: row["node_id"]
84
- )
137
+ results[:task_processing_query_result].to_a.each do |row|
138
+ add_processing_zoekt_tasks_to_metric(row)
139
+ end
140
+ results[:repositories_schema_version_query_result]&.each do |row|
141
+ add_zoekt_repositories_by_schema_version_to_metric(row)
85
142
  end
86
143
 
87
144
  self
@@ -89,6 +146,24 @@ module GitLab
89
146
  self
90
147
  end
91
148
 
149
+ def add_processing_zoekt_tasks_to_metric(row)
150
+ @metrics.add(
151
+ "search_zoekt_task_processing_queue_size",
152
+ row["task_count"].to_i,
153
+ node_name: row["node_name"],
154
+ node_id: row["node_id"]
155
+ )
156
+ end
157
+
158
+ def add_zoekt_repositories_by_schema_version_to_metric(row)
159
+ @metrics.add(
160
+ "search_zoekt_repositories_schema_version_count",
161
+ row[:unfinished_repository_count].to_i,
162
+ target_schema_version: row[:target_schema_version],
163
+ zoekt_node_id: row[:zoekt_node_id]
164
+ )
165
+ end
166
+
92
167
  def write_to(target)
93
168
  target.write(@metrics.to_s)
94
169
  end
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "16.1.0".freeze
3
+ VERSION = "16.2.0".freeze
4
4
  end
5
5
  end
@@ -4,8 +4,13 @@ require "gitlab_exporter/database/zoekt"
4
4
  describe GitLab::Exporter::Database::ZoektCollector do
5
5
  let(:connection_pool) { double("connection pool") }
6
6
  let(:connection) { double("connection") }
7
- let(:query) { described_class::QUERY }
7
+ let(:zoekt_tasks_processing_query) { described_class::ZOEKT_TASKS_PROCESSING_QUERY }
8
+ let(:zoekt_nodes_query) { described_class::ZOEKT_NODES_QUERY }
9
+ let(:zoekt_nodes_query_results) { [{ "id" => "1", "schema_version" => "2302" }] }
8
10
  let(:zoekt_enabled_query) { described_class::ZOEKT_ENABLED_QUERY }
11
+ let(:zoekt_repository_schema_version_query) { described_class::ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY }
12
+
13
+ let(:zoekt_repository_schema_version_query_results) { [{ "count" => "1" }] }
9
14
 
10
15
  subject(:collector) { described_class.new(connection_string: "host=localhost") }
11
16
 
@@ -26,13 +31,24 @@ describe GitLab::Exporter::Database::ZoektCollector do
26
31
  describe "#run" do
27
32
  let(:zoekt_enabled_results) {}
28
33
  let(:frozen_time) { Time.new(2023, 1, 1, 0, 0, 0, 0) }
29
- let(:query_results) do
34
+ let(:zoekt_tasks_processing_query_results) do
30
35
  [
31
36
  { "node_id" => "1", "node_name" => "zoekt-1", "task_count" => "5" },
32
37
  { "node_id" => "2", "node_name" => "zoekt-2", "task_count" => "10" }
33
38
  ]
34
39
  end
35
40
 
41
+ let(:zoekt_repositories_schema_version_query_results) do
42
+ Set.new([{ target_schema_version: "2302", zoekt_node_id: "1", unfinished_repository_count: 1 }])
43
+ end
44
+
45
+ let(:result) do
46
+ {
47
+ repositories_schema_version_query_result: zoekt_repositories_schema_version_query_results,
48
+ task_processing_query_result: zoekt_tasks_processing_query_results
49
+ }
50
+ end
51
+
36
52
  before do
37
53
  allow(Time).to receive(:now).and_return(frozen_time)
38
54
  end
@@ -42,10 +58,8 @@ describe GitLab::Exporter::Database::ZoektCollector do
42
58
  stub_zoekt_not_enabled
43
59
  end
44
60
 
45
- it "returns nil" do
46
- allow(connection).to receive(:exec_params).with(query, frozen_time).and_raise(PG::UndefinedTable)
47
-
48
- expect(collector.run).to be_nil
61
+ it "returns {}" do
62
+ expect(collector.run).to eq({})
49
63
  end
50
64
  end
51
65
 
@@ -54,25 +68,38 @@ describe GitLab::Exporter::Database::ZoektCollector do
54
68
  stub_zoekt_enabled
55
69
  end
56
70
 
57
- it "executes the query with the current time" do
58
- expect(connection).to receive(:exec_params).with(query, [frozen_time]).and_return(query_results)
71
+ it "executes the query with correct params" do
72
+ expect(connection).to receive(:exec_params).with(zoekt_tasks_processing_query, [frozen_time])
73
+ .and_return(zoekt_tasks_processing_query_results)
74
+ expect(connection).to receive(:exec_params).with(zoekt_nodes_query, [])
75
+ .and_return(zoekt_nodes_query_results)
76
+ expect(connection).to receive(:exec_params).with(zoekt_repository_schema_version_query, %w[1 2302])
77
+ .and_return(zoekt_repository_schema_version_query_results)
59
78
 
60
- expect(collector.run).to eq(query_results)
79
+ expect(collector.run).to eq(result)
61
80
  end
62
81
 
63
82
  context "when PG::UndefinedTable is raised" do
64
- it "returns nil" do
65
- allow(connection).to receive(:exec_params).with(query, [frozen_time]).and_raise(PG::UndefinedTable)
83
+ it "does not includes the key which got the exception" do
84
+ allow(connection).to receive(:exec_params).with(zoekt_tasks_processing_query, [frozen_time])
85
+ .and_raise(PG::UndefinedTable)
86
+ allow(connection).to receive(:exec_params).with(zoekt_nodes_query, [])
87
+ .and_raise(PG::UndefinedTable)
66
88
 
67
- expect(collector.run).to be_nil
89
+ expect(collector.run).to eq({})
68
90
  end
69
91
  end
70
92
 
71
93
  context "when PG::UndefinedColumn is raised" do
72
- it "returns nil" do
73
- allow(connection).to receive(:exec_params).with(query, [frozen_time]).and_raise(PG::UndefinedColumn)
74
-
75
- expect(collector.run).to be_nil
94
+ it "does not includes the key which got the exception" do
95
+ allow(connection).to receive(:exec_params).with(zoekt_tasks_processing_query, [frozen_time])
96
+ .and_return(zoekt_tasks_processing_query_results)
97
+ expect(connection).to receive(:exec_params).with(zoekt_nodes_query, [])
98
+ .and_return(zoekt_nodes_query_results)
99
+ expect(connection).to receive(:exec_params).with(zoekt_repository_schema_version_query, %w[1 2302])
100
+ .and_raise(PG::UndefinedTable)
101
+
102
+ expect(collector.run).to eq({ task_processing_query_result: zoekt_tasks_processing_query_results })
76
103
  end
77
104
  end
78
105
  end
@@ -99,10 +126,15 @@ describe GitLab::Exporter::Database::ZoektProber do
99
126
  let(:metrics) { double("PrometheusMetrics", add: nil) }
100
127
  let(:collector) { double(GitLab::Exporter::Database::ZoektCollector, run: data) }
101
128
  let(:data) do
102
- [
103
- { "node_id" => "1", "node_name" => "zoekt-1", "task_count" => "5" },
104
- { "node_id" => "2", "node_name" => "zoekt-2", "task_count" => "10" }
105
- ]
129
+ {
130
+ repositories_schema_version_query_result: Set.new(
131
+ [{ target_schema_version: "2302", zoekt_node_id: "1", unfinished_repository_count: 1 }]
132
+ ),
133
+ task_processing_query_result: [
134
+ { "node_id" => "1", "node_name" => "zoekt-1", "task_count" => "5" },
135
+ { "node_id" => "2", "node_name" => "zoekt-2", "task_count" => "10" }
136
+ ]
137
+ }
106
138
  end
107
139
 
108
140
  describe "#probe_db" do
@@ -123,7 +155,7 @@ describe GitLab::Exporter::Database::ZoektProber do
123
155
  it "adds metrics for each node" do
124
156
  expect(collector).to receive(:run).and_return(data)
125
157
 
126
- data.each do |node_data|
158
+ data[:task_processing_query_result].each do |node_data|
127
159
  expect(metrics).to receive(:add)
128
160
  .with("search_zoekt_task_processing_queue_size",
129
161
  node_data["task_count"].to_i,
@@ -131,6 +163,16 @@ describe GitLab::Exporter::Database::ZoektProber do
131
163
  node_id: node_data["node_id"])
132
164
  end
133
165
 
166
+ data[:repositories_schema_version_query_result].each do |node_data|
167
+ expect(metrics).to receive(:add)
168
+ .with(
169
+ "search_zoekt_repositories_schema_version_count",
170
+ node_data[:unfinished_repository_count].to_i,
171
+ target_schema_version: node_data[:target_schema_version],
172
+ zoekt_node_id: node_data[:zoekt_node_id]
173
+ )
174
+ end
175
+
134
176
  probe_db
135
177
  end
136
178
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.1.0
4
+ version: 16.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.3
19
+ version: 2.5.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.3
26
+ version: 2.5.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: deep_merge
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.13.4
47
+ version: 2.14.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.13.4
54
+ version: 2.14.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pg
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.1
61
+ version: 1.6.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.6.1
68
+ version: 1.6.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: puma
71
71
  requirement: !ruby/object:Gem::Requirement