mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fn: fnlb: enhancements and new grouper tests *) added healthy threshold (default: 1) *) grouper is now using configured hcEndpoint for version checks *) grouper now logs when servers switch between healthy/unhealthy status *) moved DB code out of grouper *) run health check immediately at start (don't wait until hcInterval) *) optional shutdown timeout (default: 0) & mgmt port (default: 8081) *) hot path List() in grouper now uses atomic ptr Load *) consistent router: moved closure to a new function *) bugfix: version parsing from fn servers should not panic fnlb *) bugfix: servers removed from DB, stayed in healthy list *) bugfix: if DB is down, health checker stopped monitoring *) basic new tests for grouper (add/rm/unhealthy/healthy) server
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package lb
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
ErrNoNodes = errors.New("no nodes available")
|
|
ErrUnknownCommand = errors.New("unknown command")
|
|
)
|
|
|
|
func sendValue(w http.ResponseWriter, v interface{}) {
|
|
err := json.NewEncoder(w).Encode(v)
|
|
|
|
if err != nil {
|
|
logrus.WithError(err).Error("error writing response response")
|
|
}
|
|
}
|
|
|
|
func sendSuccess(w http.ResponseWriter, msg string) {
|
|
err := json.NewEncoder(w).Encode(struct {
|
|
Msg string `json:"msg"`
|
|
}{
|
|
Msg: msg,
|
|
})
|
|
|
|
if err != nil {
|
|
logrus.WithError(err).Error("error writing response response")
|
|
}
|
|
}
|
|
|
|
func sendError(w http.ResponseWriter, code int, msg string) {
|
|
w.WriteHeader(code)
|
|
|
|
err := json.NewEncoder(w).Encode(struct {
|
|
Msg string `json:"msg"`
|
|
}{
|
|
Msg: msg,
|
|
})
|
|
|
|
if err != nil {
|
|
logrus.WithError(err).Error("error writing response response")
|
|
}
|
|
}
|
|
|
|
func NullHandler() http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
sendError(w, http.StatusNotFound, ErrUnknownCommand.Error())
|
|
})
|
|
}
|