gitlab-exporter 17.0.1 → 17.0.2

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: 15b0fdb50984859832e6a21dcb76c31dfbfb68f28e5601f2c1389782ea4b5f2f
4
- data.tar.gz: a02d8bda949c2d5f94981d50123ff845e73d958306d0bcf9e3ca0cfd4c8107e5
3
+ metadata.gz: 0f38401d83375e243787b0f692035d11cc9cc9e5a3bde34ca9d468261be12a41
4
+ data.tar.gz: 4f8f1dbed6854da6003209745214b6687f405145b79c5dc2a0ee06d0bbedec4f
5
5
  SHA512:
6
- metadata.gz: ab40fc6975a31c6175cb3139dd1e576a06f7f1a6b598efc387f76228e68413a47b7902d7aca1682128ee77dd76ee4f2e178fec7bed8dc027676ec2e614289490
7
- data.tar.gz: e749cdfd3a8db77f8a594ad7007db5dc919003defa0afb7c3691a461b78d0bcdf459e8bce6d5106809f0cdc567323a968fe1d8de88c990a2c5074339b6c38343
6
+ metadata.gz: 7c88e061a15dcc9f640c29a910de6d81eedb345c113bce789b08a44a252ddc708bdb082e5aa7ee881eb383dcf51c72d34fd7ec8c00353fe210e0b97915e05ab4
7
+ data.tar.gz: 9a26c277997d178c65607aadbba2b82b931bc1375a1f732c35665639cfb1a404869409272f85b640df8a5f101cf25eddee985c1f20dbb8d75f6904aaffd1e7c6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-exporter (17.0.1)
4
+ gitlab-exporter (17.0.2)
5
5
  base64 (= 0.3.0)
6
6
  connection_pool (= 2.5.5)
7
7
  deep_merge (~> 1.2.2)
data/README.md CHANGED
@@ -23,9 +23,10 @@ metrics.
23
23
  `gitlab_pg_sequences_min_value`, `gitlab_pg_sequences_max_value`, `gitlab_pg_sequences_current_value`
24
24
  * [Row count queries](lib/gitlab_exporter/database/row_count.rb) --
25
25
  `gitlab_database_rows`
26
- * [CI builds](lib/gitlab_exporter/database/ci_builds.rb) --
26
+ * [CI builds](lib/gitlab_exporter/database/ci_builds.rb) (**deprecated**) --
27
27
  `ci_pending_builds`, `ci_created_builds`, `ci_stale_builds`,
