From 9a234e3b63d9494309d43ff414f7350e29b49b9d Mon Sep 17 00:00:00 2001
From: Silvio Rhatto <rhatto@torproject.org>
Date: Wed, 26 Feb 2025 12:43:15 -0300
Subject: [PATCH 1/4] Feat: CI: tests for prometheus; sort jobs by stage

---
 .gitlab-ci-pages.yml  |  1 +
 .gitlab-ci-slides.yml |  1 +
 .gitlab-ci.yml        | 46 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/.gitlab-ci-pages.yml b/.gitlab-ci-pages.yml
index b516d87..79662ca 100644
--- a/.gitlab-ci-pages.yml
+++ b/.gitlab-ci-pages.yml
@@ -4,6 +4,7 @@ include:
     file: .gitlab-ci-base.yml
 
 pages:
+  stage: build
   extends: .onion-mkdocs-clone
   after_script:
     - $ONION_MKDOCS_LOCATION/scripts/onion-mkdocs-provision-build
diff --git a/.gitlab-ci-slides.yml b/.gitlab-ci-slides.yml
index 5052791..3ed5cce 100644
--- a/.gitlab-ci-slides.yml
+++ b/.gitlab-ci-slides.yml
@@ -1,5 +1,6 @@
 slides:
   image: debian:bookworm
+  stage: build
   script:
     - apt-get update
     - apt-get install -y git
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ab0e3e8..8675904 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,7 +3,12 @@ include:
   - local: '.gitlab-ci-pages.yml'
   - local: '.gitlab-ci-slides.yml'
 
+#
+# Python
+#
+
 python:
+  stage: build
   image: debian:bookworm
   script:
     - apt-get update
@@ -19,7 +24,12 @@ python:
   #only:
   #  - main
 
+#
+# Debian
+#
+
 debian:
+  stage: build
   # Using bookworm support due to the pybuild-plugin-pyproject package
   #image: debian:bookworm
   #image: debian:bookworm-backports
@@ -42,8 +52,13 @@ debian:
   #only:
   #  - main
 
+#
+# Configuration
+#
+
 configs:
   image: debian:bookworm
+  stage: build
   script:
     - apt-get update
     - apt-get install -y git
@@ -59,8 +74,13 @@ configs:
   #only:
   #  - main
 
+#
+# Documentation
+#
+
 #manpage:
 #  image: debian:bookworm
+#  stage: build
 #  script:
 #    - apt-get update
 #    - apt-get install -y git
@@ -76,6 +96,32 @@ configs:
 #  only:
 #    - main
 
+#
+# Prometheus
+# Thanks https://gitlab.torproject.org/tpo/tpa/prometheus-alerts
+#
+
+pint:
+  stage: test
+  image: ghcr.io/cloudflare/pint
+  script:
+    - pint lint configs/prometheus/*rules*
+
+promtool:
+  stage: test
+  image:
+    name: quay.io/prometheus/prometheus
+    entrypoint: [""]
+  script:
+    - promtool check config configs/prometheus/prometheus.yml
+    - echo checking for password leaks...
+    - grep password prometheus-ci.yml | grep -q '[[:space:]]*password:[[:space:]]*REDACTED$'
+    - promtool test rules configs/prometheus/*rules*
+
+#
+# Release
+#
+
 release:
   image: registry.gitlab.com/gitlab-org/release-cli:latest
   stage: .post
-- 
GitLab


From 420d680dafe664c5ca69c7eb4aeebb93887e74f3 Mon Sep 17 00:00:00 2001
From: Silvio Rhatto <rhatto@torproject.org>
Date: Wed, 26 Feb 2025 12:47:33 -0300
Subject: [PATCH 2/4] Feat: CI: promtool: use the right config file

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8675904..9ba94e8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -115,7 +115,7 @@ promtool:
   script:
     - promtool check config configs/prometheus/prometheus.yml
     - echo checking for password leaks...
-    - grep password prometheus-ci.yml | grep -q '[[:space:]]*password:[[:space:]]*REDACTED$'
+    - grep password configs/prometheus/prometheus.yml | grep -q '[[:space:]]*password:[[:space:]]*REDACTED$'
     - promtool test rules configs/prometheus/*rules*
 
 #
-- 
GitLab


From 4790251b287eae660fe42cccc6976e0c9c2c35ea Mon Sep 17 00:00:00 2001
From: Silvio Rhatto <rhatto@torproject.org>
Date: Wed, 26 Feb 2025 12:54:31 -0300
Subject: [PATCH 3/4] Feat: CI: promtool: no need to check for password leaks

---
 .gitlab-ci.yml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9ba94e8..20cbab3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -114,8 +114,6 @@ promtool:
     entrypoint: [""]
   script:
     - promtool check config configs/prometheus/prometheus.yml
-    - echo checking for password leaks...
-    - grep password configs/prometheus/prometheus.yml | grep -q '[[:space:]]*password:[[:space:]]*REDACTED$'
     - promtool test rules configs/prometheus/*rules*
 
 #
-- 
GitLab


From aeec4edeb295257666c8d05205f8200116f303cb Mon Sep 17 00:00:00 2001
From: Silvio Rhatto <rhatto@torproject.org>
Date: Wed, 26 Feb 2025 13:11:37 -0300
Subject: [PATCH 4/4] Fix: CI: promtool: adds skeleton test file

---
 .gitlab-ci.yml              |  2 +-
 configs/prometheus/test.yml | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 configs/prometheus/test.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 20cbab3..343f971 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -114,7 +114,7 @@ promtool:
     entrypoint: [""]
   script:
     - promtool check config configs/prometheus/prometheus.yml
-    - promtool test rules configs/prometheus/*rules*
+    - promtool test rules configs/prometheus/test.yml
 
 #
 # Release
diff --git a/configs/prometheus/test.yml b/configs/prometheus/test.yml
new file mode 100644
index 0000000..5076840
--- /dev/null
+++ b/configs/prometheus/test.yml
@@ -0,0 +1,22 @@
+---
+# Sample Prometheus test rule file to be used with Docker Compose.
+#
+# Copyright (C) 2025 The Tor Project, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License,
+# or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+rule_files:
+  - prometeus-rules.yml
+
+tests:
-- 
GitLab