Skip to content

Commit 232ed3f

Browse files
committed
refactor(flags): split flags into smaller files
1 parent 727d2c2 commit 232ed3f

29 files changed

Lines changed: 1297 additions & 1016 deletions

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TEST_FLAGS ?= -covermode=atomic -count=1 -parallel=4 -timeout=5m
66

77
BASE_URL ?= http://localhost:8080
88
ROUTE_PREFIX ?=
9-
CHECK_IN_PATH ?= /check-in
9+
CHECKIN_CHECKIN_PATH ?= /checkin
1010
AUTH_TOKEN ?=
1111
RUN_ARGS ?= --expected-every=5s --overdue-delay=3s
1212

@@ -90,7 +90,7 @@ run-test: ## Run a local instance with example webhook and email settings.
9090
go run . \
9191
--expected-every=5s \
9292
--alerting-delay=3s \
93-
--check-in-name=prometheus \
93+
--name=prometheus \
9494
--webhook.ops.url=https://slack.com/api/chat.postMessage \
9595
--webhook.ops.headers="Authorization=Bearer $${SLACK_TOKEN}" \
9696
--webhook.ops.template=builtin:slack-chat-post-message \
@@ -110,11 +110,11 @@ run-test: ## Run a local instance with example webhook and email settings.
110110

111111
.PHONY: check-in
112112
check-in: ## Send a local check-in request. Example: make check-in | jq .
113-
@$(CURL) $(CURL_FLAGS) $(AUTH_HEADER) -X POST "$(BASE_URL)$(ROUTE_PREFIX)$(CHECK_IN_PATH)"
113+
@$(CURL) $(CURL_FLAGS) $(AUTH_HEADER) -X POST "$(BASE_URL)$(ROUTE_PREFIX)$(CHECKIN_PATH)"
114114

115115
.PHONY: check-in-details
116116
check-in-details: ## Send a local check-in request with details. Example: make check-in-details | jq .
117-
@$(CURL) $(CURL_FLAGS) $(AUTH_HEADER) -X POST "$(BASE_URL)$(ROUTE_PREFIX)$(CHECK_IN_PATH)?details=true"
117+
@$(CURL) $(CURL_FLAGS) $(AUTH_HEADER) -X POST "$(BASE_URL)$(ROUTE_PREFIX)$(CHECKIN_PATH)?details=true"
118118

119119
.PHONY: status
120120
status: ## Send a local status request. Example: make status | jq .
@@ -165,3 +165,5 @@ endpoints-details: ## Test all local endpoints. Example: make endpoints-details
165165
.PHONY: help
166166
help: ## Display this help.
167167
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
168+
169+

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ docker run --rm -p 8080:8080 \
6565
Send a check-in:
6666

6767
```sh
68-
curl -XPOST http://localhost:8080/check-in
68+
curl -XPOST http://localhost:8080/checkin
6969
```
7070

7171
Read the current status:
@@ -100,8 +100,8 @@ Core settings:
100100
| `--listen-address` | `OVERDUE__LISTEN_ADDRESS` | `:8080` | HTTP server listen address. |
101101
| `--route-prefix` | `OVERDUE__ROUTE_PREFIX` | empty | Path prefix to mount the service under. |
102102
| `--public-url` | `OVERDUE__PUBLIC_URL` | empty | Externally reachable base URL used in notification templates. |
103-
| `--check-in-name` | `OVERDUE__CHECK_IN_NAME` | `default` | Name of the check-in monitor used in notifications. |
104-
| `--check-in-path` | `OVERDUE__CHECK_IN_PATH` | `/check-in` | Route used to receive check-ins. |
103+
| `--name` | `OVERDUE__NAME` | `default` | Name of the check-in monitor used in notifications. |
104+
| `--path` | `OVERDUE__PATH` | `/checkin` | Route used to receive check-ins. |
105105
| `--start-active` | `OVERDUE__START_ACTIVE` | `false` | Activate the monitor at startup instead of waiting for the first check-in. |
106106
| `--response-details` | `OVERDUE__RESPONSE_DETAILS` | `false` | Return detailed timing fields from check-in responses by default. |
107107
| `--auth-token` | `OVERDUE__AUTH_TOKEN` | empty | Optional bearer token required for check-in and status requests. |
@@ -113,6 +113,8 @@ Environment variables use the `OVERDUE__` prefix. Flag names are uppercased and
113113
Dynamic notification flags include the target name:
114114

