Skip to content

Commit 4f61106

Browse files
mrnicegyu11YuryHrytsuksanderegg
authored
✨ Add: Manage grafana content/assets via terraform (#913)
* wip * Add csi-s3 and have portainer use it * Change request @Hrytsuk 1GB max portainer volume size * Arch Linux Certificates Customization * Add grafana terrform tooling * Make osparc-config dotenv-precommit pass: Use all caps env-vars * Refactoring: jinja2 takes .env file path as explicit argument (like in osparc-config) * Make CI_ENV_FILE vailable in makefile * Refactor makefile targets * Add grafana terraform gitignore * Rename envvar: TF_STATE_S3_GRAFANAKEY * Remove old scripts, makefile targets * Remove unused files * undue arch style commit * Remove references to Tempo * CHange request YH: Stop trying tor ecah grafana eventually * Change request YH: Move tf scripts to terraform folder * Change request YH: stricter check * Add files remove typo * Add terraform fmt pre-commit hook * Use ansible.env file in lieu of ci.env if available * Rename and refactor * wip * wip * remove line * Makefile repo base dir without git * Grafana terraform ceph fixes * Fix indentation * Add manual to traefik redirect capture all rule (#933) * Introduce rolling docker config / secret update concept 🎉 🚀 (#952) * fixes * update comment * Update traefik router hardcoded priorities (#953) * Update traefik router hardcoded priorities * remove hardcoded priority from adminpanels * Configure redis replicas via ENV (#957) * Filestash: remove special docker node label (#959) * rabbit: configurable replicas (#964) * rabbit: configurable replicas * clean up * 💄 minor: Change DNS Server to Quad9 (#967) * wip * Add csi-s3 and have portainer use it * Change request @Hrytsuk 1GB max portainer volume size * Arch Linux Certificates Customization * Change DNS server for aws to swiss privacy focused one * revert wrong commit --------- Co-authored-by: Dustin Kaiser <[email protected]> * single replica (#968) * Remove docker api proxy from validate simcore settings (#972) * Add appmotiongateway add dalco * Add appmotiongateway add dalco - 2 * Add appmotiongateway add dalco - 3 * Seperate dalco-staging: disable redis special handling (#976) * wip * Add csi-s3 and have portainer use it * Change request @Hrytsuk 1GB max portainer volume size * Arch Linux Certificates Customization * Remove dalco special staging handling * remove accidental commit * remove accidental commit * Remove dalco staging special handling --------- Co-authored-by: Dustin Kaiser <[email protected]> * Fix deploy ops failure * Make curl in ensure_grafana_online_ timeout after 10s * Timeout in wait_graylog_is_online * Fix osparc.local pydantic validation failure director-v0 --------- Co-authored-by: Dustin Kaiser <[email protected]> Co-authored-by: Yury Hrytsuk <[email protected]> Co-authored-by: Sylvain <[email protected]>
1 parent 624d00d commit 4f61106

19 files changed

+229
-729
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ repos:
7979
hooks:
8080
- id: shellcheck
8181
name: Shell scripts conform to shellcheck
82+
- repo: https://github.com/antonbabenko/pre-commit-terraform
83+
rev: v1.89.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
84+
hooks:
85+
- id: terraform_fmt
8286
- repo: local
8387
hooks:
8488
- id: run-pylint

scripts/common.Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ IS_WIN := $(strip $(if $(or $(IS_LINUX),$(IS_OSX),$(IS_WSL)),,$(OS)))
1616
$(if $(IS_WSL2),,$(if $(IS_WSL),$(error WSL1 is not supported in all recipes. Use WSL2 instead. Follow instructions in README.md),))
1717

1818
# Check that a valid location to a config file is set.
19-
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
19+
REPO_BASE_DIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)
2020
export REPO_CONFIG_LOCATION := $(shell cat $(REPO_BASE_DIR)/.config.location)
2121
$(if $(REPO_CONFIG_LOCATION),,$(error The location of the repo.config file given in .config.location is invalid. Aborting))
2222
$(if $(shell cat $(REPO_CONFIG_LOCATION)),,$(error The location of the repo.config file given in .config.location is invalid. Aborting))

services/graylog/scripts/configure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
)
5050
def wait_graylog_is_online():
5151
_r = requests.get(
52-
GRAYLOG_BASE_DOMAIN + "/api/system", auth=REQUESTS_AUTH, verify=False
52+
GRAYLOG_BASE_DOMAIN + "/api/system",
53+
auth=REQUESTS_AUTH,
54+
verify=False,
55+
timeout=10,
5356
)
5457

5558
if _r.status_code == 401:

services/monitoring/Makefile

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# STACK_NAME defaults to name of the current directory. Should not to be changed if you follow GitOps operating procedures.
55
STACK_NAME = $(notdir $(CURDIR))
66
TEMP_COMPOSE=.stack.${STACK_NAME}.yaml
7-
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
7+
REPO_BASE_DIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))../..)
88

