Skip to content

Commit 4a653ef

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 5dca5c3 + 9c0d892 commit 4a653ef

22 files changed

+258
-746
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- [ ] Service has placement constraints or is global
1919
- [ ] Service is restartable
2020
- [ ] Service restart is zero-downtime
21+
- [ ] Service is monitored (via prometheus and grafana)
2122
- [ ] Service is not bound to one specific node (e.g. via files or volumes)
2223
- [ ] Relevant OPS E2E Test are added
23-
- [ ] Service's Public URL is included in maintenance mode -->
24+
- [ ] Service's Public URL is included in maintenance mode
25+
- [ ] Service's Public URL is included in testing mode -->

.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: 7 additions & 34 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
@@ -155,15 +139,4 @@ smokeping_prober_config.yaml: smokeping_prober_config.yaml.j2 ${REPO_CONFIG_LOCA
155139

156140
.PHONY: grafana/assets
157141
grafana/assets: ${REPO_CONFIG_LOCATION}
158-
@if [ ! -d "$(shell dirname ${REPO_CONFIG_LOCATION})/assets/grafana" ]; then \
159-
echo "Error: folder does not exist $$GRAFANA_ASSETS_DIR" >&2; \
160-
exit 1; \
161-
fi; \
162-
if [ ! -d "$(shell dirname ${REPO_CONFIG_LOCATION})/../shared/assets/grafana" ]; then \
163-
echo "Error: folder does not exist $$GRAFANA_COMMON_ASSETS_DIR" >&2; \
164-
exit 1; \
165-
fi; \
166-
rm -rf $(REPO_BASE_DIR)/services/monitoring/grafana/assets || true; \
167-
mkdir -p $(REPO_BASE_DIR)/services/monitoring/grafana/assets; \
168-
cp -r $(shell dirname ${REPO_CONFIG_LOCATION})/assets/grafana/* $(REPO_BASE_DIR)/services/monitoring/grafana/assets; \
169-
cp -r $(shell dirname ${REPO_CONFIG_LOCATION})/../shared/assets/grafana $(REPO_BASE_DIR)/services/monitoring/grafana/assets/shared; \
142+
@$(MAKE_C) grafana assets

services/monitoring/docker-compose.yml.j2

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,12 @@ services:
377377
networks:
378378
- monitored
379379
environment:
380-
REDIS_ADDR: redis://{{REDIS_HOST}}:{{REDIS_PORT}}
381-
REDIS_EXPORTER_CHECK_KEYS: db0=user_id*client_session_id*alive,db0=user_id*client_session_id*resources,db1=project_lock*,db3=*
380+
REDIS_ADDR: ${REDIS_ADDRESS}
381+
{%- if REDIS_USER %}
382+
REDIS_USER: ${REDIS_USER}
383+
{%- endif %}
382384
REDIS_PASSWORD: ${REDIS_PASSWORD}
385+
REDIS_EXPORTER_CHECK_KEYS: db0=user_id*client_session_id*alive,db0=user_id*client_session_id*resources,db1=project_lock*,db3=*
383386
deploy:
384387
labels:
385388
- prometheus-job=redis-exporter
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
.PHONY: terraform/main.tf
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;
65+
66+
.PHONY: assets
67+
assets: ${REPO_CONFIG_LOCATION}
68+
@if [ ! -d "$(shell dirname ${REPO_CONFIG_LOCATION})/assets/grafana" ]; then \
69+
echo "Error: folder does not exist $$GRAFANA_ASSETS_DIR" >&2; \
70+
exit 1; \
71+
fi; \
72+
if [ ! -d "$(shell dirname ${REPO_CONFIG_LOCATION})/../shared/assets/grafana" ]; then \
73+
echo "Error: folder does not exist $$GRAFANA_COMMON_ASSETS_DIR" >&2; \
74+
exit 1; \
75+
fi; \
76+
rm -rf $(REPO_BASE_DIR)/services/monitoring/grafana/assets || true; \
77+
mkdir -p $(REPO_BASE_DIR)/services/monitoring/grafana/assets; \
78+
cp -r $(shell dirname ${REPO_CONFIG_LOCATION})/assets/grafana/* $(REPO_BASE_DIR)/services/monitoring/grafana/assets; \
79+
cp -r $(shell dirname ${REPO_CONFIG_LOCATION})/../shared/assets/grafana $(REPO_BASE_DIR)/services/monitoring/grafana/assets/shared; \

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)