115115
```text
116+
--name -> OVERDUE__NAME
117+
--path -> OVERDUE__PATH
116118
--public-url -> OVERDUE__PUBLIC_URL
117119
--webhook.ops.url -> OVERDUE__WEBHOOK_OPS_URL
118120
--webhook.ops.method -> OVERDUE__WEBHOOK_OPS_METHOD
@@ -160,20 +162,20 @@ Custom templates can be mounted into the container and referenced by path:
160162
-e OVERDUE__WEBHOOK_OPS_TEMPLATE=/etc/overdue/slack.tmpl
161163
```
162164

163-
Webhook templates must render valid JSON. Email templates may render text or HTML. When `--public-url` is configured, templates can use `.App.PublicURL`, `.App.CheckInURL`, and `.App.StatusURL`.
165+
Webhook templates must render valid JSON. Email templates may render text or HTML. When `--public-url` is configured, templates can use `.App.Version`, `.App.PublicURL`, `.App.CheckInURL`, and `.App.StatusURL`.
164166

165167
See [docs/templates.md](docs/templates.md) for built-in templates, template data, and helper functions.
166168

167169
## HTTP API
168170

169171
| Method | Path | Description |
170172
| ------------- | ----------- | -------------------------- |
171-
| `GET`, `POST` | `/check-in` | Records a check-in. |
173+
| `GET`, `POST` | `/checkin` | Records a check-in. |
172174
| `GET` | `/status` | Returns the monitor state. |
173175
| `GET` | `/version` | Returns build information. |
174176
| `GET`, `POST` | `/healthz` | Returns a health response. |
175177

176-
The check-in path is configurable with `--check-in-path`. The other routes are mounted under `--route-prefix` when a route prefix is configured.
178+
The check-in endpoint path is configurable with `--path`. The other routes are mounted under `--route-prefix` when a route prefix is configured.
177179

178180
See [docs/api.md](docs/api.md) for response examples and route prefix details.
179181

docs/api.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Overdue exposes a small HTTP API.
44

55
| Method | Path | Description | Auth required with `--auth-token` |
66
| ------------- | ----------- | -------------------------- | --------------------------------- |
7-
| `GET`, `POST` | `/check-in` | Records a check-in. | yes |
7+
| `GET`, `POST` | `/checkin` | Records a check-in. | yes |
88
| `GET` | `/status` | Returns monitor state. | yes |
99
| `GET` | `/version` | Returns build information. | no |
1010
| `GET`, `POST` | `/healthz` | Returns `ok`. | no |
1111

12-
The check-in path is configurable with `--check-in-path`.
12+
The check-in endpoint path is configurable with `--path`.
1313

1414
The other routes are mounted under `--route-prefix` when a route prefix is configured.
1515

16-
## `GET /check-in` and `POST /check-in`
16+
## `GET /checkin` and `POST /checkin`
1717

1818
Records a check-in.
1919

@@ -215,8 +215,8 @@ overdue \
215215
Routes become:
216216

217217
```text
218-
GET /overdue/check-in
219-
POST /overdue/check-in
218+
GET /overdue/checkin
219+
POST /overdue/checkin
220220
GET /overdue/status
221221
GET /overdue/version
222222
GET /overdue/healthz
@@ -236,3 +236,5 @@ This becomes:
236236
```
237237

238238

239+
240+

docs/configuration.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Environment variables use the `OVERDUE__` prefix. Flag names are uppercased and
99
```text
1010
--expected-every -> OVERDUE__EXPECTED_EVERY
1111
--alerting-delay -> OVERDUE__ALERTING_DELAY
12-
--check-in-name -> OVERDUE__CHECK_IN_NAME
12+
--name -> OVERDUE__NAME
13+
--path -> OVERDUE__PATH
1314
--public-url -> OVERDUE__PUBLIC_URL
1415
--response-details -> OVERDUE__RESPONSE_DETAILS
1516
```
@@ -40,8 +41,8 @@ Dynamic notification flags include the target name:
4041
| `--listen-address` | `OVERDUE__LISTEN_ADDRESS` | `:8080` | HTTP server listen address. |
4142
| `--route-prefix` | `OVERDUE__ROUTE_PREFIX` | empty | Path prefix to mount the service under. |
4243
| `--public-url` | `OVERDUE__PUBLIC_URL` | empty | Externally reachable base URL used in notification templates. |
43-
| `--check-in-name` | `OVERDUE__CHECK_IN_NAME` | `default` | Name of the check-in monitor used in notifications. |
44-
| `--check-in-path` | `OVERDUE__CHECK_IN_PATH` | `/check-in` | Route used to receive check-ins. |
44+
| `--name` | `OVERDUE__NAME` | `default` | Name of the check-in monitor used in notifications. |
45+
| `--path` | `OVERDUE__PATH` | `/checkin` | Route used to receive check-ins. |
4546
| `--expected-every` | `OVERDUE__EXPECTED_EVERY` | required | Maximum time between check-ins. |
4647
| `--alerting-delay` | `OVERDUE__ALERTING_DELAY` | required | Extra time after the expected deadline before notifications fire. |
4748
| `--start-active` | `OVERDUE__START_ACTIVE` | `false` | Activate the monitor at startup instead of waiting for the first check-in. |
@@ -114,8 +115,8 @@ overdue \
114115
Routes become:
115116

