Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /health endpoint for watch #1237

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/spellcheck/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ humanize
io
JSON
linter
liveness
matcher
matchers
md
Expand Down
4 changes: 4 additions & 0 deletions cmd/pint/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 10 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading