From 6efa73d13b186558cc8495c6cee675e1f9a005a0 Mon Sep 17 00:00:00 2001 From: quobix Date: Sat, 13 Apr 2024 06:53:29 -0400 Subject: [PATCH] tuned up some logs, added back in compression disabled cache control middleware for now, will tune up later. --- plank/pkg/server/initialize.go | 10 +++--- plank/pkg/server/server.go | 66 +++++++++++++++++----------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/plank/pkg/server/initialize.go b/plank/pkg/server/initialize.go index d719234..99f5aed 100644 --- a/plank/pkg/server/initialize.go +++ b/plank/pkg/server/initialize.go @@ -67,11 +67,11 @@ func (ps *platformServer) initialize() { ps.router = mux.NewRouter().Schemes("http", "https").Subrouter() // register a reserved path /health for use with container orchestration layer like k8s - ps.endpointHandlerMap["/health"] = func(w http.ResponseWriter, r *http.Request) { - _, _ = w.Write([]byte("OK")) - } - ps.router.Path("/health").Name("/health").Handler( - middleware.CacheControlMiddleware([]string{"/health"}, middleware.NewCacheControlDirective().NoStore())(ps.endpointHandlerMap["/health"])) + //ps.endpointHandlerMap["/health"] = func(w http.ResponseWriter, r *http.Request) { + // _, _ = w.Write([]byte("OK")) + //} + //ps.router.Path("/health").Name("/health").Handler( + // middleware.CacheControlMiddleware([]string{"/health"}, middleware.NewCacheControlDirective().NoStore())(ps.endpointHandlerMap["/health"])) // register static paths for _, dir := range ps.serverConfig.StaticDir { diff --git a/plank/pkg/server/server.go b/plank/pkg/server/server.go index e9077b9..5973484 100644 --- a/plank/pkg/server/server.go +++ b/plank/pkg/server/server.go @@ -132,25 +132,6 @@ func (ps *platformServer) StartServer(syschan chan os.Signal) { // then all other routes registered after SPA route will be masked away. ps.configureSPA() - go func() { - ps.ServerAvailability.Http = true - if ps.serverConfig.TLSCertConfig != nil { - ps.serverConfig.Logger.Info("[ranch] yee-haw! starting up the ranch's HTTPS server at %s:%d with TLS", "host", ps.serverConfig.Host, "port", ps.serverConfig.Port) - if err := ps.HttpServer.ListenAndServeTLS(ps.serverConfig.TLSCertConfig.CertFile, ps.serverConfig.TLSCertConfig.KeyFile); err != nil { - if !errors.Is(err, http.ErrServerClosed) { - ps.serverConfig.Logger.Error(wrapError(errServerInit, err).Error()) - } - } - } else { - ps.serverConfig.Logger.Info("[ranch] yee-haw! starting up the ranch's HTTP server", "host", ps.serverConfig.Host, "port", ps.serverConfig.Port) - if err := ps.HttpServer.ListenAndServe(); err != nil { - if !errors.Is(err, http.ErrServerClosed) { - ps.serverConfig.Logger.Error(wrapError(errServerInit, err).Error()) - } - } - } - }() - // if Fabric broker configuration is found, start the broker if ps.serverConfig.FabricConfig != nil { go func() { @@ -171,6 +152,25 @@ func (ps *platformServer) StartServer(syschan chan os.Signal) { }() } + go func() { + ps.ServerAvailability.Http = true + if ps.serverConfig.TLSCertConfig != nil { + ps.serverConfig.Logger.Info("[ranch] yee-haw! starting up the ranch's HTTPS server at %s:%d with TLS", "host", ps.serverConfig.Host, "port", ps.serverConfig.Port) + if err := ps.HttpServer.ListenAndServeTLS(ps.serverConfig.TLSCertConfig.CertFile, ps.serverConfig.TLSCertConfig.KeyFile); err != nil { + if !errors.Is(err, http.ErrServerClosed) { + ps.serverConfig.Logger.Error(wrapError(errServerInit, err).Error()) + } + } + } else { + ps.serverConfig.Logger.Info("[ranch] yee-haw! starting up the ranch's HTTP server", "host", ps.serverConfig.Host, "port", ps.serverConfig.Port) + if err := ps.HttpServer.ListenAndServe(); err != nil { + if !errors.Is(err, http.ErrServerClosed) { + ps.serverConfig.Logger.Error(wrapError(errServerInit, err).Error()) + } + } + } + }() + // spawn another goroutine to respond to syscall to shut down servers and terminate the main thread go func() { <-ps.SyscallChan @@ -255,9 +255,9 @@ func (ps *platformServer) StopServer() { // SetStaticRoute adds a route where static resources will be served func (ps *platformServer) SetStaticRoute(prefix, fullpath string, middlewareFn ...mux.MiddlewareFunc) { - ps.router.Handle(prefix, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, prefix+"/", http.StatusMovedPermanently) - })) + //ps.router.Handle(prefix, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // http.Redirect(w, r, prefix+"/", http.StatusMovedPermanently) + //})) ndir := NoDirFileSystem{http.Dir(fullpath)} endpointHandlerMapKey := prefix + "*" @@ -301,7 +301,7 @@ func (ps *platformServer) SetHttpChannelBridge(bridgeConfig *service.RESTBridgeC endpointHandlerKey := bridgeConfig.Uri + "-" + bridgeConfig.Method if _, ok := ps.endpointHandlerMap[endpointHandlerKey]; ok { - ps.serverConfig.Logger.Warn("[ranch] Endpoint is already associated with a handler, "+ + ps.serverConfig.Logger.Warn("[ranch] endpoint is already associated with a handler, "+ "Try another endpoint or remove it before assigning a new handler", "uri", bridgeConfig.Uri, "method", bridgeConfig.Method) return } @@ -326,9 +326,9 @@ func (ps *platformServer) SetHttpChannelBridge(bridgeConfig *service.RESTBridgeC // NOTE: mux.Router does not have mutex or any locking mechanism so it could sometimes lead to concurrency write // panics. the following is to ensure the modification to ps.router can happen only once per thread, this atomic // counter also protects against concurrent writing to ps.endpointHandlerMap - for !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 0, 1) { - time.Sleep(1 * time.Nanosecond) - } + //for !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 0, 1) { + // time.Sleep(1 * time.Nanosecond) + //} // build endpoint handler ps.endpointHandlerMap[endpointHandlerKey] = ps.buildEndpointHandler( @@ -353,12 +353,12 @@ func (ps *platformServer) SetHttpChannelBridge(bridgeConfig *service.RESTBridgeC Methods(permittedMethods...). Name(fmt.Sprintf("%s-%s", bridgeConfig.Uri, bridgeConfig.Method)). Handler(ps.endpointHandlerMap[endpointHandlerKey]) - if !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 1, 0) { - panic("Concurrency write on router detected when running ") - } + //if !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 1, 0) { + // panic("Concurrency write on router detected when running ") + //} ps.serverConfig.Logger.Info( - "[ranch] Service channel is bridged to a REST endpoint", + "[ranch] service channel is bridged to a REST endpoint", "channel", bridgeConfig.ServiceChannel, "url", bridgeConfig.Uri, "method", bridgeConfig.Method) } @@ -371,7 +371,7 @@ func (ps *platformServer) SetHttpPathPrefixChannelBridge(bridgeConfig *service.R endpointHandlerKey := bridgeConfig.Uri + "-" + AllMethodsWildcard if _, ok := ps.endpointHandlerMap[endpointHandlerKey]; ok { - ps.serverConfig.Logger.Warn("[ranch] Path prefix is already being handled. "+ + ps.serverConfig.Logger.Warn("[ranch] path prefix is already being handled. "+ "Try another prefix or remove it before assigning a new handler", "uri", bridgeConfig.Uri, "method", bridgeConfig.Method) return } @@ -502,8 +502,8 @@ func (ps *platformServer) loadGlobalHttpHandler(h *mux.Router) { defer ps.lock.Unlock() ps.router = h ps.HttpServer.Handler = handlers.RecoveryHandler()( - //handlers.CompressHandler( - handlers.ProxyHeaders(ps.router)) + handlers.CompressHandler( + handlers.ProxyHeaders(ps.router))) //handlers.CombinedLoggingHandler( // ps.serverConfig.LogConfig.GetAccessLogFilePointer(), ps.router))) }