Skip to content

Commit

Permalink
Add custom health check endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Povilas Vaitkus <[email protected]>
  • Loading branch information
PovilasV1 committed Dec 10, 2024
1 parent 231987c commit d5394a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w
| `web.systemd-socket` | No | | Use systemd socket activation listeners instead of port listeners (Linux only). |
| `web.stackdriver-telemetry-path` | No | `/metrics` | Path under which to expose Stackdriver metrics. |
| `web.telemetry-path` | No | `/metrics` | Path under which to expose Prometheus metrics |
| `web.health-check-path` | No | `/heath` | Path under which to expose health check |

### TLS and basic authentication

Expand Down
11 changes: 11 additions & 0 deletions stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var (
"web.stackdriver-telemetry-path", "Path under which to expose Stackdriver metrics.",
).Default("/metrics").String()

healthCheckPath = kingpin.Flag(
"web.health-check-path", "Path under which to expose health check.",
).Default("/health").String()

projectID = kingpin.Flag(
"google.project-id", "DEPRECATED - Comma seperated list of Google Project IDs. Use 'google.project-ids' instead.",
).String()
Expand Down Expand Up @@ -275,6 +279,8 @@ func main() {
kingpin.HelpFlag.Short('h')
kingpin.Parse()

http.HandleFunc(*healthCheckPath, healthCheckHandler)

logger := promslog.New(promslogConfig)
if *projectID != "" {
logger.Warn("The google.project-id flag is deprecated and will be replaced by google.project-ids.")
Expand Down Expand Up @@ -432,3 +438,8 @@ func parseMetricExtraFilters() []collectors.MetricFilter {
}
return extraFilters
}

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}

0 comments on commit d5394a7

Please sign in to comment.