Skip to content

Commit 08dab8b

Browse files
authored
Add metabase stack ⚠️ (manual action required) (#1093)
* Update postgres exporter Make sure we use recent version that has export all fields used by existing community grafana Postgres dashboards Related Issue(s): * #1080 * Add metabase stack Related Issue(s): * #1061 * Add metabase stack * Add replicas and fix browser errors * Reduce logging noise * Remove comments
1 parent 24d3c26 commit 08dab8b

File tree

8 files changed

+167
-1
lines changed

8 files changed

+167
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ yq
142142
**/.env-devel
143143
**/.stack.*.yml
144144
**/.stack.*.yaml
145-
docker-compose.yml
145+
146146
stack.yml
147147
stack_with_prefix.yml
148148
docker-compose.simcore.yml

scripts/common-services.Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
STACK_NAME = $(notdir $(shell pwd))
2+
TEMP_COMPOSE=.stack.${STACK_NAME}.yaml
3+
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)

services/metabase/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
configure_metabase.sql
2+
docker-compose.yml

services/metabase/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
2+
3+
include ${REPO_BASE_DIR}/scripts/common.Makefile
4+
include ${REPO_BASE_DIR}/scripts/common-services.Makefile
5+
6+
.PHONY: up
7+
up: ${TEMP_COMPOSE} ## Deploys metabase stack
8+
9+
${TEMP_COMPOSE}: docker-compose.yml .env
10+
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
11+
12+
docker-compose.yml: docker-compose.yml.j2 .env .venv
13+
@$(call jinja, $<, .env, $@)
14+
15+
configure_metabase.sql: .env
16+
@set -o allexport; source $<; set +o allexport; \
17+
envsubst < $@.template > $@
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE USER ${METABASE_POSTGRES_USER} WITH PASSWORD '${METABASE_POSTGRES_PASSWORD}';
2+
3+
-- relies on readonly role aldready existing in the database
4+
GRANT ${POSTGRES_DB}_readonly TO ${METABASE_POSTGRES_USER};
5+
6+
CREATE DATABASE ${METABASE_POSTGRES_DB}
7+
WITH OWNER ${METABASE_POSTGRES_USER};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# https://www.metabase.com/docs/v0.54/installation-and-operation/running-metabase-on-docker
2+
3+
# https://www.metabase.com/docs/v0.54/installation-and-operation/running-metabase-on-docker#example-docker-compose-yaml-file
4+
services:
5+
metabase:
6+
image: metabase/metabase:v0.54.13.3
7+
networks:
8+
- public
9+
- monitored
10+
environment:
11+
- MB_HEALTH_CHECK_LOGGING_ENABLED=false
12+
# Avoid: site URL basename "/" does not match the actual basename
13+
# https://www.metabase.com/docs/latest/configuring-metabase/environment-variables#mb_site_url
14+
- MB_SITE_URL=https://${ADMIN_DOMAIN}/metabase/
15+
# Metabase logs: https://www.metabase.com/docs/v0.54/configuring-metabase/log-configuration
16+
- JAVA_OPTS=-Dlog4j.configurationFile=file:/etc/metabase/log4j2.xml
17+
# https://www.metabase.com/docs/v0.54/installation-and-operation/configuring-application-database
18+
- MB_DB_TYPE=postgres
19+
- MB_DB_DBNAME=metabase
20+
- MB_DB_HOST=${POSTGRES_HOST}
21+
- MB_DB_PORT=${POSTGRES_PORT}
22+
- MB_DB_USER=${METABASE_POSTGRES_USER}
23+
- MB_DB_PASS=${METABASE_POSTGRES_PASSWORD}
24+
# https://www.metabase.com/docs/v0.54/installation-and-operation/running-metabase-on-docker#setting-the-java-timezone
25+
- JAVA_TIMEZONE=UTC
26+
# https://www.metabase.com/docs/latest/installation-and-operation/observability-with-prometheus
27+
- MB_PROMETHEUS_SERVER_PORT=9191
28+
deploy:
29+
# https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/metabase-at-scale
30+
replicas: ${METABASE_REPLICAS}
31+
update_config:
32+
parallelism: 1
33+
order: start-first
34+
failure_action: rollback
35+
delay: 30s
36+
placement:
37+
constraints:
38+
- node.labels.ops==true
39+
labels:
40+
# prometheus only keeps jobs with `prometheus-job` label
41+
- prometheus-job=metabase
42+
# Set in `MB_PROMETHEUS_SERVER_PORT` environment variable
43+
- prometheus-port=9191
44+
# TODO: add prometheus metrics
45+
- traefik.enable=true
46+
- traefik.docker.network=${PUBLIC_NETWORK}
47+
# router
48+
- traefik.http.routers.metabase.rule=Host(`${ADMIN_DOMAIN}`) && PathPrefix(`/metabase`)
49+
- traefik.http.routers.metabase.entrypoints=https
50+
- traefik.http.routers.metabase.tls=true
51+
- traefik.http.middlewares.metabase_stripprefixregex.stripprefixregex.regex=^/metabase
52+
- traefik.http.routers.metabase.middlewares=ops_whitelist_ips@swarm, ops_gzip@swarm, ops_auth@swarm, metabase_stripprefixregex
53+
# service
54+
- traefik.http.services.metabase.loadbalancer.server.port=3000
55+
- traefik.http.services.metabase.loadbalancer.healthcheck.path=/api/health
56+
- traefik.http.services.metabase.loadbalancer.healthcheck.interval=10s
57+
# GET method sometimes fails (`Request canceled before finishing`) log
58+
# This does not happen with HEAD method. Official healthcheck documentation
59+
# defines HEAD as well
60+
- traefik.http.services.metabase.loadbalancer.healthcheck.method=HEAD
61+
- traefik.http.services.metabase.loadbalancer.healthcheck.timeout=1s
62+
63+
# https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/metabase-in-production
64+
resources:
65+
limits:
66+
memory: 2G
67+
cpus: "2.0"
68+
reservations:
69+
memory: 1G
70+
cpus: "1.0"
71+
healthcheck:
72+
test: curl --fail -I http://localhost:3000/api/health || exit 1
73+
interval: 15s
74+
timeout: 5s
75+
retries: 5
76+
configs:
77+
- source: logging_configuration
78+
target: /etc/metabase/log4j2.xml
79+
80+
configs:
81+
logging_configuration:
82+
file: ./logging_configuration.xml
83+
name: {{ STACK_NAME }}_logging_configuration_{{ "./logging_configuration.xml" | sha256file | substring(0,10) }}
84+
85+
networks:
86+
public:
87+
external: true
88+
name: ${PUBLIC_NETWORK}
89+
monitored:
90+
name: ${MONITORED_NETWORK}
91+
external: true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Original file: https://github.com/metabase/metabase/blob/v0.54.14.3/resources/log4j2.xml -->
3+
4+
<Configuration>
5+
<Appenders>
6+
<Console name="STDOUT" target="SYSTEM_OUT" follow="true">
7+
<PatternLayout pattern="%date %level %logger{2} :: %message %notEmpty{%X}%n%throwable">
8+
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
9+
</PatternLayout>
10+
</Console>
11+
</Appenders>
12+
13+
<Loggers>
14+
<Logger name="com.mchange" level="ERROR"/>
15+
<Logger name="liquibase" level="INFO"/>
16+
<Logger name="metabase" level="INFO"/>
17+
<Logger name="metabase-enterprise" level="INFO"/>
18+
<Logger name="metabase.metabot" level="INFO"/>
19+
<Logger name="metabase.plugins" level="INFO"/>
20+
<Logger name="metabase.query-processor.async" level="INFO"/>
21+
<Logger name="metabase.server.middleware" level="INFO"/>
22+
<Logger name="org.quartz" level="INFO"/>
23+
<Logger name="net.snowflake.client.jdbc.SnowflakeConnectString" level="ERROR"/>
24+
<Logger name="net.snowflake.client.core.SessionUtil" level="FATAL"/>
25+
26+
<Root level="WARN">
27+
<AppenderRef ref="STDOUT"/>
28+
</Root>
29+
</Loggers>
30+
</Configuration>

services/metabase/template.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
STACK_NAME=${STACK_NAME}
2+
3+
METABASE_REPLICAS=${METABASE_REPLICAS}
4+
5+
ADMIN_DOMAIN=${ADMIN_DOMAIN}
6+
7+
PUBLIC_NETWORK=${PUBLIC_NETWORK}
8+
MONITORED_NETWORK=${MONITORED_NETWORK}
9+
10+
POSTGRES_HOST=${POSTGRES_HOST}
11+
POSTGRES_PORT=${POSTGRES_PORT}
12+
POSTGRES_DB=${POSTGRES_DB}
13+
14+
METABASE_POSTGRES_USER=${METABASE_POSTGRES_USER}
15+
METABASE_POSTGRES_PASSWORD=${METABASE_POSTGRES_PASSWORD}
16+
METABASE_POSTGRES_DB=${METABASE_POSTGRES_DB}

0 commit comments

Comments
 (0)