@@ -19,10 +19,14 @@ package fission
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
)
|
||||
|
||||
func UrlForFunction(name string) string {
|
||||
@@ -52,3 +56,13 @@ func IsNetworkError(err error) bool {
|
||||
func GetFunctionIstioServiceName(fnName, fnNamespace string) string {
|
||||
return fmt.Sprintf("istio-%v-%v", fnName, fnNamespace)
|
||||
}
|
||||
|
||||
func LoggingMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requestURI := r.RequestURI
|
||||
if !strings.Contains(requestURI, "healthz") {
|
||||
// Call the next handler, which can be another middleware in the chain, or the final handler.
|
||||
handlers.LoggingHandler(os.Stdout, next).ServeHTTP(w, r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -209,5 +208,6 @@ func (api *API) Serve(port int) {
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
|
||||
log.WithFields(log.Fields{"port": port}).Info("Server started")
|
||||
log.Fatal(http.ListenAndServe(address, handlers.LoggingHandler(os.Stdout, r)))
|
||||
r.Use(fission.LoggingMiddleware)
|
||||
log.Fatal(http.ListenAndServe(address, r))
|
||||
}
|
||||
|
||||
+2
-3
@@ -23,10 +23,8 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -113,5 +111,6 @@ func (executor *Executor) Serve(port int) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
executor.ndm.Run(ctx)
|
||||
log.Fatal(http.ListenAndServe(address, handlers.LoggingHandler(os.Stdout, r)))
|
||||
r.Use(fission.LoggingMiddleware)
|
||||
log.Fatal(http.ListenAndServe(address, r))
|
||||
}
|
||||
|
||||
+2
-3
@@ -44,10 +44,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/fission/fission"
|
||||
@@ -62,6 +60,7 @@ import (
|
||||
func router(ctx context.Context, httpTriggerSet *HTTPTriggerSet, resolver *functionReferenceResolver) *mutableRouter {
|
||||
muxRouter := mux.NewRouter()
|
||||
mr := NewMutableRouter(muxRouter)
|
||||
muxRouter.Use(fission.LoggingMiddleware)
|
||||
httpTriggerSet.subscribeRouter(ctx, mr, resolver)
|
||||
return mr
|
||||
}
|
||||
@@ -69,7 +68,7 @@ func router(ctx context.Context, httpTriggerSet *HTTPTriggerSet, resolver *funct
|
||||
func serve(ctx context.Context, port int, httpTriggerSet *HTTPTriggerSet, resolver *functionReferenceResolver) {
|
||||
mr := router(ctx, httpTriggerSet, resolver)
|
||||
url := fmt.Sprintf(":%v", port)
|
||||
http.ListenAndServe(url, handlers.LoggingHandler(os.Stdout, mr))
|
||||
http.ListenAndServe(url, mr)
|
||||
}
|
||||
|
||||
func Start(port int, executorUrl string) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
_ "github.com/graymeta/stow/local"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -169,7 +168,9 @@ func (ss *StorageService) Start(port int) {
|
||||
r.HandleFunc("/healthz", ss.healthHandler).Methods("GET")
|
||||
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
log.Fatal(http.ListenAndServe(address, handlers.LoggingHandler(os.Stdout, r)))
|
||||
|
||||
r.Use(fission.LoggingMiddleware)
|
||||
log.Fatal(http.ListenAndServe(address, r))
|
||||
}
|
||||
|
||||
func RunStorageService(storageType StorageType, storagePath string, containerName string, port int, enablePruner bool) *StorageService {
|
||||
|
||||
@@ -42,7 +42,7 @@ done
|
||||
|
||||
log "Grabbing logs, should have 4 calls in logs"
|
||||
|
||||
sleep 15
|
||||
sleep 60
|
||||
|
||||
fission function logs --name $fn --detail > /tmp/logfile
|
||||
|
||||
@@ -61,6 +61,7 @@ log $num logs found
|
||||
if [ $num -ne 4 ]
|
||||
then
|
||||
log "Test Failed: expected 4, found $num logs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "All done."
|
||||
|
||||
Reference in New Issue
Block a user