Update go.mod and Prometheus version

Updates various internal dependencies in go.mod, and Prometheus
within docker-compose.yaml

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2023-12-11 16:08:16 +00:00
parent 7ef56d8dae
commit f17a25f3e8
393 changed files with 1983 additions and 3418 deletions

View File

@ -35,8 +35,9 @@ import (
)
const (
watchdogPort = "8080"
defaultContentType = "text/plain"
watchdogPort = "8080"
defaultContentType = "text/plain"
openFaaSInternalHeader = "X-OpenFaaS-Internal"
)
// BaseURLResolver URL resolver for proxy requests
@ -139,7 +140,7 @@ func proxyRequest(w http.ResponseWriter, originalReq *http.Request, proxyClient
pathVars := mux.Vars(originalReq)
functionName := pathVars["name"]
if functionName == "" {
w.Header().Add("X-OpenFaaS-Internal", "proxy")
w.Header().Add(openFaaSInternalHeader, "proxy")
httputil.Errorf(w, http.StatusBadRequest, "Provide function name in the request path")
return
@ -147,7 +148,7 @@ func proxyRequest(w http.ResponseWriter, originalReq *http.Request, proxyClient
functionAddr, err := resolver.Resolve(functionName)
if err != nil {
w.Header().Add("X-OpenFaaS-Internal", "proxy")
w.Header().Add(openFaaSInternalHeader, "proxy")
// TODO: Should record the 404/not found error in Prometheus.
log.Printf("resolver error: no endpoints for %s: %s\n", functionName, err.Error())
@ -158,7 +159,7 @@ func proxyRequest(w http.ResponseWriter, originalReq *http.Request, proxyClient
proxyReq, err := buildProxyRequest(originalReq, functionAddr, pathVars["params"])
if err != nil {
w.Header().Add("X-OpenFaaS-Internal", "proxy")
w.Header().Add(openFaaSInternalHeader, "proxy")
httputil.Errorf(w, http.StatusInternalServerError, "Failed to resolve service: %s.", functionName)
return
@ -175,7 +176,7 @@ func proxyRequest(w http.ResponseWriter, originalReq *http.Request, proxyClient
if err != nil {
log.Printf("error with proxy request to: %s, %s\n", proxyReq.URL.String(), err.Error())
w.Header().Add("X-OpenFaaS-Internal", "proxy")
w.Header().Add(openFaaSInternalHeader, "proxy")
httputil.Errorf(w, http.StatusInternalServerError, "Can't reach service for: %s.", functionName)
return

View File

@ -4,6 +4,8 @@
package bootstrap
import (
"context"
"errors"
"fmt"
"log"
"net/http"
@ -31,7 +33,7 @@ func Router() *mux.Router {
}
// Serve load your handlers into the correct OpenFaaS route spec. This function is blocking.
func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
func Serve(ctx context.Context, handlers *types.FaaSHandlers, config *types.FaaSConfig) {
if config.EnableBasicAuth {
reader := auth.ReadBasicAuthFromDisk{
@ -118,5 +120,16 @@ func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
Handler: r,
}
log.Fatal(s.ListenAndServe())
// Start server in a goroutine
go func() {
if err := s.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}()
// Shutdown server when context is done.
<-ctx.Done()
if err := s.Shutdown(context.Background()); err != nil {
log.Printf("Failed to shut down provider gracefully: %s", err)
}
}