28
- `ci_running_builds`
28
+ `ci_running_builds`, `ci_unarchived_traces`
29
+ (see [Deprecated: CI builds metrics](#deprecated-ci-builds-metrics))
29
30
  * [Bloat](lib/gitlab_exporter/database/bloat.rb) --
30
31
  `gitlab_database_bloat_$type_$key` with type `btree` (index bloat) or `table`
31
32
  (table bloat) and keys `bloat_ratio bloat_size extra_size real_size` (see below)
@@ -133,6 +134,57 @@ Also see the [original documentation](https://github.com/ioguix/pgsql-bloat-esti
133
134
  Note that all metrics returned are estimates without an upper bound for
134
135
  the error.
135
136
 
137
+ ### Deprecated: CI builds metrics
138
+
139
+ The [CI builds probe](lib/gitlab_exporter/database/ci_builds.rb) is deprecated and
140
+ will be removed in a future major version. It collects its metrics by querying
141
+ `p_ci_builds` directly, which puts avoidable load on tables that job scheduling
142
+ already loads heavily, and it has had almost no maintenance since 2021. GitLab
143
+ Rails and GitLab Runner instrument most of the same information by counting
144
+ events as they happen; GitLab.com stopped using this probe for CI state years
145
+ ago.
146
+
147
+ The probe prints a deprecation notice on every run, and each of its metrics
148
+ carries `(deprecated, ...)` in its `# HELP` line, so the warning reaches
149
+ Prometheus and Grafana and not only the exporter's log.
150
+
151
+ Replacements, where one exists:
152
+
153
+ | Deprecated metric | Replacement |
154
+ | --- | --- |
155
+ | `ci_pending_builds` | `gitlab_ci_current_queue_size` (Rails, gauge, by `runner_type`) |
156
+ | `ci_running_builds` | `gitlab_runner_jobs` (Runner, gauge, by `runner`, `state`, `stage`) |
157
+ | `ci_created_builds` | None. A `created` build is not queued yet, so nothing counts it. |
158
+ | `ci_stale_builds` | None. The nearest signal is `gitlab_ci_queue_operations_total{operation="build_status_stale"}` (Rails, counter), which counts stale rows met while queueing rather than how many are stale now. |
159
+ | `ci_unarchived_traces` | None. |
160
+
161
+ The replacements are not a like-for-like relabel: the Rails queue metrics are
162
+ keyed by `runner_type` and the Runner metrics by runner, so neither carries the
163
+ `namespace` label this probe reports. Queue health is better served by the Rails
164
+ metrics that have no exporter equivalent at all -- `job_queue_duration_seconds`
165
+ (how long jobs wait), `job_register_attempts_total` and
166
+ `job_register_attempts_failed_total`, and `gitlab_ci_queue_operations_total`.
167
+ Those four are always instrumented.
168
+
169
+ **`gitlab_ci_current_queue_size`, and every other `gitlab_ci_queue_*` metric, is
170
+ behind the `gitlab_ci_builds_queuing_metrics` ops feature flag, which is disabled
171
+ by default.** Enable it before pointing a dashboard at them, or the replacement
172
+ panels stay empty:
173
+
174
+ ```ruby
175
+ Feature.enable(:gitlab_ci_builds_queuing_metrics)
176
+ ```
177
+
178
+ Metric definitions live in
179
+ [`lib/gitlab/ci/queue/metrics.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/queue/metrics.rb)
180
+ (Rails) and
181
+ [`commands/builds_helper.go`](https://gitlab.com/gitlab-org/gitlab-runner/-/blob/main/commands/builds_helper.go)
182
+ (Runner). See
183
+ [GitLab Prometheus metrics](https://docs.gitlab.com/administration/monitoring/prometheus/gitlab_metrics/)
184
+ for enabling the Rails exporter, and
185
+ [Monitoring runners](https://docs.gitlab.com/runner/monitoring/) for the
186
+ Runner's.
187
+
136
188
  ## Contributing
137
189
 
138
190
  gitlab-exporter is an open source project and we are very happy to accept community contributions. Please refer to [CONTRIBUTING.md](/CONTRIBUTING.md) for details.
@@ -294,12 +294,53 @@ module GitLab
294
294
 
295
295
  # The prober which is called when gathering metrics
296
296
  class CiBuildsProber
297
+ # The stdout notice in #probe_db reaches whoever reads the exporter's log,
298
+ # which is not who reads the metrics. HELP is the one channel that travels
299
+ # with the sample to the scraper, so the deprecation rides there too: it
300
+ # survives into Prometheus and shows up in Grafana's metric browser.
301
+ DEPRECATED = "(deprecated, to be removed in a future major version)".freeze
302
+ REPLACEMENT = "See the CI builds entry in README.md for replacements.".freeze
303
+
304
+ PrometheusMetrics.describe(
305
+ "ci_created_builds",
306
+ "#{DEPRECATED} Number of CI builds in the created state, by namespace. #{REPLACEMENT}",
307
+ "gauge"
308
+ )
309
+
310
+ PrometheusMetrics.describe(
311
+ "ci_pending_builds",
312
+ "#{DEPRECATED} Number of CI builds in the pending state, by namespace. #{REPLACEMENT}",
313
+ "gauge"
314
+ )
315
+
316
+ PrometheusMetrics.describe(
317
+ "ci_stale_builds",
318
+ "#{DEPRECATED} Number of running CI builds not updated for over an hour. #{REPLACEMENT}",
319
+ "gauge"
320
+ )
321
+
322
+ PrometheusMetrics.describe(
323
+ "ci_running_builds",
324
+ "#{DEPRECATED} Number of running CI builds, by runner and namespace. #{REPLACEMENT}",
325
+ "gauge"
326
+ )
327
+
328
+ PrometheusMetrics.describe(
329
+ "ci_unarchived_traces",
330
+ "#{DEPRECATED} Number of finished CI builds whose trace is not archived. #{REPLACEMENT}",
331
+ "gauge"
332
+ )
333
+
297
334
  def initialize(metrics: PrometheusMetrics.new, **opts)
298
335
  @metrics = metrics
299
336
  @collector = CiBuildsCollector.new(**opts)
300
337
  end
301
338
 
302
339
  def probe_db
340
+ puts "[DEPRECATED] probe_db and CiBuildsProber are now considered obsolete"\
341
+ " and will be removed in a future major version,"\
342
+ " please use the CI/CD queuing metrics emitted by GitLab Rails instead"
343
+
303
344
  @results = @collector.run
304
345
 
305
346
  ci_builds_metrics(@results[:created_builds], "ci_created_builds") if @results[:created_builds]
@@ -1,5 +1,5 @@
1
1
  module GitLab
2
2
  module Exporter
3
- VERSION = "17.0.1".freeze
3
+ VERSION = "17.0.2".freeze
4
4
  end
5
5
  end
@@ -361,3 +361,55 @@ describe GitLab::Exporter::Database do
361
361
  end
362
362
  end
363
363
  end
364
+
365
+ # Asserting on the notice keeps a later refactor of #probe_db from dropping it
366
+ # silently, which would leave operators unwarned before the probe goes (issue #119).
367
+ describe GitLab::Exporter::Database::CiBuildsProber do
368
+ let(:prober) do
369
+ described_class.new(connection_string: "host=localhost",
370
+ metrics: GitLab::Exporter::PrometheusMetrics.new(include_timestamp: false))
371
+ end
372
+
373
+ let(:metric_names) do
374
+ %w[ci_created_builds ci_pending_builds ci_stale_builds ci_running_builds ci_unarchived_traces]
375
+ end
376
+
377
+ it "warns that the probe is deprecated and names the replacement" do
378
+ allow_any_instance_of(GitLab::Exporter::Database::CiBuildsCollector).to receive(:run)
379
+ .and_return(pending_builds: [], stale_builds: 0, per_runner: [], unarchived_traces: 0)
380
+
381
+ expect { prober.probe_db }.to output(/\[DEPRECATED\].*CiBuildsProber.*GitLab Rails/m).to_stdout
382
+ end
383
+
384
+ # The stdout notice never reaches the scraper. HELP does, so every metric the
385
+ # probe can emit has to carry the deprecation, not just the ones with a
386
+ # replacement.
387
+ it "describes every metric it can emit as deprecated" do
388
+ metric_names.each do |name|
389
+ expect(GitLab::Exporter::PrometheusMetrics.description(name))
390
+ .to start_with("(deprecated"), "#{name} is emitted without a deprecated HELP line"
391
+ expect(GitLab::Exporter::PrometheusMetrics.metric_type(name)).to eq("gauge")
392
+ end
393
+ end
394
+
395
+ it "renders the deprecation into the scrape output" do
396
+ allow_any_instance_of(GitLab::Exporter::Database::CiBuildsCollector).to receive(:run)
397
+ .and_return(pending_builds: [{ namespace: "1", shared_runners: "yes", value: 12 }],
398
+ stale_builds: 3, per_runner: [], unarchived_traces: 0)
399
+
400
+ output = StringIO.new
401
+ capture_stdout do prober.probe_db.write_to(output) end
402
+
403
+ expect(output.string).to include("# HELP ci_pending_builds (deprecated")
404
+ expect(output.string).to include("# TYPE ci_pending_builds gauge")
405
+ expect(output.string).to include(%(ci_pending_builds{namespace="1",shared_runners="yes"} 12.0))
406
+ end
407
+
408
+ def capture_stdout
409
+ original = $stdout
410
+ $stdout = StringIO.new
411
+ yield
412
+ ensure
413
+ $stdout = original
414
+ end
415
+ end
@@ -29,15 +29,29 @@ describe GitLab::Exporter::PrometheusMetrics do
29
29
 
30
30
  allow(Time).to receive(:now).and_return(time)
31
31
 
32
- described_class.describe("mymetric", "description")
33
- described_class.describe("missingmetric", "otherdescription")
34
- subject.add("mymetric", 1.3, mylabel: "x", myotherlabel: "y")
35
-
36
- expect(subject.to_s).to eq(<<~METRICS)
32
+ # Descriptions are class-level state, and probes register theirs when their
33
+ # file loads, which happens once. Describing on a subclass keeps this example
34
+ # out of the shared registry: clearing it here would drop those registrations
35
+ # for every later example, and nothing can put them back.
36
+ metrics_class = Class.new(described_class)
37
+ metrics = metrics_class.new
38
+
39
+ metrics_class.describe("mymetric", "description")
40
+ metrics_class.describe("missingmetric", "otherdescription")
41
+ metrics.add("mymetric", 1.3, mylabel: "x", myotherlabel: "y")
42
+
43
+ expect(metrics.to_s).to eq(<<~METRICS)
37
44
  # HELP mymetric description
38
45
  mymetric{mylabel="x",myotherlabel="y"} 1.3 #{(time.to_f * 1000).to_i}
39
46
  METRICS
47
+ end
48
+
49
+ it "clears descriptions" do
50
+ metrics_class = Class.new(described_class)
51
+ metrics_class.describe("mymetric", "description", "gauge")
40
52
 
41
- described_class.clear_descriptions
53
+ expect { metrics_class.clear_descriptions }
54
+ .to change { metrics_class.description("mymetric") }.from("description").to(nil)
55
+ expect(metrics_class.metric_type("mymetric")).to be_nil
42
56
  end
43
57
  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: 17.0.1
4
+ version: 17.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Carranza