Skip to content

Commit 6ae6524

Browse files
committed
fix: sync docs with codebase — startup/shutdown sequences, API names, missing package
- architecture.md: fix startup sequence order (handlers register before servers start, not after), expand shutdown sequence to match actual code (9 steps including admin server, graceful stop, force stop), correct options API from Set/Get to AddToOptions/FromContext, add admin port to deployment topology diagram - Packages.md: add missing options package entry - integrations.md: fix Sentry env var RELEASE → RELEASE_NAME - production.md, signals.md: add admin server shutdown step - Index.md: add link to full interceptor chain from simplified diagram
1 parent fee649f commit 6ae6524

6 files changed

Lines changed: 52 additions & 27 deletions

File tree

Index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Run `buf generate` — it creates typed Go interfaces from your proto definition
117117
│ │
118118
│ /metrics /healthcheck /debug/pprof │
119119
└─────────────────────────────────────────┘
120+
121+
See the [full interceptor chain](/architecture#server-interceptor-chain) for all 10 interceptors including timeout, rate limiting, debug logging, and New Relic.
120122
```
121123

122124
## Packages

Packages.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ hystrixprometheus provides a Prometheus metrics collector for Hystrix (https://g
5555

5656
Documentation can be found at [hystrixprometheus-docs]
5757

58+
## [Options]
59+
options is a request-scoped key-value store that propagates metadata through `context.Context` using RWMutex+map. Used by interceptors to pass metadata between layers. Only string keys are supported.
60+
61+
Documentation can be found at [options-docs]
62+
5863
## [grpcpool]
5964
grpcpool is a pool of grpc.ClientConns that can be used to make requests to a grpc server. It implements grpc.ClientConnInterface to enable it to be used directly with generated proto stubs.
6065

@@ -93,4 +98,6 @@ Documentation can be found at [data-builder-docs]
9398
[workers-docs]: https://pkg.go.dev/github.com/go-coldbrew/workers
9499
[Data Builder]: https://github.com/go-coldbrew/data-builder/tree/main#readme
95100
[data-builder-docs]: https://pkg.go.dev/github.com/go-coldbrew/data-builder
101+
[Options]: https://github.com/go-coldbrew/options/tree/main#readme
102+
[options-docs]: https://pkg.go.dev/github.com/go-coldbrew/options
96103
[envconfig]: https://github.com/kelseyhightower/envconfig

architecture.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ ColdBrew uses `context.Context` to propagate metadata through every layer:
275275
context.Context
276276
277277
├── options (key-value metadata)
278-
│ Set: options.Set(ctx, key, value)
279-
│ Get: options.Get(ctx, key)
278+
│ Set: options.AddToOptions(ctx, key, value)
279+
│ Get: options.FromContext(ctx).Get(key)
280280
281281
├── log fields (per-request structured logging)
282282
│ Add: log.AddToContext(ctx, key, value)
@@ -299,7 +299,7 @@ Every interceptor reads from and writes to the context. By the time the request
299299

300300
## Deployment Topology
301301

302-
A typical ColdBrew service exposes two ports:
302+
A typical ColdBrew service exposes two ports (optionally three with `ADMIN_PORT`):
303303

304304
```
305305
┌─────────────────────────────────────────┐
@@ -314,10 +314,18 @@ A typical ColdBrew service exposes two ports:
314314
│ ├── /api/... (REST gateway) │
315315
│ ├── /healthcheck (liveness probe) │
316316
│ ├── /readycheck (readiness probe) │
317+
│ ├── /metrics (Prometheus)* │
318+
│ ├── /swagger/ (OpenAPI UI)* │
319+
│ └── /debug/pprof/ (profiling)* │
320+
│ │
321+
│ ADMIN_PORT (optional, e.g. 9092) │
317322
│ ├── /metrics (Prometheus) │
318323
│ ├── /swagger/ (OpenAPI UI) │
319324
│ └── /debug/pprof/ (profiling) │
320325
└─────────────────────────────────────────┘
326+
327+
* When ADMIN_PORT is set, these endpoints move
328+
to the admin port and are removed from 9091.
321329
```
322330

323331
### Kubernetes Integration
@@ -365,19 +373,25 @@ func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResp
365373

366374
### Startup Sequence
367375

368-
1. Configuration loaded from environment variables
369-
2. Interceptor chain assembled (init-only, not thread-safe)
370-
3. gRPC server starts on port 9090
371-
4. HTTP gateway starts on port 9091
372-
5. Service registers handlers (`InitGRPC`, `InitHTTP`)
373-
6. Service marks itself as ready (`SetReady()`)
374-
7. Server blocks until shutdown signal
376+
1. Configuration loaded from environment variables (`core.New(cfg)`)
377+
2. Interceptor chain assembled during `init()` (not thread-safe)
378+
3. gRPC server created, service registers handlers (`InitGRPC`)
379+
4. Unix socket created for gateway (if `DISABLE_UNIX_GATEWAY=false`)
380+
5. HTTP server created, service registers handlers (`InitHTTP`)
381+
6. gRPC and HTTP servers start listening concurrently
382+
7. Admin server starts (if `ADMIN_PORT` is set)
383+
8. Server blocks until shutdown signal
375384

376385
### Shutdown Sequence
377386

378387
1. SIGTERM/SIGINT received
379-
2. Service marked as not ready (`/readycheck` returns unhealthy)
380-
3. Kubernetes stops routing new traffic
381-
4. In-flight requests allowed to complete
382-
5. `Stop()` called on the service (your cleanup logic)
383-
6. Server exits
388+
2. `FailCheck(true)` on `CBGracefulStopper` services — `/readycheck` starts failing
389+
3. Wait `GRPC_GRACEFUL_DURATION_IN_SECONDS` (default 7s) for load balancer to drain
390+
4. Shutdown admin server (if configured)
391+
5. Shutdown HTTP server (stop accepting new requests)
392+
6. `GracefulStop()` gRPC server (finish in-flight RPCs, reject new ones)
393+
7. Force-stop gRPC server if graceful shutdown didn't complete in time
394+
8. `Stop()` called on `CBStopper` services (your cleanup logic)
395+
9. Exit
396+
397+
See [Signal Handling and Graceful Shutdown](/howto/signals) for configuration and tuning details.

howto/production.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ ColdBrew's shutdown sequence (bounded by `SHUTDOWN_DURATION_IN_SECONDS`, default
179179
1. Receive SIGTERM from Kubernetes
180180
2. `FailCheck(true)` on `CBGracefulStopper` services — `/readycheck` starts failing
181181
3. Wait `GRPC_GRACEFUL_DURATION_IN_SECONDS` (default: 7s, included in shutdown timeout) for the load balancer to drain
182-
4. Shutdown HTTP server (stop accepting new requests)
183-
5. `GracefulStop()` gRPC server (finish in-flight RPCs, reject new ones)
184-
6. Force-stop gRPC server if graceful shutdown didn't complete in time
185-
7. Call `Stop()` on `CBStopper` services — close database pools, flush metrics, drain message producers
186-
8. Exit
182+
4. Shutdown admin server if configured (`ADMIN_PORT`)
183+
5. Shutdown HTTP server (stop accepting new requests)
184+
6. `GracefulStop()` gRPC server (finish in-flight RPCs, reject new ones)
185+
7. Force-stop gRPC server if graceful shutdown didn't complete in time
186+
8. Call `Stop()` on `CBStopper` services — close database pools, flush metrics, drain message producers
187+
9. Exit
187188

188189
Tune these values based on your service:
189190

howto/signals.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ When the application receives a signal, ColdBrew executes a multi-step shutdown
3131

3232
1. **`FailCheck(true)`** on services implementing [CBGracefulStopper]`/readycheck` starts returning failure
3333
2. **Wait** `GRPC_GRACEFUL_DURATION_IN_SECONDS` (default: 7s) for the load balancer to stop sending traffic
34-
3. **Shutdown HTTP server** — stop accepting new HTTP requests
35-
4. **`GracefulStop()` gRPC server** — finish in-flight RPCs, reject new ones
36-
5. **Force-stop gRPC server** if graceful shutdown didn't complete in time
37-
6. **`Stop()`** on services implementing [CBStopper] — resource cleanup
38-
7. **Exit**
34+
3. **Shutdown admin server** if configured (`ADMIN_PORT`)
35+
4. **Shutdown HTTP server** — stop accepting new HTTP requests
36+
5. **`GracefulStop()` gRPC server** — finish in-flight RPCs, reject new ones
37+
6. **Force-stop gRPC server** if graceful shutdown didn't complete in time
38+
7. **`Stop()`** on services implementing [CBStopper] — resource cleanup
39+
8. **Exit**
3940

4041
## Customizing the shutdown process
4142

4243
Configuring the shutdown process is done by setting the [config] values:
4344

44-
- `SHUTDOWN_DURATION_IN_SECONDS` - Timeout for the entire `Stop()` sequence (default: 15s), covering steps 2-7 above including the drain wait. After this, the process exits regardless.
45+
- `SHUTDOWN_DURATION_IN_SECONDS` - Timeout for the entire `Stop()` sequence (default: 15s), covering steps 2-8 above including the drain wait. After this, the process exits regardless.
4546
- `GRPC_GRACEFUL_DURATION_IN_SECONDS` - Duration of step 2 — how long to wait after failing `/readycheck` before stopping servers (default: 7s). This is **included within** `SHUTDOWN_DURATION_IN_SECONDS`, not additional to it.
4647
- `DISABLE_SIGNAL_HANDLER` - If set to `true`, ColdBrew will not register a signal handler (useful when you want to handle signals yourself).
4748

integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ See the [Metrics How-To](/howto/Metrics/) for details on which metrics are expor
9999
To configure Sentry, set the following environment variables as defined in [Config]
100100
- `SENTRY_DSN`: Sentry DSN
101101
- `ENVIRONMENT`: Environment (e.g. `production`)
102-
- `RELEASE`: App release (e.g. `v1.0.0`)
102+
- `RELEASE_NAME`: App release (e.g. `v1.0.0`)
103103

104104
### Initialising
105105

0 commit comments

Comments
 (0)