Skip to content

Commit

Permalink
Add /health endpoint for watch
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Jan 2, 2025
1 parent ddebf43 commit 79ff76b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit 79ff76b

Please sign in to comment.