From c703e2949e98773960fd45c3a12c5f09a6c66f46 Mon Sep 17 00:00:00 2001 From: Bruno FERNANDO Date: Thu, 22 Feb 2024 10:00:13 +0100 Subject: [PATCH] feat: add backend option to action (#23) * feat: bump docker layer grafana/cortex-tools to v0.11.0 * feat: add BACKEND settings in the entrypoint.sh --- Dockerfile | 2 +- README.md | 13 +++++++------ entrypoint.sh | 17 +++++++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a3bb22..30c3bb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM grafana/cortex-tools:v0.10.6 +FROM grafana/cortex-tools:v0.11.0 COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index dffb8a1..8f7ae72 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,15 @@ This action is used to lint, prepare, verify, diff, and sync rules to a [Cortex] This action is configured using environment variables defined in the workflow. The following variables can be configured. | Name | Description | Required | Default | -| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- | -| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A | +| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- | +| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A | | `CORTEX_TENANT_ID` | ID for the desired tenant in the target Cortex cluster. Used as the username under HTTP Basic authentication. | `false` | N/A | | `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. Used as the password under HTTP Basic authentication. | `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` | `./` | -| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A | -| `NAMESPACES` | Comma-separated list of namespaces to use | `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` | `./` | +| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A | +| `NAMESPACES` | Comma-separated list of namespaces to use | `false` | N/A | +| `BACKEND` | Backend type to interact with: cortex, loki | `false` | `cortex` | ## Authentication diff --git a/entrypoint.sh b/entrypoint.sh index c21664d..739c04d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -28,6 +28,11 @@ SYNC_CMD=sync DIFF_CMD="diff" PRINT_CMD=print +if [ -z "${BACKEND}" ]; then + echo "BACKEND not set, using 'cortex' as a default." + BACKEND="cortex" +fi + if [ -z "${RULES_DIR}" ]; then echo "RULES_DIR not set, using './' as a default." RULES_DIR="./" @@ -41,28 +46,28 @@ fi case "${ACTION}" in "$SYNC_CMD") verifyTenantAndAddress - OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@") + OUTPUT=$(/usr/bin/cortextool rules sync --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@") STATUS=$? ;; "$DIFF_CMD") verifyTenantAndAddress - OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@") + OUTPUT=$(/usr/bin/cortextool rules diff --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@") STATUS=$? ;; "$LINT_CMD") - OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@") + OUTPUT=$(/usr/bin/cortextool rules lint --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@") STATUS=$? ;; "$PREPARE_CMD") - OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@") + OUTPUT=$(/usr/bin/cortextool rules prepare --backend="${BACKEND}" -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@") STATUS=$? ;; "$CHECK_CMD") - OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@") + OUTPUT=$(/usr/bin/cortextool rules check --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@") STATUS=$? ;; "$PRINT_CMD") - OUTPUT=$(/usr/bin/cortextool rules print --disable-color "$@") + OUTPUT=$(/usr/bin/cortextool rules print --backend="${BACKEND}" --disable-color "$@") STATUS=$? ;; *)