Skip to content

Commit bec8913

Browse files
Clemens BeckRobert Marshall
Clemens Beck
authored and
Robert Marshall
committed
Remove redundant postgres exporter custom queries
Postgres-exporter 13.0 moved queries from the default queries.yaml to collectors. The newly implemented collectors conflict with the custom queries.yaml from Omnibus, causing errors like: ``` An error has occurred while serving metrics: collected metric pg_replication_is_replica gauge:{value:0} has help "Indicates if the server is a replica" but should have "Indicates if this host is a slave" ``` Upstream MR: prometheus-community/postgres_exporter#801 Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8164 Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8112 Changelog: fixed
1 parent c74c850 commit bec8913

File tree

6 files changed

+34
-106
lines changed

6 files changed

+34
-106
lines changed

files/gitlab-config-template/gitlab.rb.template

+4-2
Original file line numberDiff line numberDiff line change
@@ -2287,14 +2287,16 @@ external_url 'GENERATED_EXTERNAL_URL'
22872287
# postgres_exporter['home'] = '/var/opt/gitlab/postgres-exporter'
22882288
# postgres_exporter['log_directory'] = '/var/log/gitlab/postgres-exporter'
22892289
# postgres_exporter['log_group'] = nil
2290-
# postgres_exporter['flags'] = {}
2290+
# postgres_exporter['flags'] = {
2291+
# 'collector.stat_user_tables' => false,
2292+
# 'collector.postmaster' => true
2293+
# }
22912294
# postgres_exporter['listen_address'] = 'localhost:9187'
22922295
# postgres_exporter['env_directory'] = '/opt/gitlab/etc/postgres-exporter/env'
22932296
# postgres_exporter['env'] = {
22942297
# 'SSL_CERT_DIR' => "/opt/gitlab/embedded/ssl/certs/"
22952298
# }
22962299
# postgres_exporter['sslmode'] = nil
2297-
# postgres_exporter['per_table_stats'] = false
22982300

22992301
##! Service name used to register Postgres Exporter as a Consul service
23002302
# postgres_exporter['consul_service_name'] = 'postgres-exporter'

files/gitlab-cookbooks/monitoring/attributes/default.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@
8484
default['monitoring']['postgres_exporter']['env'] = {
8585
'SSL_CERT_DIR' => "#{node['package']['install-dir']}/embedded/ssl/certs/"
8686
}
87+
default['monitoring']['postgres_exporter']['flags'] = {
88+
'collector.stat_user_tables' => false,
89+
'collector.postmaster' => true
90+
}
8791
default['monitoring']['postgres_exporter']['sslmode'] = nil
88-
default['monitoring']['postgres_exporter']['per_table_stats'] = false
92+
default['monitoring']['postgres_exporter']['per_table_stats'] = nil
8993
default['monitoring']['postgres_exporter']['consul_service_name'] = 'postgres-exporter'
9094
default['monitoring']['postgres_exporter']['consul_service_meta'] = nil
9195

files/gitlab-cookbooks/monitoring/recipes/postgres-exporter.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
node.default['monitoring']['postgres_exporter']['env']['DATA_SOURCE_NAME'] = "#{postgres_exporter_connection_string} " \
3737
"database=#{postgres_exporter_database}"
38-
38+
deprecated_per_table_stats = node['monitoring']['postgres_exporter']['per_table_stats']
39+
node.override['monitoring']['postgres_exporter']['flags']['collector.stat_user_tables'] = deprecated_per_table_stats unless deprecated_per_table_stats.nil?
3940
include_recipe 'postgresql::user'
4041

4142
# Create log_directory

files/gitlab-cookbooks/monitoring/templates/postgres-queries.yaml.erb

