diff --git a/deploy/compose.yaml b/deploy/compose.yaml index c71e611..bf195dd 100644 --- a/deploy/compose.yaml +++ b/deploy/compose.yaml @@ -11,6 +11,11 @@ # The service publishes no port. Whatever carries webhook deliveries to it # joins the `edge` network and reaches it at receiver:8080. # +# OTEL_EXPORTER_OTLP_ENDPOINT defaults to empty. Setting it drains the stored +# queue, so the host owner must export the stored backlog first. +# METRICS_NETWORK is required and names an existing network on the host. +# Compose reads both from the environment or a .env file beside compose.yaml. +# # Both secrets are files, never environment variables: `secrets/webhook_secret` # for the receiver and `secrets/tunnel_token` for the tunnel connector. Compose # bind-mounts each file as it is, so the host file itself must be readable by @@ -45,6 +50,7 @@ services: restart: unless-stopped environment: LISTEN_ADDR: ":8080" + OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-} STORE_FILE: /var/lib/github-metrics/store.db WEBHOOK_SECRET_FILE: /run/secrets/webhook_secret volumes: @@ -53,6 +59,7 @@ services: - webhook_secret networks: - edge + - metrics healthcheck: test: ["CMD", "/github-metrics", "-healthcheck"] interval: 30s @@ -116,6 +123,9 @@ secrets: networks: edge: {} + metrics: + name: "${METRICS_NETWORK:?set METRICS_NETWORK to the existing collector network}" + external: true volumes: store: {} diff --git a/deploy/deploy_test.go b/deploy/deploy_test.go index 87aed34..b0cb1aa 100644 --- a/deploy/deploy_test.go +++ b/deploy/deploy_test.go @@ -363,8 +363,10 @@ func TestReceiverServiceSettings(t *testing.T) { for _, want := range []string{ "\n user: \"65532:65532\"\n", "\n read_only: true\n", + "\n OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-}\n", "\n STORE_FILE: /var/lib/github-metrics/store.db\n", "\n volumes:\n - store:/var/lib/github-metrics\n", + "\n networks:\n - edge\n - metrics\n", } { if !strings.Contains(block, want) { t.Errorf("the receiver service lacks %q", strings.TrimSpace(want)) @@ -374,6 +376,14 @@ func TestReceiverServiceSettings(t *testing.T) { if !strings.Contains(composeText(t), "\nvolumes:\n store: {}\n") { t.Error("compose.yaml does not define the named store volume") } + + const network = "\n metrics:\n" + + " name: \"${METRICS_NETWORK:?set METRICS_NETWORK to the existing collector network}\"\n" + + " external: true\n" + + if !strings.Contains(composeText(t), network) { + t.Error("compose.yaml does not define the external metrics network with its required METRICS_NETWORK name") + } } // TestTunnelServiceSettings reads the block for the pinned image, the token @@ -397,6 +407,7 @@ func TestTunnelServiceSettings(t *testing.T) { "\n secrets:\n - tunnel_token\n", "\n - --token-file\n - /run/secrets/tunnel_token\n", "\n depends_on:\n receiver:\n condition: service_healthy\n", + "\n networks:\n - edge\n healthcheck:\n", } { if !strings.Contains(block, want) { t.Errorf("the tunnel service lacks %q", strings.TrimSpace(want))