-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to sync AlertManager configuration with Cortex #10
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ This action is configured using environment variables defined in the workflow. T | |
| `CORTEX_API_KEY` | Optional password that is required for password protected Cortex clusters. An encrypted [github secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets ) is recommended. | `false` | N/A | | ||
| `ACTION` | Which action to take. One of `lint`, `prepare`, `check`, `diff` or `sync` | `true` | N/A | | ||
| `RULES_DIR` | Comma-separated list of directories to walk in order to source rules files | `false` | `./` | | ||
| `COMPONENT` | `RULER` or `ALERTMANAGER`. This dictates whether to sync ruler rulegroups or AlertManager configurations | `true` | N/A | | ||
| `ALERTMANAGER_CONFIG_PATH` | Path to the tenants AlertManager configuration | `true` If `COMPONENT` is set to `ALERTMANAGER` | `./alertManager.yml` | ||
|
||
## Actions | ||
|
||
|
@@ -74,7 +76,7 @@ jobs: | |
CORTEX_TENANT_ID: 1 | ||
CORTEX_API_KEY: ${{ secrets.CORTEX_API_KEY }} # Encrypted Github Secret https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets | ||
ACTION: diff | ||
RULES_DIR: "./rules/" # In this example rules are stored in a rules directory in the repo | ||
RULES_DIR: "./rules/" # In this example rules are stored in a rules directory in the repo | ||
- name: comment PR | ||
uses: unsplash/[email protected] # https://github.com/unsplash/comment-on-pr | ||
env: | ||
|
@@ -108,5 +110,30 @@ jobs: | |
CORTEX_TENANT_ID: 1 | ||
CORTEX_API_KEY: ${{ secrets.CORTEX_API_KEY }} # Encrypted Github Secret https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets | ||
ACTION: sync | ||
RULES_DIR: "./rules/" # In this example rules are stored in a rules directory in the repo | ||
RULES_DIR: "./rules/" # In this example rules are stored in a rules directory in the repo | ||
``` | ||
|
||
The following workflow will sync the AlertManager configuration file in the `master` branch against the configured Cortex cluster | ||
```yaml | ||
name: sync_alertmanager_master | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
sync-master: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: master | ||
- name: sync-alertmanager | ||
uses: grafana//[email protected] | ||
env: | ||
CORTEX_ADDRESS: https://example-cluster.com/ | ||
CORTEX_TENANT_ID: 1 | ||
CORTEX_API_KEY: ${{ secrets.CORTEX_API_KEY }} # Encrypted Github Secret https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets | ||
ACTION: sync | ||
COMPONENT: ALERTMANAGER | ||
ALERTMANAGER_CONFIG_PATH: "./alertmanager/config.yml" # In this example the AlertManager config is stored in the `alertmanager/` directory in the repository``` |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,48 +27,66 @@ SYNC_CMD=sync | |||||||||
DIFF_CMD=diff | ||||||||||
PRINT_CMD=print | ||||||||||
|
||||||||||
if [ -z "${COMPONENT}" ]; then | ||||||||||
echo "COMPONENT not set, select either RULER or ALERTMANAGER" | ||||||||||
exit 1 | ||||||||||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make sure we do not break existing setups. |
||||||||||
fi | ||||||||||
|
||||||||||
if [ -z "${RULES_DIR}" ]; then | ||||||||||
echo "RULES_DIR not set, using './' as a default." | ||||||||||
RULES_DIR="./" | ||||||||||
fi | ||||||||||
|
||||||||||
if [ ${COMPONENT} == "ALERTMANAGER" ] && [ -z "${ALERTMANAGER_CONFIG_PATH}" ]; then | ||||||||||
echo "No ALERTMANAGER_CONFIG_PATH variable set. Defaulting to ./alertManager.yml" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
ALERTMANAGER_CONFIG_PATH=./alertManager.yml | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
fi | ||||||||||
|
||||||||||
if [ -z "${ACTION}" ]; then | ||||||||||
err "ACTION has not been set." | ||||||||||
exit 1 | ||||||||||
fi | ||||||||||
|
||||||||||
case "${ACTION}" in | ||||||||||
$SYNC_CMD) | ||||||||||
verifyTenantAndAddress | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$DIFF_CMD) | ||||||||||
verifyTenantAndAddress | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$LINT_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$PREPARE_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$CHECK_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$PRINT_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules print "$@") | ||||||||||
if [ "${COMPONENT}" == "RULER" ]; then | ||||||||||
case "${ACTION}" in | ||||||||||
$SYNC_CMD) | ||||||||||
verifyTenantAndAddress | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
*) | ||||||||||
err "Unexpected action '${ACTION}'" | ||||||||||
exit 1 | ||||||||||
;; | ||||||||||
esac | ||||||||||
$DIFF_CMD) | ||||||||||
verifyTenantAndAddress | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$LINT_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$PREPARE_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$CHECK_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@") | ||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
$PRINT_CMD) | ||||||||||
OUTPUT=$(/usr/bin/cortextool rules print "$@") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
STATUS=$? | ||||||||||
;; | ||||||||||
*) | ||||||||||
err "Unexpected action '${ACTION}'" | ||||||||||
exit 1 | ||||||||||
;; | ||||||||||
esac | ||||||||||
elif [ "${COMPONENT}" == "ALERTMANAGER" ]; then | ||||||||||
OUTPUT=$(/usr/bin/cortextool alertmanager load ${ALERTMANAGER_CONFIG_PATH}) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have time to add the other commands just like the previous block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
STATUS=$? | ||||||||||
else | ||||||||||
echo "Invalid component selected, use RULER or ALERTMANAGER" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
exit 1 | ||||||||||
fi | ||||||||||
|
||||||||||
echo "${OUTPUT}" | ||||||||||
echo ::set-output name=detailed::"${OUTPUT}" | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's missing a
|
at the end, in the diff, it looks like one column instead of two - am I missing something?