Git Workflow: Adding Prometheus Alert
Guide for adding a new Prometheus alert (Example: PrometheusPodHighMemoryUsage)
1. Branch Setup
Create a new feature branch for your alert:
2. Making Changes
Update Alert Files
- Add or modify the alert YAML file
- Update the corresponding promtool test file
Example files:
- Alert: rhobs/alerting/data_plane/prometheus.prometheus_pod_high_memory_usage_alert.yaml
- Test: test/promql/tests/data_plane/high_pod_memory_usage_alert_test.yaml
Check Status
Output:
On branch prometheus-pod-memory-alert
Your branch is up to date with 'origin/prometheus-pod-memory-alert'.
Changes not staged for commit:
modified: prometheus.prometheus_pod_high_memory_usage_alert.yaml
modified: test/promql/tests/data_plane/high_pod_memory_usage_alert_test.yaml
Stage Changes
git add rhobs/alerting/data_plane/prometheus.prometheus_pod_high_memory_usage_alert.yaml
git add test/promql/tests/data_plane/high_pod_memory_usage_alert_test.yaml
3. Committing Changes
Commit with a descriptive message following conventional commits:
git commit -m "feat(OPS-4586): create new memory usage alert of prometheus instances" \
-m "" \
-m "Signed-off-by: Karishma Karna <kkarna@company.com>"
Output:
[prometheus-pod-memory-alert bc176d1] Update the component in test and alert file
2 files changed, 2 insertions(+)
Push to Remote
4. Rebasing and Squashing Commits
Use interactive rebase to squash multiple commits into a single clean commit:
Interactive Editor
In the editor, mark commits to squash:
pick 049bb51 Add PrometheusPodHighMemoryUsage alert with unit tests
squash bc176d1 Update the component in test and alert file
squash 14efe84 feat(OPS-4586): create new memory usage alert of prometheus instances
Save and close. Git will combine the commits and allow you to edit the final commit message.
Output:
Force Push
Force Push Safety
Always use --force-with-lease instead of --force to avoid overwriting others' work.
5. Running promtool Tests
Verify your alert with promtool unit tests:
Expected output:
6. Summary
Complete workflow:
- Branch created
- Alert and test files updated
- Changes committed with proper message
- Interactive rebase for squash
- Force push with
--force-with-lease - Promtool tests verified
Related Resources
Author: Karishma Karna Ticket: OPS-4586 Date: March 2025