Skip to content

Commit

Permalink
Add a simple health check
Browse files Browse the repository at this point in the history
  • Loading branch information
supergibbs authored and mcrute committed Jan 8, 2025
1 parent 2047cad commit 0c3a855
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ expected by Go's http.Server.
Prometheus metric serving (though not metric aggregation) can be
disabled by passing ``--disable-prometheus`` on the command line.

## Health Check Integration

A simple health check can be enabled by passing `--enable-health-check`
on the command line. A JSON response will be served on `:3000` at the
path `/health` by default. The bind address and port can be
customized by passing `--health-check-bind=bind-string` in the format
expected by Go's http.Server. A sample response:

```json
{ "name": "ses-smtp-proxy", "status": "ok", "version": "v1.3.0" }
```

## Usage
By default the command takes no arguments and will listen on port 2500 on all
interfaces. The listen interfaces and port can be specified as the only
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func main() {
vaultPath := flag.String("vault-path", "", "Full path to Vault credential (ex: \"aws/creds/my-mail-user\")")
showVersion := flag.Bool("version", false, "Show program version")
configurationSetName := flag.String("configuration-set-name", "", "Configuration set name with which SendRawEmail will be invoked")
enableHealthCheck := flag.Bool("enable-health-check", false, "Enable health check server")
healthCheckBind := flag.String("health-check-bind", ":3000", "Address/port on which to bind health check server")

flag.Parse()

Expand All @@ -253,6 +255,16 @@ func main() {
return
}

if *enableHealthCheck {
sm := http.NewServeMux()
ps := &http.Server{Addr: *healthCheckBind, Handler: sm}
sm.Handle("/health", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
w.Write([]byte("{\"name\": \"ses-smtp-proxy\", \"status\": \"ok\", \"version\": \"" + version + "\"}"))
}))
go ps.ListenAndServe()
}

credentialError := make(chan error, 2)
sesClient, err := makeSesClient(ctx, *enableVault, *vaultPath, credentialError)
if err != nil {
Expand Down

0 comments on commit 0c3a855

Please sign in to comment.