gitlab-exporter 16.4.1 → 16.5.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: ddf051049df2fc97f6075da3453f40c99dbd5924613e52f7613f68f4061369d1
4
- data.tar.gz: 2e5d19430d6de12d9ef679a74719e0047671955edf2a7a5cfbfa16128920493e
3
+ metadata.gz: 2ccb9b4710efb99847099a897fd1b8459c0d3e8d835b6f2ab4e8569d0a565242
4
+ data.tar.gz: c04beba06c2aa5866f5c09faf93f44cd14d01a0e5e174004ccaf81f8f9ba1171
5
5
  SHA512:
6
- metadata.gz: 62fe67971ee82117f04fa6189867450469f67ba2818719ec4f0bec39a601cce5a47bfcecbaab02ce22c4f07fd16094a8e12d6fee258611555fd6f2605ae3f209
7
- data.tar.gz: 706d36baae273e77e2211ade5dec5848316f1d5a473c33aa89e7e11ce20814bc5ffbd83735f3f20c1090c072b4fed5f4f056ab2472c2bd1ef2096b08f018151c
6
+ metadata.gz: ff2ca3937e3b3beebfdc5bf60cb967e16384ed50de585610aec8a86c5e2f985b35eba1f8108d99fad7fb7972b4683496e1cc70f17a791ec9847977f41613fe7e
7
+ data.tar.gz: 55d3cb8d8b971124f8f170a061efa23348f506477829cd59f2f7d9a7fc3902a04fc297b06c6638818b7283121106ab8e53bdfea75be00c05773f9a597ce7d1e5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (16.4.1)
4
+ gitlab-exporter (16.5.0)
5
5
  connection_pool (= 2.5.5)
6
6
  deep_merge (~> 1.2.2)
7
7
  faraday (= 2.14.0)
@@ -62,13 +62,23 @@ module GitLab
62
62
  LIMIT 1
63
63
  SQL
64
64
 
65
+ ZOEKT_NODE_STORAGE_QUERY = <<~SQL.freeze
66
+ SELECT
67
+ id,
68
+ metadata ->> 'name' AS node_name,
69
+ unclaimed_storage_bytes,
70
+ storage_percent_used
71
+ FROM zoekt_nodes
72
+ SQL
73
+
65
74
  def run
66
75
  return {} unless zoekt_indexing_enabled?
67
76
 
68
77
  {
69
78
  task_processing_query_result: execute(ZOEKT_TASKS_PROCESSING_QUERY, [Time.now.utc]),
70
79
  repositories_schema_version_query_result: repositories_schema_version_query_result,
71
- zoekt_nodes_status_query_result: execute(ZOEKT_NODES_STATUS_QUERY)
80
+ zoekt_nodes_status_query_result: execute(ZOEKT_NODES_STATUS_QUERY),
81
+ node_storage_query_result: execute(ZOEKT_NODE_STORAGE_QUERY)
72
82
  }.compact
73
83
  end
74
84
 
@@ -150,6 +160,18 @@ module GitLab
150
160
  "gauge"
151
161
  )
152
162
 
163
+ PrometheusMetrics.describe(
164
+ "search_zoekt_node_unclaimed_storage_bytes",
165
+ "Unclaimed storage bytes for Zoekt node",
166
+ "gauge"
167
+ )
168
+
169
+ PrometheusMetrics.describe(
170
+ "search_zoekt_node_storage_percent_used",
171
+ "Fraction of storage used on Zoekt node (0..1)",
172
+ "gauge"
173
+ )
174
+
153
175
  def initialize(metrics: PrometheusMetrics.new, **opts)
154
176
  @metrics = metrics
155
177
  @collector = opts[:collector] || ZoektCollector.new(**opts)
@@ -157,21 +179,40 @@ module GitLab
157
179
 
158
180
  def probe_db
159
181
  results = @collector.run