116117
```text
117-
GET /overdue/check-in
118-
POST /overdue/check-in
118+
GET /overdue/checkin
119+
POST /overdue/checkin
119120
GET /overdue/status
120121
GET /overdue/version
121122
GET /overdue/healthz
@@ -141,14 +142,15 @@ Use `--public-url` to expose externally reachable links to notification template
141142
```sh
142143
overdue \
143144
--public-url=https://example.com/overdue \
144-
--check-in-path=/check-in \
145+
--path=/checkin \
145146
--expected-every=1m \
146147
--alerting-delay=10s
147148
```
148149

149150
Templates can then use:
150151

151152
```gotemplate
153+
{{ .App.Version }}
152154
{{ .App.PublicURL }}
153155
{{ .App.CheckInURL }}
154156
{{ .App.StatusURL }}
@@ -158,13 +160,13 @@ With the example above, those values are:
158160

159161
```text
160162
.App.PublicURL = https://example.com/overdue
161-
.App.CheckInURL = https://example.com/overdue/check-in
163+
.App.CheckInURL = https://example.com/overdue/checkin
162164
.App.StatusURL = https://example.com/overdue/status
163165
```
164166

165167
## Authentication
166168

167-
Set `--auth-token` to require bearer-token auth for `/check-in` and `/status`.
169+
Set `--auth-token` to require bearer-token auth for `/checkin` and `/status`.
168170

169171
```sh
170172
overdue \
@@ -184,7 +186,7 @@ export OVERDUE__AUTH_TOKEN=0123456789abcdef0123456789abcdef
184186
Send authorized requests:
185187

186188
```sh
187-
curl -XPOST http://localhost:8080/check-in \
189+
curl -XPOST http://localhost:8080/checkin \
188190
-H 'Authorization: Bearer 0123456789abcdef0123456789abcdef'
189191

190192
curl http://localhost:8080/status \

docs/deployment.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ docker run --rm -p 8080:8080 \
2828
Check in:
2929

3030
```sh
31-
curl -XPOST http://localhost:8080/check-in \
31+
curl -XPOST http://localhost:8080/checkin \
3232
-H "Authorization: Bearer $OVERDUE_TOKEN"
3333
```
3434

@@ -97,3 +97,5 @@ The top-level directory command applies the core manifests only. Apply the optio
9797
Expose the service through your ingress or gateway as usual.
9898

9999
If Overdue is mounted below a path prefix, set `OVERDUE__ROUTE_PREFIX` and make sure your ingress forwards the same prefix.
100+
101+

docs/notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ And this creates an email target named `primary`:
2323

2424
If no notification targets are configured, Overdue still runs and records status, but sends no notifications.
2525

26-
Set `--public-url` when notification templates should include externally reachable Overdue links. The value is exposed as `.App.PublicURL`; `.App.CheckInURL` and `.App.StatusURL` are derived from it.
26+
Set `--public-url` when notification templates should include externally reachable Overdue links. The value is exposed as `.App.PublicURL`; `.App.CheckInURL` and `.App.StatusURL` are derived from it. `.App.Version` is always available.
2727

2828
## Environment variables
2929

docs/templates.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Notification templates receive a check-in lifecycle event.
6363
| `.Resolved` | bool | `true` for resolved notifications. |
6464
| `.Title` | string | Rendered notification title. Available in body and subject templates. |
6565
| `.Text` | string | Rendered notification text. Available in body templates. |
66-
| `.App` | struct | Application link data derived from `--public-url`. Empty when no public URL is configured. |
66+
| `.App` | struct | Application metadata and links. URL fields are empty when no public URL is configured. |
6767
| `.CustomData` | map[string]string | Target-local custom data from `--webhook.<name>.custom-data` or `--email.<name>.custom-data`. |
6868

69-
`.App` contains `.App.PublicURL`, `.App.CheckInURL`, and `.App.StatusURL`. `--public-url` is the externally reachable base URL and may include a path prefix. `.App.CheckInURL` appends the configured check-in path, and `.App.StatusURL` appends `/status`.
69+
`.App` contains `.App.Version`, `.App.PublicURL`, `.App.CheckInURL`, and `.App.StatusURL`. `--public-url` is the externally reachable base URL and may include a path prefix. `.App.CheckInURL` appends the configured path, and `.App.StatusURL` appends `/status`.
7070

