Skip to content

Commit

Permalink
upgrade log to panic (#542)
Browse files Browse the repository at this point in the history
Currently, if the `admin.Serve()` crashes, the resulting error is logged with a warning and the process keeps chugging along without everything it provides (like metrics). Upgrading the log to a Panicw will cause the go routine to panic and crash the program meaning the software can never be in a state where the metrics server is not also running successfully.
  • Loading branch information
migleeson authored Jul 14, 2022
1 parent f695615 commit 0bba92c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion httpbp/admin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package httpbp

import (
"errors"
"net/http"

"github.com/reddit/baseplate.go/internal/admin"
"github.com/reddit/baseplate.go/log"
)
Expand All @@ -15,5 +18,9 @@ import (
// This function blocks, so it should be run as its own goroutine.
func ServeAdmin(healthCheck HandlerFunc) {
admin.Mux.Handle("/health", handler{handle: healthCheck})
log.Warnw("httpbp: admin serving exited", "err", admin.Serve())
if err := admin.Serve(); errors.Is(err, http.ErrServerClosed) {
log.Info("httpbp: admin server closed")
} else {
log.Panicw("httpbp: admin serving failed", "err", err)
}
}
9 changes: 8 additions & 1 deletion thriftbp/admin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package thriftbp

import (
"errors"
"net/http"

"github.com/reddit/baseplate.go/internal/admin"
"github.com/reddit/baseplate.go/log"
)
Expand All @@ -13,5 +16,9 @@ import (
//
// This function blocks, so it should be run as its own goroutine.
func ServeAdmin() {
log.Warnw("thriftbp: admin serving exited", "err", admin.Serve())
if err := admin.Serve(); errors.Is(err, http.ErrServerClosed) {
log.Info("thriftbp: admin server closed")
} else {
log.Panicw("thriftbp: admin serving failed", "err", err)
}
}

0 comments on commit 0bba92c

Please sign in to comment.