160
- results[:task_processing_query_result].to_a.each do |row|
161
- add_processing_zoekt_tasks_to_metric(row)
162
- end
163
- results[:repositories_schema_version_query_result]&.each do |row|
164
- add_zoekt_repositories_by_schema_version_to_metric(row)
165
- end
166
- results[:zoekt_nodes_status_query_result]&.each do |row|
167
- add_zoekt_nodes_status_to_metric(row)
168
- end
169
-
182
+ process_results(results)
170
183
  self
171
184
  rescue PG::ConnectionBad
172
185
  self
173
186
  end
174
187
 
188
+ private
189
+
190
+ def process_results(results)
191
+ process_task_results(results[:task_processing_query_result])
192
+ process_repository_results(results[:repositories_schema_version_query_result])
193
+ process_node_status_results(results[:zoekt_nodes_status_query_result])
194
+ process_node_storage_results(results[:node_storage_query_result])
195
+ end
196
+
197
+ def process_task_results(results)
198
+ results.to_a.each { |row| add_processing_zoekt_tasks_to_metric(row) }
199
+ end
200
+
201
+ def process_repository_results(results)
202
+ results&.each { |row| add_zoekt_repositories_by_schema_version_to_metric(row) }
203
+ end
204
+
205
+ def process_node_status_results(results)
206
+ results&.each { |row| add_zoekt_nodes_status_to_metric(row) }
207
+ end
208
+
209
+ def process_node_storage_results(results)
210
+ results&.each do |row|
211
+ add_zoekt_node_unclaimed_storage_to_metric(row)
212
+ add_zoekt_node_storage_percent_used_to_metric(row)
213
+ end
214
+ end
215
+
175
216
  def add_processing_zoekt_tasks_to_metric(row)
176
217
  @metrics.add(
177
218
  "search_zoekt_task_processing_queue_size",
@@ -206,6 +247,28 @@ module GitLab
206
247
  )
207
248
  end
208
249
 
250
+ def add_zoekt_node_unclaimed_storage_to_metric(row)
251
+ @metrics.add(
252
+ "search_zoekt_node_unclaimed_storage_bytes",
253
+ row["unclaimed_storage_bytes"].to_i,
254
+ **{
255
+ zoekt_node_id: row["id"],
256
+ zoekt_node_name: row["node_name"]
257
+ }.compact
258
+ )
259
+ end
260
+
261
+ def add_zoekt_node_storage_percent_used_to_metric(row)
262
+ @metrics.add(
263
+ "search_zoekt_node_storage_percent_used",
264
+ row["storage_percent_used"].to_f,
265
+ **{
266
+ zoekt_node_id: row["id"],
267
+ zoekt_node_name: row["node_name"]
268
+ }.compact
269
+ )
270
+ end
271
+
209
272
  def write_to(target)
210
273
  target.write(@metrics.to_s)
211
274
  end
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "16.4.1".freeze
3
+ VERSION = "16.5.0".freeze
4
4
  end
5
5
  end
@@ -11,6 +11,10 @@ describe GitLab::Exporter::Database::ZoektCollector do
11
11
  let(:zoekt_repository_schema_version_query) { described_class::ZOEKT_REPOSITORY_SCHEMA_VERSION_QUERY }
12
12
  let(:zoekt_nodes_status_query) { described_class::ZOEKT_NODES_STATUS_QUERY }
13
13
  let(:zoekt_nodes_status_query_results) { [{ "id" => "1", "name" => "foo", "status" => "1" }] }
14
+ let(:zoekt_node_storage_query) { described_class::ZOEKT_NODE_STORAGE_QUERY }
15
+ let(:zoekt_node_storage_query_results) do
16
+ [{ "id" => "1", "node_name" => "foo", "unclaimed_storage_bytes" => "1000000", "storage_percent_used" => "0.75" }]
17
+ end
14
18
 
15
19
  let(:zoekt_repository_schema_version_query_results) { [{ "count" => "1" }] }
16
20
 