-94
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,3 @@
1-
pg_replication:
2-
query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::INT as lag, CASE WHEN pg_is_in_recovery() THEN 1 ELSE 0 END as is_replica"
3-
metrics:
4-
- lag:
5-
usage: "GAUGE"
6-
description: "Replication lag behind master in seconds"
7-
- is_replica:
8-
usage: "GAUGE"
9-
description: "Indicates if this host is a slave"
10-
11-
pg_postmaster:
12-
query: "SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time()"
13-
metrics:
14-
- start_time_seconds:
15-
usage: "GAUGE"
16-
description: "Time at which postmaster started"
17-
18-
<% if node['monitoring']['postgres_exporter']['per_table_stats'] -%>
19-
pg_stat_user_tables:
20-
query: |
21-
SELECT
22-
current_database() datname,
23-
schemaname,
24-
relname,
25-
seq_scan,
26-
seq_tup_read,
27-
idx_scan,
28-
idx_tup_fetch,
29-
n_tup_ins,
30-
n_tup_upd,
31-
n_tup_del,
32-
n_tup_hot_upd,
33-
n_live_tup,
34-
n_dead_tup,
35-
GREATEST(last_autovacuum, last_vacuum, '1970-01-01Z') as last_vacuum,
36-
GREATEST(last_autoanalyze, last_analyze, '1970-01-01Z') as last_analyze,
37-
(vacuum_count + autovacuum_count) as vacuum_count,
38-
(analyze_count + autoanalyze_count) as analyze_count
39-
FROM
40-
pg_stat_user_tables
41-
metrics:
42-
- datname:
43-
usage: "LABEL"
44-
description: "Name of current database"
45-
- schemaname:
46-
usage: "LABEL"
47-
description: "Name of the schema that this table is in"
48-
- relname:
49-
usage: "LABEL"
50-
description: "Name of this table"
51-
- seq_scan:
52-
usage: "COUNTER"
53-
description: "Number of sequential scans initiated on this table"
54-
- seq_tup_read:
55-
usage: "COUNTER"
56-
description: "Number of live rows fetched by sequential scans"
57-
- idx_scan:
58-
usage: "COUNTER"
59-
description: "Number of index scans initiated on this table"
60-
- idx_tup_fetch:
61-
usage: "COUNTER"
62-
description: "Number of live rows fetched by index scans"
63-
- n_tup_ins:
64-
usage: "COUNTER"
65-
description: "Number of rows inserted"
66-
- n_tup_upd:
67-
usage: "COUNTER"
68-
description: "Number of rows updated"
69-
- n_tup_del:
70-
usage: "COUNTER"
71-
description: "Number of rows deleted"
72-
- n_tup_hot_upd:
73-
usage: "COUNTER"
74-
description: "Number of rows HOT updated (i.e., with no separate index update required)"
75-
- n_live_tup:
76-
usage: "GAUGE"
77-
description: "Estimated number of live rows"
78-
- n_dead_tup:
79-
usage: "GAUGE"
80-
description: "Estimated number of dead rows"
81-
- last_vacuum:
82-
usage: "GAUGE"
83-
description: "Last time at which this table was vacuumed (not counting VACUUM FULL)"
84-
- last_analyze:
85-
usage: "GAUGE"
86-
description: "Last time at which this table was analyzed"
87-
- vacuum_count:
88-
usage: "COUNTER"
89-
description: "Number of times this table has been vacuumed"
90-
- analyze_count:
91-
usage: "COUNTER"
92-
description: "Number of times this table has been analyzed"
93-
94-
<% end -%>
951
pg_total_relation_size:
962
query: |
973
SELECT relnamespace::regnamespace as schemaname,

files/gitlab-cookbooks/package/libraries/deprecations.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,13 @@ def list(existing_config = nil)
337337
deprecation: '15.9',
338338
removal: '17.0',
339339
note: "Starting with GitLab 17.0, running Sidekiq with negate (`sidekiq['negate'] = true`) will be removed. We recommend to follow the steps at https://docs.gitlab.com/ee/administration/sidekiq/extra_sidekiq_processes.html#start-multiple-processes, to run Sidekiq with multiple processes while listening to all queues."
340-
}
340+
},
341+
{
342+
config_keys: %w(postgres_exporter per_table_stats),
343+
deprecation: '16.4', # Remove message issue: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8170
344+
removal: '17.0', # Removal issue: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8169
345+
note: "Starting with GitLab 17.0, this directive will be controlled by `postgres_exporter['flags'] = { 'collector.stat_user_tables' => bool }`."
346+
},
341347
]
342348

343349
deprecations += praefect_legacy_configuration_deprecations

spec/chef/cookbooks/monitoring/recipes/postgres_exporter_spec.rb

+16-7
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
it 'creates the queries.yaml file' do
9999
expect(chef_run).to render_file('/var/opt/gitlab/postgres-exporter/queries.yaml')
100100
.with_content { |content|
101-
expect(content).to match(/pg_replication:/)
102-
expect(content).not_to match(/pg_stat_user_table:/)
101+
expect(content).to match(/pg_total_relation_size:/)
102+
expect(content).to match(/pg_blocked:/)
103103
}
104104
end
105105

@@ -110,6 +110,13 @@
110110
expect(content).to match(/extend.query-path=\/var\/opt\/gitlab\/postgres-exporter\/queries.yaml/)
111111
}
112112
end
113+
114+
it 'does disable user stats' do
115+
expect(chef_run).to render_file('/opt/gitlab/sv/postgres-exporter/run')
116+
.with_content { |content|
117+
expect(content).to match(/no-collector.stat_user_tables/)
118+
}
119+
end
113120
end
114121

115122
context 'when enabled and run as an isolated recipe' do
@@ -164,11 +171,6 @@
164171
.with_content(/some.flag=foo/)
165172
end
166173

167-
it 'creates the queries.yaml file' do
168-
expect(chef_run).to render_file('/var/opt/gitlab/postgres-exporter/queries.yaml')
169-
.with_content(/pg_stat_user_tables:/)
170-
end
171-
172174
it 'creates necessary env variable files' do
173175
expect(chef_run).to create_env_dir('/opt/gitlab/etc/postgres-exporter/env').with_variables(
174176
default_vars.merge(
@@ -180,6 +182,13 @@
180182
)
181183
)
182184
end
185+
186+
it 'does not disable user stats' do
187+
expect(chef_run).to render_file('/opt/gitlab/sv/postgres-exporter/run')
188+
.with_content { |content|
189+
expect(content).not_to match(/no-collector.stat_user_tables/)
190+
}
191+
end
183192
end
184193

185194
context 'log directory and runit group' do

0 commit comments

Comments
 (0)