Add postgres_exporter queries depending on postgres version
Overview
At the moment we are running different versions of Postgres in staging (v14) and production (v12) and when we do Postgres upgrades we always do that. We have postgres_exporter which runs queries on the database to expose Prometheus metrics. Sometimes the columns change between major versions as it did in v14, we've opened gitlab-cookbooks/gitlab-exporters!296 (diffs) to fix this problem. However we can't merge this version in production because production is still using v12.
This leaves us in a bad situation where we can no longer add changes to postgres_exporter in production until we deploy v14 to production (which is 1-2 months away currently in 2023-05).
Proposal
We can update our queries.erb like below to allow us to specify the major version of postgres for the exporter and then we generate the correct queries.
diff --git a/.ruby-version b/.ruby-version
index 57cf282..1f7da99 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.6.5
+2.7.7
diff --git a/attributes/postgres_exporter.rb b/attributes/postgres_exporter.rb
index 06a8f54..9553ef6 100644
--- a/attributes/postgres_exporter.rb
+++ b/attributes/postgres_exporter.rb
@@ -9,6 +9,7 @@ default['postgres_exporter']['version'] = '0.6.0'
default['postgres_exporter']['db_user'] = 'postgres_exporter'
default['postgres_exporter']['database'] = 'gitlabhq_production'
default['postgres_exporter']['binary_url'] = "https://github.com/wrouesnel/postgres_exporter/releases/download/v#{node['postgres_exporter']['version']}/postgres_exporter_v#{node['postgres_exporter']['version']}_linux-amd64.tar.gz"
+default['postgres_exporter']['postgres_major_version'] = 12
default['postgres_exporter']['flags']['extend.query-path'] = "#{node['postgres_exporter']['dir']}/queries.yaml"
default['postgres_exporter']['secrets']['backend'] = 'chef_vault'
diff --git a/templates/postgres_exporter/queries.yaml.erb b/templates/postgres_exporter/queries.yaml.erb
index 10130d8..509306c 100644
--- a/templates/postgres_exporter/queries.yaml.erb
+++ b/templates/postgres_exporter/queries.yaml.erb
@@ -745,6 +745,10 @@ pg_gin_index:
usage: GAUGE
description: The current size of the GIN index pending-list, measured in bytes (page count * page size)
+<% if node.to_h.dig('postgres_exporter', 'postgres_major_version') == 12 %>
+
+<% end %>
+
# NOT
# DO NOT ADD GENERAL PURPOSE GITLAB MONITORING HERE
# NOT