Skip to content

Commit 79ff76b

Browse files
committed
Add /health endpoint for watch
1 parent ddebf43 commit 79ff76b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

cmd/pint/watch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78
"log/slog"
89
"net/http"
910
_ "net/http/pprof"
@@ -180,6 +181,9 @@ func actionWatch(c *cli.Context, meta actionMeta, f pathFinderFunc) error {
180181
rulesParsedTotal.WithLabelValues(config.RecordingRuleType).Add(0)
181182
rulesParsedTotal.WithLabelValues(config.InvalidRuleType).Add(0)
182183

184+
http.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
185+
_, _ = io.WriteString(w, "OK\n")
186+
})
183187
http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{
184188
ErrorLog: slog.NewLogLogger(slog.Default().Handler(), slog.LevelError),
185189
Timeout: time.Second * 20,

docs/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.70.0
4+
5+
### Added
6+
7+
- When running `pint watch` command `/health` HTTP endpoint can now be used for liveness probes.
8+
39
## v0.69.1
410

511
### Fixed

docs/index.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ Run pint as a daemon in watch mode where it continuously checks
152152
all rules found in selected files and exposes metrics about
153153
found problems.
154154

155+
By default it will start a HTTP server on port `8080` and run all checks every
156+
10 minutes. This can be customised by passing extra flags to the `watch` command.
157+
Run `pint watch -h` to see all available flags.
158+
159+
Currently supported HTTP paths:
160+
161+
- `/health` - static endpoint for liveness probes.
162+
- `/metrics` - returns Prometheus metrics, see below.
163+
155164
#### Manually selecting files and directories
156165

157166
You can tell it to continuously test specific files or directories:
@@ -203,11 +212,7 @@ pint watch rule_files local
203212

204213
#### Accessing watch mode metrics
205214

206-
By default it will start a HTTP server on port `8080` and run all checks every
207-
10 minutes. This can be customised by passing extra flags to the `watch` command.
208-
Run `pint watch -h` to see all available flags.
209-
210-
Query `/metrics` to see all expose metrics, example with default flags:
215+
Query `/metrics` HTTP endpoint to see all expose metrics, example with default flags:
211216

212217
```shell
213218
curl -s http://localhost:8080/metrics

0 commit comments

Comments
 (0)