@@ -50,7 +54,8 @@ describe GitLab::Exporter::Database::ZoektCollector do
50
54
  {
51
55
  repositories_schema_version_query_result: zoekt_repositories_schema_version_query_results,
52
56
  task_processing_query_result: zoekt_tasks_processing_query_results,
53
- zoekt_nodes_status_query_result: zoekt_nodes_status_query_results
57
+ zoekt_nodes_status_query_result: zoekt_nodes_status_query_results,
58
+ node_storage_query_result: zoekt_node_storage_query_results
54
59
  }
55
60
  end
56
61
 
@@ -82,6 +87,8 @@ describe GitLab::Exporter::Database::ZoektCollector do
82
87
  .and_return(zoekt_repository_schema_version_query_results)
83
88
  expect(connection).to receive(:exec_params).with(zoekt_nodes_status_query, [])
84
89
  .and_return(zoekt_nodes_status_query_results)
90
+ expect(connection).to receive(:exec_params).with(zoekt_node_storage_query, [])
91
+ .and_return(zoekt_node_storage_query_results)
85
92
 
86
93
  expect(collector.run).to eq(result)
87
94
  end
@@ -94,6 +101,8 @@ describe GitLab::Exporter::Database::ZoektCollector do
94
101
  .and_raise(PG::UndefinedTable)
95
102
  allow(connection).to receive(:exec_params).with(zoekt_nodes_status_query, [])
96
103
  .and_raise(PG::UndefinedTable)
104
+ allow(connection).to receive(:exec_params).with(zoekt_node_storage_query, [])
105
+ .and_raise(PG::UndefinedTable)
97
106
 
98
107
  expect(collector.run).to eq({})
99
108
  end
@@ -108,6 +117,7 @@ describe GitLab::Exporter::Database::ZoektCollector do
108
117
  expect(connection).to receive(:exec_params).with(zoekt_repository_schema_version_query, %w[1 2302])
109
118
  .and_raise(PG::UndefinedTable)
110
119
  expect(connection).to receive(:exec_params).with(zoekt_nodes_status_query, []).and_raise(PG::UndefinedTable)
120
+ expect(connection).to receive(:exec_params).with(zoekt_node_storage_query, []).and_raise(PG::UndefinedColumn)
111
121
 
112
122
  expect(collector.run).to eq({ task_processing_query_result: zoekt_tasks_processing_query_results })
113
123
  end
@@ -143,6 +153,16 @@ describe GitLab::Exporter::Database::ZoektProber do
143
153
  task_processing_query_result: [
144
154
  { "node_id" => "1", "node_name" => "zoekt-1", "task_count" => "5" },
145
155
  { "node_id" => "2", "node_name" => "zoekt-2", "task_count" => "10" }
156
+ ],
157
+ node_storage_query_result: [
158
+ {
159
+ "id" => "1", "node_name" => "zoekt-1", "unclaimed_storage_bytes" => "1000000",
160
+ "storage_percent_used" => "0.75"
161
+ },
162
+ {
163
+ "id" => "2", "node_name" => "zoekt-2", "unclaimed_storage_bytes" => "2000000",
164
+ "storage_percent_used" => "0.50"
165
+ }
146
166
  ]
147
167
  }
148
168
  end
@@ -186,6 +206,23 @@ describe GitLab::Exporter::Database::ZoektProber do
186
206
  )
187
207
  end
188
208
 
209
+ data[:node_storage_query_result].each do |node_data|
210
+ expect(metrics).to receive(:add)
211
+ .with(
212
+ "search_zoekt_node_unclaimed_storage_bytes",
213
+ node_data["unclaimed_storage_bytes"].to_i,
214
+ zoekt_node_id: node_data["id"],
215
+ zoekt_node_name: node_data["node_name"]
216
+ )
217
+ expect(metrics).to receive(:add)
218
+ .with(
219
+ "search_zoekt_node_storage_percent_used",
220
+ node_data["storage_percent_used"].to_f,
221
+ zoekt_node_id: node_data["id"],
222
+ zoekt_node_name: node_data["node_name"]
223
+ )
224
+ end
225
+
189
226
  probe_db
190
227
  end
191
228
  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.4.1
4
+ version: 16.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza