From 8ebf00d980c105ae312cbb4d41ef3710de005634 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Mon, 21 Mar 2022 13:28:21 +0100 Subject: [PATCH] Add aggregation to GraphQL API; Update frontend --- frontend | 2 +- graph/generated/generated.go | 75 ++++++++++++++++++++++++++++-------- graph/model/models_gen.go | 17 ++++---- graph/schema.graphqls | 17 ++++---- 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/frontend b/frontend index 184a507..03818be 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit 184a5079bd53a89442664c28c5cebb733557f1f1 +Subproject commit 03818be47032194f1f450ab242eed56a94a3c5d1 diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 03a6a75..cc179cc 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -143,14 +143,15 @@ type ComplexityRoot struct { } MetricConfig struct { - Alert func(childComplexity int) int - Caution func(childComplexity int) int - Name func(childComplexity int) int - Normal func(childComplexity int) int - Peak func(childComplexity int) int - Scope func(childComplexity int) int - Timestep func(childComplexity int) int - Unit func(childComplexity int) int + Aggregation func(childComplexity int) int + Alert func(childComplexity int) int + Caution func(childComplexity int) int + Name func(childComplexity int) int + Normal func(childComplexity int) int + Peak func(childComplexity int) int + Scope func(childComplexity int) int + Timestep func(childComplexity int) int + Unit func(childComplexity int) int } MetricFootprints struct { @@ -709,6 +710,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.JobsStatistics.TotalWalltime(childComplexity), true + case "MetricConfig.aggregation": + if e.complexity.MetricConfig.Aggregation == nil { + break + } + + return e.complexity.MetricConfig.Aggregation(childComplexity), true + case "MetricConfig.alert": if e.complexity.MetricConfig.Alert == nil { break @@ -1375,14 +1383,15 @@ type Accelerator { } type MetricConfig { - name: String! - unit: String! - scope: MetricScope! - timestep: Int! - peak: Float! - normal: Float! - caution: Float! - alert: Float! + name: String! + unit: String! + scope: MetricScope! + aggregation: String + timestep: Int! + peak: Float! + normal: Float! + caution: Float! + alert: Float! } type Tag { @@ -4202,6 +4211,38 @@ func (ec *executionContext) _MetricConfig_scope(ctx context.Context, field graph return ec.marshalNMetricScope2githubᚗcomᚋClusterCockpitᚋccᚑbackendᚋschemaᚐMetricScope(ctx, field.Selections, res) } +func (ec *executionContext) _MetricConfig_aggregation(ctx context.Context, field graphql.CollectedField, obj *model.MetricConfig) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MetricConfig", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + 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.Aggregation, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + func (ec *executionContext) _MetricConfig_timestep(ctx context.Context, field graphql.CollectedField, obj *model.MetricConfig) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -8570,6 +8611,8 @@ func (ec *executionContext) _MetricConfig(ctx context.Context, sel ast.Selection if out.Values[i] == graphql.Null { invalids++ } + case "aggregation": + out.Values[i] = ec._MetricConfig_aggregation(ctx, field, obj) case "timestep": out.Values[i] = ec._MetricConfig_timestep(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 7022d80..acd50bb 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -97,14 +97,15 @@ type JobsStatistics struct { } type MetricConfig struct { - Name string `json:"name"` - Unit string `json:"unit"` - Scope schema.MetricScope `json:"scope"` - Timestep int `json:"timestep"` - Peak float64 `json:"peak"` - Normal float64 `json:"normal"` - Caution float64 `json:"caution"` - Alert float64 `json:"alert"` + Name string `json:"name"` + Unit string `json:"unit"` + Scope schema.MetricScope `json:"scope"` + Aggregation *string `json:"aggregation"` + Timestep int `json:"timestep"` + Peak float64 `json:"peak"` + Normal float64 `json:"normal"` + Caution float64 `json:"caution"` + Alert float64 `json:"alert"` } type MetricFootprints struct { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index b3fbe29..f3209e3 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -68,14 +68,15 @@ type Accelerator { } type MetricConfig { - name: String! - unit: String! - scope: MetricScope! - timestep: Int! - peak: Float! - normal: Float! - caution: Float! - alert: Float! + name: String! + unit: String! + scope: MetricScope! + aggregation: String + timestep: Int! + peak: Float! + normal: Float! + caution: Float! + alert: Float! } type Tag {