99
# TARGETS --------------------------------------------------
1010
include ${REPO_BASE_DIR}/scripts/common.Makefile
@@ -76,28 +76,12 @@ ${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.letsencrypt.dns.yml con
7676
docker-compose.yml: docker-compose.yml.j2 .env .venv pgsql_query_exporter_config.yaml
7777
$(call jinja,$<,.env,$@)
7878

79-
.PHONY: update.grafana.pwd
80-
update.grafana.pwd: .env ## Change grafana pwd
81-
@set -o allexport; \
82-
source $(REPO_CONFIG_LOCATION); \
83-
set +o allexport; \
84-
grafanacontainerid=$$(docker ps | grep grafana | awk '{print $$1;}');\
85-
docker exec -ti $$grafanacontainerid grafana-cli admin reset-admin-password $$TRAEFIK_PASSWORD
86-
87-
88-
.PHONY: grafana-export
89-
grafana-export: .venv## Export the remote grafana dashboards and datasources TO YOUR LOCAL MACHINE
90-
@cd grafana/scripts;\
91-
source ${REPO_BASE_DIR}/.venv/bin/activate;\
92-
pip install -r requirements.txt > /dev/null 2>&1;\
93-
python3 export.py;
94-
9579
.PHONY: grafana-import
96-
grafana-import: grafana/assets .venv ## Imports AND OVERWRITES the remote grafana dashboards and datasources FROM YOUR LOCAL MACHINE
97-
@cd grafana/scripts;\
98-
source ${REPO_BASE_DIR}/.venv/bin/activate;\
99-
pip install -r requirements.txt > /dev/null 2>&1;\
100-
python3 import.py
80+
grafana-import: grafana/assets ## Imports the remote grafana dashboards and datasources FROM YOUR LOCAL MACHINE
81+
@pushd ${REPO_BASE_DIR}/services/monitoring/grafana && \
82+
$(MAKE) terraform-plan && \
83+
$(MAKE) terraform-apply; \
84+
popd > /dev/null
10185

10286
.PHONY: config.grafana.dashboards
10387
config.grafana.dashboards: grafana/templates-provisioning/dashboards/simcore/Metrics-dashboard.json.j2 .venv #Configure dashboards for aws or dalco clusters

services/monitoring/grafana/Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.DEFAULT_GOAL := help
2+
REPO_BASE_DIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))../../..)
3+
include ${REPO_BASE_DIR}/scripts/common.Makefile
4+
5+
6+
7+
# Internal VARIABLES ------------------------------------------------
8+
TF_STATE_FILE := terraform/.terraform/terraform.tfstate
9+
10+
terraform/main.tf: terraform/main.tf.j2 .venv $(REPO_CONFIG_LOCATION)
11+
# generate $@
12+
@$(call jinja, $<, $(REPO_CONFIG_LOCATION), $@)
13+
14+
terraform-init: $(TF_STATE_FILE) ## init terraform
15+
16+
$(TF_STATE_FILE): $(REPO_CONFIG_LOCATION) terraform/main.tf
17+
# terraform init
18+
@set -a; source $<; set +a; \
19+
if [ "$${GRAFANA_TERRAFORM_STATE_BACKEND_TYPE}" = "local" ]; then \
20+
terraform -chdir=./terraform init; \
21+
else \
22+
terraform -chdir=./terraform init -backend-config="access_key=$${TF_GRAFANA_STATE_BACKEND_AWS_ACCESS_KEY_ID}" -backend-config="secret_key=$${TF_GRAFANA_STATE_BACKEND_AWS_SECRET_ACCESS_KEY}"; \
23+
fi
24+
25+
terraform/plan.cache:
26+
@echo "$@ file not found. Run 'make terraform-plan' to generate it."
27+
@exit 1
28+
29+
.PHONY: terraform-plan
30+
terraform-plan: $(REPO_CONFIG_LOCATION) $(TF_STATE_FILE) ensure-grafana-online ## terraform plan
31+
# terraform plan
32+
@set -a; source $<; set +a; \
33+
terraform -chdir=./terraform plan -out=plan.cache
34+
35+
.PHONY: terraform-apply
36+
terraform-apply: $(REPO_CONFIG_LOCATION) terraform/plan.cache $(TF_STATE_FILE) ensure-grafana-online ## terraform apply
37+
# terraform apply
38+
@set -a; source $<; set +a; \
39+
terraform -chdir=./terraform apply plan.cache
40+
41+
.PHONY: ensure-grafana-online
42+
ensure-grafana-online:
43+
@set -o allexport; \
44+
source $(REPO_CONFIG_LOCATION); \
45+
set +o allexport; \
46+
url=$${TF_VAR_GRAFANA_URL}; \
47+
echo "Waiting for grafana at $$url to become reachable..."; \
48+
attempts=0; \
49+
max_attempts=10; \
50+
while [ $$attempts -lt $$max_attempts ]; do \
51+
status_code=$$(curl -k -o /dev/null -s -w "%{http_code}" --max-time 10 $$url); \
52+
if [ "$$status_code" -ge 200 ] && [ "$$status_code" -lt 400 ]; then \
53+
echo "Grafana is online"; \
54+
break; \
55+
else \
56+
echo "Grafana still unreachable, waiting 5s for grafana to become reachable... (Attempt $$((attempts+1)))"; \
57+
sleep 5; \
58+
attempts=$$((attempts + 1)); \
59+
fi; \
60+
done; \
61+
if [ $$attempts -eq $$max_attempts ]; then \
62+
echo "Max attempts reached, Grafana is still unreachable."; \
63+
exit 1; \
64+
fi;

services/monitoring/grafana/scripts/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

services/monitoring/grafana/scripts/README.MD

Lines changed: 0 additions & 26 deletions
This file was deleted.

services/monitoring/grafana/scripts/export.py

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)