Skip to content

Commit

Permalink
Add a health check endpoint (#2)
Browse files Browse the repository at this point in the history
* Add a health check endpoint

* Change comments
  • Loading branch information
tzjames authored Jun 26, 2024
1 parent 3680ab5 commit 27867de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ COPY --from=builder /go/src/app/smokescreen /usr/local/bin/smokescreen
RUN apk add --no-cache gcompat

EXPOSE 4750
# For the health check
EXPOSE 4751

CMD ["smokescreen"]
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"net/http"

Expand All @@ -23,7 +24,21 @@ func defaultRoleFromRequest(req *http.Request) (string, error) {
return req.TLS.PeerCertificates[0].Subject.CommonName, nil
}

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK")
}

func startHealthCheckServer() {
http.HandleFunc("/healthcheck", healthCheckHandler)
// Run the health check server on a different port than smokescreen proxy
go func() {
log.Fatal(http.ListenAndServe(":4751", nil))
}()
}

func main() {
startHealthCheckServer()

conf, err := cmd.NewConfiguration(nil, nil)
if err != nil {
logrus.Fatalf("Could not create configuration: %v", err)
Expand Down

0 comments on commit 27867de

Please sign in to comment.