From b47d175ab2b017c7dff7ab2a011f06ed263fe480 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Thu, 31 Mar 2022 09:44:26 +0200 Subject: [PATCH] Rename histWalltime to histDuration; Fix for running jobs --- frontend | 2 +- graph/generated/generated.go | 26 +++++++++++++------------- graph/model/models_gen.go | 2 +- graph/schema.graphqls | 2 +- graph/stats.go | 6 ++++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend b/frontend index 5d90ff9..3f3d1fa 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit 5d90ff9a4a03242f3a4686c7803dc4b0cee66488 +Subproject commit 3f3d1fac6b2ea88964ba357ad35688e204d82037 diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 91db1f1..7ce97ab 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -133,8 +133,8 @@ type ComplexityRoot struct { } JobsStatistics struct { + HistDuration func(childComplexity int) int HistNumNodes func(childComplexity int) int - HistWalltime func(childComplexity int) int ID func(childComplexity int) int ShortJobs func(childComplexity int) int TotalCoreHours func(childComplexity int) int @@ -665,6 +665,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.JobResultList.Offset(childComplexity), true + case "JobsStatistics.histDuration": + if e.complexity.JobsStatistics.HistDuration == nil { + break + } + + return e.complexity.JobsStatistics.HistDuration(childComplexity), true + case "JobsStatistics.histNumNodes": if e.complexity.JobsStatistics.HistNumNodes == nil { break @@ -672,13 +679,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.JobsStatistics.HistNumNodes(childComplexity), true - case "JobsStatistics.histWalltime": - if e.complexity.JobsStatistics.HistWalltime == nil { - break - } - - return e.complexity.JobsStatistics.HistWalltime(childComplexity), true - case "JobsStatistics.id": if e.complexity.JobsStatistics.ID == nil { break @@ -1601,7 +1601,7 @@ type JobsStatistics { shortJobs: Int! # Number of jobs with a duration of less than 2 minutes totalWalltime: Int! # Sum of the duration of all matched jobs in hours totalCoreHours: Int! # Sum of the core hours of all matched jobs - histWalltime: [HistoPoint!]! # value: hour, count: number of jobs with a rounded duration of value + histDuration: [HistoPoint!]! # value: hour, count: number of jobs with a rounded duration of value histNumNodes: [HistoPoint!]! # value: number of nodes, count: number of jobs with that number of nodes } @@ -4085,7 +4085,7 @@ func (ec *executionContext) _JobsStatistics_totalCoreHours(ctx context.Context, return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _JobsStatistics_histWalltime(ctx context.Context, field graphql.CollectedField, obj *model.JobsStatistics) (ret graphql.Marshaler) { +func (ec *executionContext) _JobsStatistics_histDuration(ctx context.Context, field graphql.CollectedField, obj *model.JobsStatistics) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -4103,7 +4103,7 @@ func (ec *executionContext) _JobsStatistics_histWalltime(ctx context.Context, fi ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.HistWalltime, nil + return obj.HistDuration, nil }) if err != nil { ec.Error(ctx, err) @@ -8725,8 +8725,8 @@ func (ec *executionContext) _JobsStatistics(ctx context.Context, sel ast.Selecti if out.Values[i] == graphql.Null { invalids++ } - case "histWalltime": - out.Values[i] = ec._JobsStatistics_histWalltime(ctx, field, obj) + case "histDuration": + out.Values[i] = ec._JobsStatistics_histDuration(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 46baa30..34e84a4 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -92,7 +92,7 @@ type JobsStatistics struct { ShortJobs int `json:"shortJobs"` TotalWalltime int `json:"totalWalltime"` TotalCoreHours int `json:"totalCoreHours"` - HistWalltime []*HistoPoint `json:"histWalltime"` + HistDuration []*HistoPoint `json:"histDuration"` HistNumNodes []*HistoPoint `json:"histNumNodes"` } diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 793fe69..0cb0a92 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -256,7 +256,7 @@ type JobsStatistics { shortJobs: Int! # Number of jobs with a duration of less than 2 minutes totalWalltime: Int! # Sum of the duration of all matched jobs in hours totalCoreHours: Int! # Sum of the core hours of all matched jobs - histWalltime: [HistoPoint!]! # value: hour, count: number of jobs with a rounded duration of value + histDuration: [HistoPoint!]! # value: hour, count: number of jobs with a rounded duration of value histNumNodes: [HistoPoint!]! # value: number of nodes, count: number of jobs with that number of nodes } diff --git a/graph/stats.go b/graph/stats.go index ed32edf..52c8443 100644 --- a/graph/stats.go +++ b/graph/stats.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "math" + "time" "github.com/99designs/gqlgen/graphql" "github.com/ClusterCockpit/cc-backend/config" @@ -130,7 +131,7 @@ func (r *queryResolver) jobsStatistics(ctx context.Context, filter []*model.JobF histogramsNeeded := false fields := graphql.CollectFieldsCtx(ctx, nil) for _, col := range fields { - if col.Name == "histWalltime" || col.Name == "histNumNodes" { + if col.Name == "histDuration" || col.Name == "histNumNodes" { histogramsNeeded = true } } @@ -146,7 +147,8 @@ func (r *queryResolver) jobsStatistics(ctx context.Context, filter []*model.JobF if histogramsNeeded { var err error - stat.HistWalltime, err = r.jobsStatisticsHistogram(ctx, "CAST(ROUND(job.duration / 3600) as int) as value", filter, id, col) + value := fmt.Sprintf(`CAST(ROUND((CASE WHEN job.job_state = "running" THEN %d - job.start_time ELSE job.duration END) / 3600) as int) as value`, time.Now().Unix()) + stat.HistDuration, err = r.jobsStatisticsHistogram(ctx, value, filter, id, col) if err != nil { return nil, err }