gitlab-exporter 15.0.0 → 15.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/config/gitlab-exporter.yml.example +4 -0
- data/lib/gitlab_exporter/database/pg_sequences.rb +60 -0
- data/lib/gitlab_exporter/database.rb +1 -0
- data/lib/gitlab_exporter/version.rb +1 -1
- data/spec/database/pg_sequences_spec.rb +133 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73d7d8a42035a6cb634f0c234e6bcd3e723492f2903663d7ecd0ccacde53279c
|
4
|
+
data.tar.gz: 012ce7e6313ec24c72c605bf016477c75d6de08ec2c37339e0a12c09c64aaa23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc31a10b7051bb5c76667d817cdd2761cd9ce9b755949567770b390f4362b37722d5658300b63607ff8f2566e577786ddb6e5b8edf3263bbbba3c478d28e08e7
|
7
|
+
data.tar.gz: 96b24d081ca6172197f6bdf44b739b3d053f32f2944378bb09609a02e485a053251c752ad49c921202eeee165437284aea73f875cce06a85edc455fb2d4e573d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,9 @@ metrics.
|
|
19
19
|
1. Database
|
20
20
|
* [Per-table tuple stats](lib/gitlab_exporter/database/tuple_stats.rb) --
|
21
21
|
`gitlab_database_stat_table_*`
|
22
|
+
* [Per-sequence stats](lib/gitlab_exporter/database/pg_sequences.rb) --
|
23
|
+
`gitlab_pg_sequences_min_value`, `gitlab_pg_sequences_max_value`, `gitlab_pg_sequences_current_value`,
|
24
|
+
`gitlab_pg_sequences_saturation_ratio`
|
22
25
|
* [Row count queries](lib/gitlab_exporter/database/row_count.rb) --
|
23
26
|
`gitlab_database_rows`
|
24
27
|
* [CI builds](lib/gitlab_exporter/database/ci_builds.rb) --
|
@@ -41,6 +41,10 @@ probes:
|
|
41
41
|
class_name: Database::BloatProber
|
42
42
|
<<: *db_common
|
43
43
|
|
44
|
+
pg_sequences:
|
45
|
+
class_name: Database::PgSequencesProber
|
46
|
+
<<: *db_common
|
47
|
+
|
44
48
|
# We can group multiple probes under a single endpoint by setting the `multiple` key to `true`, followed
|
45
49
|
# by probe definitions as usual.
|
46
50
|
database:
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module GitLab
|
2
|
+
module Exporter
|
3
|
+
module Database
|
4
|
+
# A helper class to collect sequences metrics. Mainly used to monitor Cells sequences.
|
5
|
+
class PgSequencesCollector < Base
|
6
|
+
QUERY = <<~SQL.freeze
|
7
|
+
SELECT
|
8
|
+
schemaname,
|
9
|
+
sequencename,
|
10
|
+
CONCAT(schemaname, '.', sequencename) AS fully_qualified_sequencename,
|
11
|
+
start_value,
|
12
|
+
min_value,
|
13
|
+
max_value,
|
14
|
+
last_value AS current_value
|
15
|
+
FROM pg_catalog.pg_sequences;
|
16
|
+
SQL
|
17
|
+
|
18
|
+
def run
|
19
|
+
with_connection_pool do |conn|
|
20
|
+
conn.exec(QUERY).each.with_object({}) do |row, stats|
|
21
|
+
stats[row.delete("fully_qualified_sequencename")] = row
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# The prober which is called when gathering metrics
|
28
|
+
class PgSequencesProber
|
29
|
+
METRIC_NAME = "gitlab_pg_sequences".freeze
|
30
|
+
METRIC_KEYS = %w[min_value max_value current_value].freeze
|
31
|
+
|
32
|
+
def initialize(metrics: PrometheusMetrics.new, **opts)
|
33
|
+
@metrics = metrics
|
34
|
+
@collector = PgSequencesCollector.new(**opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def probe_db
|
38
|
+
result = @collector.run
|
39
|
+
|
40
|
+
result.each do |fully_qualified_sequencename, sequence_info|
|
41
|
+
METRIC_KEYS.each do |key|
|
42
|
+
value = sequence_info.fetch(key).to_f
|
43
|
+
tags = {
|
44
|
+
schemaname: sequence_info.fetch("schemaname"),
|
45
|
+
sequencename: sequence_info.fetch("sequencename"),
|
46
|
+
fully_qualified_sequencename: fully_qualified_sequencename
|
47
|
+
}
|
48
|
+
|
49
|
+
@metrics.add("#{METRIC_NAME}_#{key}", value, **tags)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
self
|
54
|
+
rescue PG::ConnectionBad
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -8,6 +8,7 @@ module GitLab
|
|
8
8
|
autoload :RowCountProber, "gitlab_exporter/database/row_count"
|
9
9
|
autoload :BloatProber, "gitlab_exporter/database/bloat"
|
10
10
|
autoload :RemoteMirrorsProber, "gitlab_exporter/database/remote_mirrors"
|
11
|
+
autoload :PgSequencesProber, "gitlab_exporter/database/pg_sequences"
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "gitlab_exporter/database/pg_sequences"
|
3
|
+
|
4
|
+
describe GitLab::Exporter::Database::PgSequencesCollector do
|
5
|
+
subject { described_class.new(connection_string: "") }
|
6
|
+
|
7
|
+
let(:connection_pool) { double("connection pool") }
|
8
|
+
let(:connection) { double("connection", exec: query_result) }
|
9
|
+
let(:type) { :btree }
|
10
|
+
let(:query_result) do
|
11
|
+
[
|
12
|
+
{
|
13
|
+
"schemaname" => "public",
|
14
|
+
"sequencename" => "seq_one",
|
15
|
+
"fully_qualified_sequencename" => "public.seq_one",
|
16
|
+
"min_value" => 1,
|
17
|
+
"max_value" => 9_223_372_036_854_775_807,
|
18
|
+
"current_value" => 6_223_372_036_854_745_121,
|
19
|
+
"saturation_ratio" => 0.6747e2
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"schemaname" => "public",
|
23
|
+
"sequencename" => "seq_two",
|
24
|
+
"fully_qualified_sequencename" => "public.seq_two",
|
25
|
+
"min_value" => 1,
|
26
|
+
"max_value" => 9_223_372_036_854_775_807,
|
27
|
+
"current_value" => nil,
|
28
|
+
"saturation_ratio" => 0.0
|
29
|
+
}
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow_any_instance_of(described_class).to receive(:connection_pool).and_return(connection_pool)
|
35
|
+
allow(connection_pool).to receive(:with).and_yield(connection)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "converts query results into a hash" do
|
39
|
+
expect(subject.run).to(
|
40
|
+
eq(
|
41
|
+
"public.seq_one" => {
|
42
|
+
"schemaname" => "public",
|
43
|
+
"sequencename" => "seq_one",
|
44
|
+
"min_value" => 1,
|
45
|
+
"max_value" => 9_223_372_036_854_775_807,
|
46
|
+
"current_value" => 6_223_372_036_854_745_121,
|
47
|
+
"saturation_ratio" => 0.6747e2
|
48
|
+
},
|
49
|
+
"public.seq_two" => {
|
50
|
+
"schemaname" => "public",
|
51
|
+
"sequencename" => "seq_two",
|
52
|
+
"min_value" => 1,
|
53
|
+
"max_value" => 9_223_372_036_854_775_807,
|
54
|
+
"current_value" => nil,
|
55
|
+
"saturation_ratio" => 0.0
|
56
|
+
}
|
57
|
+
)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe GitLab::Exporter::Database::PgSequencesProber do
|
63
|
+
subject(:prober) { described_class.new(metrics: metrics, connection_string: "") }
|
64
|
+
|
65
|
+
let(:metrics) { double("PrometheusMetrics", add: nil) }
|
66
|
+
let(:collector) { double("PgSequencesCollector", run: data) }
|
67
|
+
let(:data) do
|
68
|
+
{
|
69
|
+
"public.seq_one" => {
|
70
|
+
"schemaname" => "public",
|
71
|
+
"sequencename" => "seq_one",
|
72
|
+
"min_value" => 1,
|
73
|
+
"max_value" => 10,
|
74
|
+
"current_value" => 2,
|
75
|
+
"saturation_ratio" => 0.2
|
76
|
+
}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#probe_db" do
|
81
|
+
before do
|
82
|
+
allow(GitLab::Exporter::Database::PgSequencesCollector).to receive(:new).and_return(collector)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "properly invokes the collector" do
|
86
|
+
expect(collector).to receive(:run)
|
87
|
+
|
88
|
+
prober.probe_db
|
89
|
+
end
|
90
|
+
|
91
|
+
it "adds min_value metric" do
|
92
|
+
expect(metrics).to(
|
93
|
+
receive(:add).with(
|
94
|
+
"gitlab_pg_sequences_min_value",
|
95
|
+
1.0,
|
96
|
+
schemaname: "public",
|
97
|
+
sequencename: "seq_one",
|
98
|
+
fully_qualified_sequencename: "public.seq_one"
|
99
|
+
)
|
100
|
+
)
|
101
|
+
|
102
|
+
prober.probe_db
|
103
|
+
end
|
104
|
+
|
105
|
+
it "adds max_value metric" do
|
106
|
+
expect(metrics).to(
|
107
|
+
receive(:add).with(
|
108
|
+
"gitlab_pg_sequences_max_value",
|
109
|
+
10.0,
|
110
|
+
schemaname: "public",
|
111
|
+
sequencename: "seq_one",
|
112
|
+
fully_qualified_sequencename: "public.seq_one"
|
113
|
+
)
|
114
|
+
)
|
115
|
+
|
116
|
+
prober.probe_db
|
117
|
+
end
|
118
|
+
|
119
|
+
it "adds current_value metric" do
|
120
|
+
expect(metrics).to(
|
121
|
+
receive(:add).with(
|
122
|
+
"gitlab_pg_sequences_current_value",
|
123
|
+
2.0,
|
124
|
+
schemaname: "public",
|
125
|
+
sequencename: "seq_one",
|
126
|
+
fully_qualified_sequencename: "public.seq_one"
|
127
|
+
)
|
128
|
+
)
|
129
|
+
|
130
|
+
prober.probe_db
|
131
|
+
end
|
132
|
+
end
|
133
|
+
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: 15.
|
4
|
+
version: 15.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Carranza
|
@@ -227,6 +227,7 @@ files:
|
|
227
227
|
- lib/gitlab_exporter/database/bloat_btree.sql
|
228
228
|
- lib/gitlab_exporter/database/bloat_table.sql
|
229
229
|
- lib/gitlab_exporter/database/ci_builds.rb
|
230
|
+
- lib/gitlab_exporter/database/pg_sequences.rb
|
230
231
|
- lib/gitlab_exporter/database/remote_mirrors.rb
|
231
232
|
- lib/gitlab_exporter/database/row_count.rb
|
232
233
|
- lib/gitlab_exporter/database/tuple_stats.rb
|
@@ -247,6 +248,7 @@ files:
|
|
247
248
|
- spec/cli_spec.rb
|
248
249
|
- spec/database/bloat_spec.rb
|
249
250
|
- spec/database/ci_builds_spec.rb
|
251
|
+
- spec/database/pg_sequences_spec.rb
|
250
252
|
- spec/database/row_count_spec.rb
|
251
253
|
- spec/elasticsearch_spec.rb
|
252
254
|
- spec/fixtures/config.yml
|
@@ -286,6 +288,7 @@ test_files:
|
|
286
288
|
- spec/cli_spec.rb
|
287
289
|
- spec/database/bloat_spec.rb
|
288
290
|
- spec/database/ci_builds_spec.rb
|
291
|
+
- spec/database/pg_sequences_spec.rb
|
289
292
|
- spec/database/row_count_spec.rb
|
290
293
|
- spec/elasticsearch_spec.rb
|
291
294
|
- spec/fixtures/config.yml
|