added manger to keep track of go routines in the services (#2869)

- added manager to wait for all go routines to end before exit
- code refactor
- renamed Manafer to Interface and GoRoutineManager to GroupManager
- replaced some go routine calls with manager Add func
- added unit tests for manager
This commit is contained in:
Vardhaman Surana
2023-11-07 15:30:48 +05:30
committed by GitHub
parent 27132975c4
commit 2a40b4538c
24 changed files with 283 additions and 67 deletions
+3 -2
View File
@@ -31,6 +31,7 @@ import (
"github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/fetcher"
"github.com/fission/fission/pkg/utils/httpserver"
"github.com/fission/fission/pkg/utils/manager"
otelUtils "github.com/fission/fission/pkg/utils/otel"
)
@@ -38,7 +39,7 @@ var (
readyToServe uint32
)
func Run(ctx context.Context, clientGen crd.ClientGeneratorInterface, logger *zap.Logger) {
func Run(ctx context.Context, clientGen crd.ClientGeneratorInterface, logger *zap.Logger, mgr manager.Interface) {
flag.Usage = fetcherUsage
specializeOnStart := flag.Bool("specialize-on-startup", false, "Flag to activate specialize process at pod startup")
specializePayload := flag.String("specialize-request", "", "JSON payload for specialize request")
@@ -120,7 +121,7 @@ func Run(ctx context.Context, clientGen crd.ClientGeneratorInterface, logger *za
logger.Info("fetcher ready to receive requests")
handler := otelUtils.GetHandlerWithOTEL(mux, "fission-fetcher", otelUtils.UrlsToIgnore("/healthz", "/readiness-healthz"))
httpserver.StartServer(ctx, logger, "fetcher", "8000", handler)
httpserver.StartServer(ctx, logger, mgr, "fetcher", "8000", handler)
}
func fetcherUsage() {
+8 -2
View File
@@ -22,15 +22,21 @@ import (
"github.com/fission/fission/cmd/fetcher/app"
"github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/utils/loggerfactory"
"github.com/fission/fission/pkg/utils/manager"
"github.com/fission/fission/pkg/utils/profile"
)
// Usage: fetcher <shared volume path>
func main() {
mgr := manager.New()
defer mgr.Wait()
logger := loggerfactory.GetLogger()
defer logger.Sync()
ctx := signals.SetupSignalHandler()
profile.ProfileIfEnabled(ctx, logger)
app.Run(ctx, crd.NewClientGenerator(), logger)
profile.ProfileIfEnabled(ctx, logger, mgr)
app.Run(ctx, crd.NewClientGenerator(), logger, mgr)
}