Skip to content

About

Go REST ledger service with OpenTelemetry, Prometheus SLO burn-rate alerting, Grafana, and GCP (Cloud Run/GKE) deployment tooling

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ledger-api

CI

A small ledger REST service (accounts + idempotent transfers) in Go, built as a portfolio piece to demonstrate production-style observability and reliability-engineering practice: OpenTelemetry tracing/metrics, RED dashboards, a multi-window burn-rate SLO alert with a promtool-verified unit test, a scripted incident + blameless postmortem, and GCP packaging (Cloud Run + Cloud SQL via Terraform, plus GKE manifests) that is written but not deployed.

Status (read this first)

  • Not deployed anywhere. No live URL, no real traffic, no cloud spend.
  • The Terraform in deploy/terraform/ and the manifests in deploy/k8s/ are packaging, meant to demonstrate GCP/K8s deployment shape — they have not been terraform apply'd or kubectl apply'd against a real cluster.
  • The code was written and reasoned about carefully, but not compiled or run locally — this environment had no Go toolchain, Docker, Terraform, or gcloud installed. CI (.github/workflows/ci.yml) is the first place everything actually gets vetted, linted, built, and tested. See go.sum below — it doesn't exist yet; run go mod tidy before building.
  • docs/postmortem-001.md documents a scripted incident (triggered deliberately via the fault-injection endpoint against the local docker-compose stack), not a real production outage.

Architecture

flowchart LR
    client[Client] -->|HTTP| api[ledger-api\nnet/http + slog]
    api -->|pgx v5| pg[(PostgreSQL)]
    api -->|OTLP gRPC| otelc[OTel Collector]
    otelc --> tempo[(Tempo\ntraces)]
    otelc --> prom[(Prometheus\nmetrics)]
    api -->|/metrics scrape| prom
    prom --> grafana[Grafana\nRED dashboard]
    prom -->|burn-rate rules| alerts[Alertmanager-style\nalert rules]
    tempo --> grafana

    subgraph GCP packaging - not deployed
      cloudrun[Cloud Run]
      cloudsql[(Cloud SQL Postgres)]
      artifact[Artifact Registry]
      monitoring[Cloud Monitoring\nalert + uptime check]
    end
Loading

API

Route Method Purpose
/accounts POST Create an account (owner, currency)
/accounts/{id} GET Fetch an account
/transfers POST Create a transfer; requires Idempotency-Key header
/healthz GET Liveness probe
/readyz GET Readiness probe (pings the store)
/metrics GET Prometheus metrics
/admin/fault GET/PUT Fault injection (latency/error-rate); only registered when LEDGER_FAULT_INJECTION_ENABLED=true

Storage backend is chosen via LEDGER_STORE_BACKEND (memory or postgres); see internal/config/config.go for every environment variable and its default.

Local run

docker compose -f deploy/local/docker-compose.yml up --build

This starts the API, Postgres, an OTel Collector, Prometheus (with the burn-rate alert rules loaded), Grafana (pre-provisioned RED dashboard at http://localhost:3000, anonymous viewer access enabled), and Tempo.

Generate some traffic:

./scripts/load.sh http://localhost:8080 60 5

Tests

go mod tidy                 # generates go.sum (not committed — see Status)
go vet ./...
go test -race -cover ./...                          # unit tests (memory store, handlers, idempotency)
go test -tags=integration ./internal/store/...       # requires a live Postgres via LEDGER_TEST_POSTGRES_DSN

CI runs the promtool unit test proving the burn-rate alert fires on a simulated incident:

docker run --rm -v "$PWD/deploy/local/prometheus:/rules" \
  prom/prometheus:v2.54.0 promtool test rules /rules/alerts_test.yml

SLO summary

99.9% availability over a rolling 30-day window (0.1% error budget). Alerted via a two-tier multi-window burn-rate rule (14.4x over 5m+1h -> page, 6x over 30m+6h -> ticket). Full SLI definition and error-budget math in docs/slo.md; the incident that exercises it is in docs/postmortem-001.md; operational response is in docs/runbook.md.

Tech

Go 1.23 (stdlib net/http), pgx v5, OpenTelemetry Go SDK (OTLP export), Prometheus client_golang, Grafana, Tempo, Terraform (Cloud Run / Cloud SQL / Artifact Registry / Cloud Monitoring), Kubernetes/GKE manifests (Deployment/Service/HPA/ServiceMonitor), GitHub Actions CI.

License

MIT — see LICENSE.

About

Go REST ledger service with OpenTelemetry, Prometheus SLO burn-rate alerting, Grafana, and GCP (Cloud Run/GKE) deployment tooling

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages