From 7f1e0daded93101182ae69e39dfcafdbcdf33b24 Mon Sep 17 00:00:00 2001 From: 12ww1160 Date: Thu, 4 Dec 2025 13:11:43 +0100 Subject: [PATCH] OP#188 add env file --- .vscode/settings.json | 6 ++++++ manifests/main/files.pp | 18 ++++++++++++++++++ manifests/params.pp | 19 +++++++++++++++++++ templates/prune.env.erb | 20 ++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 templates/prune.env.erb diff --git a/.vscode/settings.json b/.vscode/settings.json index cf89a25..58088c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,8 +4,14 @@ "GITEA", "GOMAXPROCS", "Iseconds", + "PGDATABASE", + "PGHOST", + "PGPASSWORD", + "PGPORT", + "PGUSER", "pipefail", "procs", + "readaccess", "reqpackage", "rpms", "sslcacert", diff --git a/manifests/main/files.pp b/manifests/main/files.pp index 6df5e8e..5211fdd 100644 --- a/manifests/main/files.pp +++ b/manifests/main/files.pp @@ -56,10 +56,28 @@ class prometheus_cd::main::files ( content => template('prometheus_cd/prune_blocks.erb'), # notify Service ToDo, } + file { $ps_env_file: + ensure => file, + owner => 'prometheus', + group => 'prometheus', + mode => '0750', + selrange => s0, + selrole => object_r, + seltype => usr_, + seluser => unconfined_u, + content => template('prometheus_cd/prune.env.erb'), + # notify Service ToDo, + } } + if $ps_enable_pruning == false { file { $ps_pruning_file: ensure => absent, + # notify Service ToDo, + } + file { $ps_env_file: + ensure => absent, + # notify Service ToDo, } } } diff --git a/manifests/params.pp b/manifests/params.pp index e163d2a..9583ee2 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -30,6 +30,16 @@ # @param [String] ps_external_url the full url for the remote write point # @param [Boolean] ps_enable_pruning whether to allow pruning local blocks # @param [String] ps_pruning_dir the directory for the pruning script +# @param [String] ps_pruning_file the url and filename for the pruning script +# @param [String] ps_env_file the url and filename for the env file +# @param [String] ps_pg_host the host running the database for cold metrics +# @param [String] ps_pg_port the port for the database for cold metrics +# @param [String] ps_pg_db the database for cold metrics +# @param [String] ps_pg_user the read-only user for the db for cold metrics +# @param [String] ps_pg_pass the password for the db for cold metrics +# @param [Boolean] ps_dry_run (true = just log, false = actually delete blocks) +# @param [String] ps_min_age_hours Minimum block age in hours before pruning +# @param [String] ps_grace_hours Grace period in hours to be extra safe ############################################################################## class prometheus_cd::params ( @@ -79,6 +89,15 @@ class prometheus_cd::params ( Boolean $ps_enable_pruning = false, String $ps_pruning_dir = '/opt/prometheus-prune', String $ps_pruning_file = "${ps_pruning_dir}/prune_prometheus_pg.sh", + String $ps_env_file = "${ps_pruning_dir}/prune.env", + String $ps_pg_host = 'localhost', + String $ps_pg_port = '5432', + String $ps_pg_db = 'prometheus', + String $ps_pg_user = 'readaccess', + String $ps_pg_pass = 'Changeme', + Boolean $ps_dry_run = true, + String $ps_min_age_hours = '4', + String $ps_grace_hours = '1', ) { # defaults diff --git a/templates/prune.env.erb b/templates/prune.env.erb new file mode 100644 index 0000000..0edc507 --- /dev/null +++ b/templates/prune.env.erb @@ -0,0 +1,20 @@ +# /opt/prometheus-prune/prune.env + +# PostgreSQL connection +PGHOST=<%= @ps_pg_host %> +PGPORT=<%= @ps_pg_port %> +PGDATABASE=<%= @ps_pg_db %> +PGUSER=<%= @ps_pg_user %> +PGPASSWORD=<%= @ps_pg_pass %> + +# Dry-run mode (true = just log, false = actually delete) +DRY_RUN=<%= @ps_dry_run %> + +# Minimum block age in hours before pruning +MIN_AGE_HOURS=<%= @ps_min_age_hours %> + +# Grace period in hours to be extra safe +GRACE_HOURS=<%= @ps_grace_hours %> + +# SQL template to check if block exists in PostgreSQL +CHECK_SQL_TEMPLATE="SELECT 1 FROM metric_values WHERE metric_time >= to_timestamp({min}/1000.0) AND metric_time <= to_timestamp({max}/1000.0) LIMIT 1;"