7171
Custom data keys that are valid Go template identifiers can be read with dot notation, such as `.CustomData.channel`. Other keys can be read with `index`, such as `{{ index .CustomData "team-name" }}`.
7272

@@ -76,6 +76,7 @@ Example:
7676
{{ .Title }}
7777
7878
Check-in: {{ .CheckInName }}
79+
Version: {{ .App.Version }}
7980
Status: {{ .Status }}
8081
Channel: {{ .CustomData.channel | default "alertmanager" | withPrefix "#" }}
8182
Status URL: {{ .App.StatusURL }}

internal/app/run.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ func Run(
4747
"listenAddr", flags.ListenAddr,
4848
"routePrefix", flags.RoutePrefix,
4949
"publicURL", flags.PublicURL,
50-
"checkInName", flags.CheckInName,
51-
"checkInPath", flags.CheckInPath,
52-
"expectedEvery", flags.ExpectedEvery.String(),
53-
"alertingDelay", flags.AlertingDelay.String(),
54-
"startActive", flags.StartActive,
50+
"name", flags.CheckIn.Name,
51+
"path", flags.CheckIn.Path,
52+
"expectedEvery", flags.CheckIn.ExpectedEvery.String(),
53+
"alertingDelay", flags.CheckIn.AlertingDelay.String(),
54+
"startActive", flags.CheckIn.StartActive,
5555
"responseDetails", flags.ResponseDetails,
5656
"initialPhase", monitor.PhaseScheduled,
5757
)
5858

5959
if err := notifier.ValidateRuntimeTemplates(
6060
templateFS,
6161
flags.Notify,
62-
flags.CheckInName,
63-
flags.ExpectedEvery,
64-
flags.AlertingDelay,
62+
flags.CheckIn.Name,
63+
flags.CheckIn.ExpectedEvery,
64+
flags.CheckIn.AlertingDelay,
6565
); err != nil {
6666
setupLog.Error("notification template validation error", "error", err)
6767
return err
@@ -83,21 +83,21 @@ func Run(
8383
defer stop()
8484

8585
mon := monitor.New(
86-
flags.CheckInName,
87-
flags.ExpectedEvery,
88-
flags.AlertingDelay,
86+
flags.CheckIn.Name,
87+
flags.CheckIn.ExpectedEvery,
88+
flags.CheckIn.AlertingDelay,
8989
logger.With("component", "monitor"),
9090
)
9191

9292
sched := scheduler.New(mon, notify, reg, logger.With("component", "scheduler"))
93-
if flags.StartActive {
93+
if flags.CheckIn.StartActive {
9494
activatedAt := time.Now()
9595
sched.RecordCheckIn(activatedAt)
9696
setupLog.Info(
9797
"check-in monitor activated at startup",
9898
"activatedAt", activatedAt,
99-
"expectedBy", activatedAt.Add(flags.ExpectedEvery),
100-
"alertingAt", activatedAt.Add(flags.ExpectedEvery+flags.AlertingDelay),
99+
"expectedBy", activatedAt.Add(flags.CheckIn.ExpectedEvery),
100+
"alertingAt", activatedAt.Add(flags.CheckIn.ExpectedEvery+flags.CheckIn.AlertingDelay),
101101
)
102102
}
103103
sched.Run(ctx)
@@ -113,14 +113,14 @@ func Run(
113113
logger.With("component", "api"),
114114
)
115115

116-
router := routes.NewRouter(flags.CheckInPath, flags.RoutePrefix, api)
116+
router := routes.NewRouter(flags.CheckIn.Path, flags.RoutePrefix, api)
117117
if err := server.Run(
118118
ctx,
119-
flags.ListenAddr,
119+
flags.ListenAddr.String(),
120120
router,
121121
logger.With("component", "server"),
122122
); err != nil {
123-
setupLog.Error("server run", "listenAddr", flags.ListenAddr, "error", err)
123+
setupLog.Error("server run", "listenAddr", flags.ListenAddr.String(), "error", err)
124124
return err
125125
}
126126

internal/app/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestRun(t *testing.T) {
4141

4242
waitForHTTPStatus(t, client, baseURL+"/healthz", http.MethodGet, http.StatusOK)
4343

44-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+"/check-in", nil)
44+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+"/checkin", nil)
4545
require.NoError(t, err)
4646

4747
resp, err := client.Do(req)

0 commit comments

Comments
 (0)