From 8e8b205da8d22ada10062b76a414de15a9c87f1e Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Tue, 8 Mar 2022 10:26:51 +0100 Subject: [PATCH] Show number of short jobs per cluster on start page Fixes ClusterCockpit/cc-frontend#21 --- graph/stats.go | 2 +- server.go | 24 ++++++++++++++++++------ templates/home.tmpl | 3 +++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/graph/stats.go b/graph/stats.go index e71d929..da21995 100644 --- a/graph/stats.go +++ b/graph/stats.go @@ -23,7 +23,7 @@ var groupBy2column = map[model.Aggregate]string{ model.AggregateCluster: "job.cluster", } -const ShortJobDuration int = 180 +const ShortJobDuration int = 5 * 60 // Helper function for the jobsStatistics GraphQL query placed here so that schema.resolvers.go is not too full. func (r *queryResolver) jobsStatistics(ctx context.Context, filter []*model.JobFilter, groupBy *model.Aggregate) ([]*model.JobsStatistics, error) { diff --git a/server.go b/server.go index c2c5a2e..56ed59d 100644 --- a/server.go +++ b/server.go @@ -126,9 +126,10 @@ var programConfig ProgramConfig = ProgramConfig{ func setupHomeRoute(i InfoType, r *http.Request) InfoType { type cluster struct { - Name string - RunningJobs int - TotalJobs int + Name string + RunningJobs int + TotalJobs int + RecentShortJobs int } runningJobs, err := jobRepo.CountGroupedJobs(r.Context(), model.AggregateCluster, []*model.JobFilter{{ @@ -144,12 +145,23 @@ func setupHomeRoute(i InfoType, r *http.Request) InfoType { totalJobs = map[string]int{} } + from := time.Now().Add(-24 * time.Hour) + recentShortJobs, err := jobRepo.CountGroupedJobs(r.Context(), model.AggregateCluster, []*model.JobFilter{{ + StartTime: &model.TimeRange{From: &from, To: nil}, + Duration: &model.IntRange{From: 0, To: graph.ShortJobDuration}, + }}, nil) + if err != nil { + log.Errorf("failed to count jobs: %s", err.Error()) + recentShortJobs = map[string]int{} + } + clusters := make([]cluster, 0) for _, c := range config.Clusters { clusters = append(clusters, cluster{ - Name: c.Name, - RunningJobs: runningJobs[c.Name], - TotalJobs: totalJobs[c.Name], + Name: c.Name, + RunningJobs: runningJobs[c.Name], + TotalJobs: totalJobs[c.Name], + RecentShortJobs: recentShortJobs[c.Name], }) } diff --git a/templates/home.tmpl b/templates/home.tmpl index c44b8de..17cb668 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -8,6 +8,7 @@ Name Running Jobs Total Jobs + Short Jobs in past 24h Jobs {{if .User.IsAdmin}} System View @@ -22,6 +23,7 @@ {{.Name}} {{.RunningJobs}} {{.TotalJobs}} + {{.RecentShortJobs}} Jobs System View Analysis View @@ -33,6 +35,7 @@ {{.Name}} {{.RunningJobs}} {{.TotalJobs}} + {{.RecentShortJobs}} Jobs {{end}}