From b5ddb7d8cf7fdb514e848df5544e2ffa46c0762a Mon Sep 17 00:00:00 2001 From: gearnode Date: Thu, 16 Jan 2025 13:45:38 +0100 Subject: [PATCH] Add docker and compose config Signed-off-by: gearnode --- GNUmakefile | 15 ++++ compose.yaml | 70 +++++++++++++++++++ .../provisioning/datasources/datasources.yaml | 42 +++++++++++ compose/postgres/01_probod.sh | 23 ++++++ compose/prometheus/prometheus.yaml | 12 ++++ compose/tempo/tempo.yaml | 41 +++++++++++ 6 files changed, 203 insertions(+) create mode 100644 compose.yaml create mode 100644 compose/grafana/provisioning/datasources/datasources.yaml create mode 100755 compose/postgres/01_probod.sh create mode 100644 compose/prometheus/prometheus.yaml create mode 100644 compose/tempo/tempo.yaml diff --git a/GNUmakefile b/GNUmakefile index f121c6af7..5c8326d5f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,9 @@ NPX?= npx PRETTIER?= $(NPX) prettier GO?= go +DOCKER?= docker + +DOCKER_COMPOSE= $(DOCKER) compose -f compose.yaml $(DOCKER_COMPOSE_FLAGS) VERSION= unknown LDFLAGS= -ldflags "-X 'main.version=$(VERSION)' -X 'main.env=prod'" @@ -41,3 +44,15 @@ fmt-check: .PHONY: clean clean: $(RM) -rf bin/* + +.PHONY: stack-up +stack-up: + $(DOCKER_COMPOSE) up -d + +.PHONY: stack-down +stack-down: + $(DOCKER_COMPOSE) down + +.PHONY: stack-ps +stack-ps: + $(DOCKER_COMPOSE) ps diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 000000000..9a95fbb8a --- /dev/null +++ b/compose.yaml @@ -0,0 +1,70 @@ + +services: + postgres: + image: "postgres:16" + shm_size: "1g" + command: > + postgres -c "shared_buffers=4GB" + -c "max_connections=200" + -c "log_statement=all" + ports: + - "5432:5432" + volumes: + - "./compose/postgres:/docker-entrypoint-initdb.d:ro" + - "postgres-data:/var/lib/postgresql/data:rw" + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + + grafana: + image: "grafana/grafana:latest" + ports: + - "3001:3000" + volumes: + - "./compose/grafana/provisioning:/etc/grafana/provisioning:ro" + - "grafana-data:/var/lib/grafana:rw" + environment: + GF_AUTH_ANONYMOUS_ENABLED: "true" + GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin" + GF_AUTH_DISABLE_LOGIN_FORM: "true" + GF_USERS_DEFAULT_THEME: "light" + + prometheus: + image: "prom/prometheus:latest" + volumes: + - "./compose/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml" + - "prometheus-data:/prometheus" + command: + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--web.console.libraries=/etc/prometheus/console_libraries" + - "--web.console.templates=/etc/prometheus/consoles" + - "--web.enable-lifecycle" + - "--web.enable-remote-write-receiver" + - "--web.listen-address=:9191" + ports: + - "9191:9191" + + loki: + image: "grafana/loki:latest" + ports: + - "3100:3100" + command: + - "-config.file=/etc/loki/local-config.yaml" + + tempo: + image: "grafana/tempo:latest" + command: + - "-config.file=/etc/tempo.yaml" + ports: + - "4317:4317" + volumes: + - "./compose/tempo/tempo.yaml:/etc/tempo.yaml:ro" + - "tempo-data:/var/db/tempo:rw" + +volumes: + postgres-data: + grafana-data: + prometheus-data: + tempo-data: + diff --git a/compose/grafana/provisioning/datasources/datasources.yaml b/compose/grafana/provisioning/datasources/datasources.yaml new file mode 100644 index 000000000..6a8977916 --- /dev/null +++ b/compose/grafana/provisioning/datasources/datasources.yaml @@ -0,0 +1,42 @@ +apiVersion: 1 +deleteDatasources: + - name: "Prometheus" + - name: "Loki" + - name: "Tempo" +datasources: + - name: "Prometheus" + type: "prometheus" + access: "proxy" + url: "http://prometheus:9191" + basicAuth: false + jsonData: + httpMethod: "POST" + manageAlerts: true + prometheusType: "Prometheus" + cacheLevel: 'High' + disableRecordingRules: false + incrementalQueryOverlapWindow: 10m + isDefault: false + version: 1 + editable: false + - name: "Loki" + type: "loki" + access: "proxy" + url: "http://loki:3100" + basicAuth: false + version: 1 + editable: false + jsonData: + derivedFields: + - datasourceUid: "tempo" + matcherRegex: traceID=(\w+) + name: "TraceID" + url: $${__value.raw} + - name: "Tempo" + type: tempo + access: proxy + url: "http://tempo:3200" + basicAuth: false + isDefault: true + version: 1 + editable: false diff --git a/compose/postgres/01_probod.sh b/compose/postgres/01_probod.sh new file mode 100755 index 000000000..ad18b10d9 --- /dev/null +++ b/compose/postgres/01_probod.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -eu + +psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOF +CREATE USER probod; +ALTER USER probod WITH SUPERUSER; +ALTER USER probod PASSWORD 'probod'; +CREATE DATABASE probod; +GRANT ALL PRIVILEGES ON DATABASE probod TO probod; +CREATE DATABASE probod_test; +GRANT ALL PRIVILEGES ON DATABASE probod_test TO probod; +EOF + +psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d probod <<-EOF +ALTER SCHEMA public OWNER TO probod; +GRANT ALL ON SCHEMA public TO probod; +EOF + +psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d probod_test <<-EOF +ALTER SCHEMA public OWNER TO probod; +GRANT ALL ON SCHEMA public TO probod; +EOF diff --git a/compose/prometheus/prometheus.yaml b/compose/prometheus/prometheus.yaml new file mode 100644 index 000000000..182c58a17 --- /dev/null +++ b/compose/prometheus/prometheus.yaml @@ -0,0 +1,12 @@ +global: + scrape_interval: "15s" + evaluation_interval: "15s" + +scrape_configs: + - job_name: "prometheus" + static_configs: + - targets: ["host.docker.internal:9090"] + - job_name: "tempo" + static_configs: + - targets: ["tempo:3200"] + diff --git a/compose/tempo/tempo.yaml b/compose/tempo/tempo.yaml new file mode 100644 index 000000000..a78edd775 --- /dev/null +++ b/compose/tempo/tempo.yaml @@ -0,0 +1,41 @@ +server: + http_listen_port: 3200 + +distributor: + receivers: + otlp: + protocols: + grpc: + endpoint: "0.0.0.0:4317" + +ingester: + trace_idle_period: "10s" + max_block_bytes: 1_000_000 + max_block_duration: "5m" + +compactor: + compaction: + compaction_window: "1h" + max_block_bytes: 100_000_000 + block_retention: "1h" + compacted_block_retention: "10m" + +storage: + trace: + backend: "local" + local: + path: "/var/db/tempo" + block: + bloom_filter_false_positive: .05 + v2_index_downsample_bytes: 1000 + v2_encoding: "zstd" + wal: + path: "/var/db/tempo/wal" + v2_encoding: "snappy" + pool: + max_workers: 100 + queue_depth: 10000 + +usage_report: + reporting_enabled: false +