add logged timing to homeroute calls

This commit is contained in:
Christoph Kluge 2024-10-31 14:34:32 +01:00
parent eabc6212ea
commit 2c8b73e2e2
2 changed files with 10 additions and 9 deletions

View File

@ -324,7 +324,7 @@ func GetUserFromContext(ctx context.Context) *schema.User {
log.Warnf("no user retrieved from context") log.Warnf("no user retrieved from context")
return nil return nil
} }
log.Infof("user retrieved from context: %v", x.(*schema.User)) // log.Infof("user retrieved from context: %v", x.(*schema.User))
return x.(*schema.User) return x.(*schema.User)
} }

View File

@ -51,15 +51,21 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType {
jobRepo := repository.GetJobRepository() jobRepo := repository.GetJobRepository()
groupBy := model.AggregateCluster groupBy := model.AggregateCluster
log.Infof(">>> HELLO HOME ROUTE")
startJobCount := time.Now()
stats, err := jobRepo.JobCountGrouped(r.Context(), nil, &groupBy) stats, err := jobRepo.JobCountGrouped(r.Context(), nil, &groupBy)
if err != nil { if err != nil {
log.Warnf("failed to count jobs: %s", err.Error()) log.Warnf("failed to count jobs: %s", err.Error())
} }
log.Infof("Timer HOME ROUTE startJobCount: %s", time.Since(startJobCount))
startRunningJobCount := time.Now()
stats, err = jobRepo.AddJobCountGrouped(r.Context(), nil, &groupBy, stats, "running") stats, err = jobRepo.AddJobCountGrouped(r.Context(), nil, &groupBy, stats, "running")
if err != nil { if err != nil {
log.Warnf("failed to count running jobs: %s", err.Error()) log.Warnf("failed to count running jobs: %s", err.Error())
} }
log.Infof("Timer HOME ROUTE startRunningJobCount: %s", time.Since(startRunningJobCount))
i["clusters"] = stats i["clusters"] = stats
@ -72,6 +78,8 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType {
} }
} }
log.Infof("... BYE HOME ROUTE")
return i return i
} }
@ -254,7 +262,6 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
for _, route := range routes { for _, route := range routes {
route := route route := route
router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) { router.HandleFunc(route.Route, func(rw http.ResponseWriter, r *http.Request) {
log.Info(">>> HELLO ROUTE HANDLER ...") log.Info(">>> HELLO ROUTE HANDLER ...")
conf, err := userCfgRepo.GetUIConfig(repository.GetUserFromContext(r.Context())) conf, err := userCfgRepo.GetUIConfig(repository.GetUserFromContext(r.Context()))
@ -264,21 +271,16 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
} }
title := route.Title title := route.Title
log.Infof(">>> >>> ROUTE TITLE : %s ", title)
infos := route.Setup(map[string]interface{}{}, r) infos := route.Setup(map[string]interface{}{}, r)
if id, ok := infos["id"]; ok { if id, ok := infos["id"]; ok {
title = strings.Replace(route.Title, "<ID>", id.(string), 1) title = strings.Replace(route.Title, "<ID>", id.(string), 1)
} }
log.Infof(">>> >>> ROUTE INFOS : %v ", infos)
// Get User -> What if NIL? // Get User -> What if NIL?
user := repository.GetUserFromContext(r.Context()) user := repository.GetUserFromContext(r.Context())
log.Infof(">>> >>> ROUTE USER : %v ", *user)
// Get Roles // Get Roles
availableRoles, _ := schema.GetValidRolesMap(user) availableRoles, _ := schema.GetValidRolesMap(user)
log.Infof(">>> >>> ROUTE AVAILABLE ROLES : %v ", availableRoles)
page := web.Page{ page := web.Page{
Title: title, Title: title,
@ -288,12 +290,11 @@ func SetupRoutes(router *mux.Router, buildInfo web.Build) {
Config: conf, Config: conf,
Infos: infos, Infos: infos,
} }
log.Infof(">>> >>> ROUTE PAGE : %v ", page)
if route.Filter { if route.Filter {
page.FilterPresets = buildFilterPresets(r.URL.Query()) page.FilterPresets = buildFilterPresets(r.URL.Query())
} }
log.Infof(">>> >>> ROUTE FILTER : %v ", page.FilterPresets) log.Infof("... ROUTE HANDLED: %s for %v", page.Title, page.User)
web.RenderTemplate(rw, route.Template, &page) web.RenderTemplate(rw, route.Template, &page)
}) })