From 79ff76b3c0a4af47e365916035777eca5c046ad4 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 2 Jan 2025 12:23:19 +0000 Subject: [PATCH] Add /health endpoint for watch --- cmd/pint/watch.go | 4 ++++ docs/changelog.md | 6 ++++++ docs/index.md | 15 ++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cmd/pint/watch.go b/cmd/pint/watch.go index 2550cf6c..23e1181d 100644 --- a/cmd/pint/watch.go +++ b/cmd/pint/watch.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" "log/slog" "net/http" _ "net/http/pprof" @@ -180,6 +181,9 @@ func actionWatch(c *cli.Context, meta actionMeta, f pathFinderFunc) error { rulesParsedTotal.WithLabelValues(config.RecordingRuleType).Add(0) rulesParsedTotal.WithLabelValues(config.InvalidRuleType).Add(0) + http.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) { + _, _ = io.WriteString(w, "OK\n") + }) http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{ ErrorLog: slog.NewLogLogger(slog.Default().Handler(), slog.LevelError), Timeout: time.Second * 20, diff --git a/docs/changelog.md b/docs/changelog.md index 1c5f2eaa..33242812 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,11 @@ # Changelog +## v0.70.0 + +### Added + +- When running `pint watch` command `/health` HTTP endpoint can now be used for liveness probes. + ## v0.69.1 ### Fixed diff --git a/docs/index.md b/docs/index.md index aae1bf45..62c4038c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -152,6 +152,15 @@ Run pint as a daemon in watch mode where it continuously checks all rules found in selected files and exposes metrics about found problems. +By default it will start a HTTP server on port `8080` and run all checks every +10 minutes. This can be customised by passing extra flags to the `watch` command. +Run `pint watch -h` to see all available flags. + +Currently supported HTTP paths: + +- `/health` - static endpoint for liveness probes. +- `/metrics` - returns Prometheus metrics, see below. + #### Manually selecting files and directories You can tell it to continuously test specific files or directories: @@ -203,11 +212,7 @@ pint watch rule_files local #### Accessing watch mode metrics -By default it will start a HTTP server on port `8080` and run all checks every -10 minutes. This can be customised by passing extra flags to the `watch` command. -Run `pint watch -h` to see all available flags. - -Query `/metrics` to see all expose metrics, example with default flags: +Query `/metrics` HTTP endpoint to see all expose metrics, example with default flags: ```shell curl -s http://localhost:8080/metrics