review clusterMetrics aggregation handling, fixes index error

This commit is contained in:
Christoph Kluge
2026-01-27 19:04:29 +01:00
parent 719aaaff4b
commit 9d9babe94d

View File

@@ -905,26 +905,32 @@ func (r *queryResolver) ClusterMetrics(ctx context.Context, cluster string, metr
for _, metrics := range data { for _, metrics := range data {
clusterMetrics.NodeCount += 1 clusterMetrics.NodeCount += 1
for metric, scopedMetrics := range metrics { for metric, scopedMetrics := range metrics {
_, ok := collectorData[metric] for _, scopedMetric := range scopedMetrics {
if !ok { // Collect Info Once
collectorData[metric] = make([]schema.Float, 0) _, okTimestep := collectorTimestep[metric]
for _, scopedMetric := range scopedMetrics { if !okTimestep {
// Collect Info
collectorTimestep[metric] = scopedMetric.Timestep collectorTimestep[metric] = scopedMetric.Timestep
collectorUnit[metric] = scopedMetric.Unit
// Collect Initial Data
for _, ser := range scopedMetric.Series {
collectorData[metric] = append(collectorData[metric], ser.Data...)
}
} }
} else { _, okUnit := collectorUnit[metric]
// Sum up values by index if !okUnit {
for _, scopedMetric := range scopedMetrics { collectorUnit[metric] = scopedMetric.Unit
// For This Purpose (Cluster_Wide-Sum of Node Metrics) OK }
for _, ser := range scopedMetric.Series { // Collect Data
for _, ser := range scopedMetric.Series {
_, okData := collectorData[metric]
// Init With Datasize > 0
if !okData && len(ser.Data) != 0 {
collectorData[metric] = make([]schema.Float, len(ser.Data))
} else if !okData {
cclog.Debugf("ClusterMetrics Skip Init: No Data -> %s at %s; Size %d", metric, ser.Hostname, len(ser.Data))
}
// Sum if init'd and matching size
if okData && len(ser.Data) == len(collectorData[metric]) {
for i, val := range ser.Data { for i, val := range ser.Data {
collectorData[metric][i] += val collectorData[metric][i] += val
} }
} else if okData {
cclog.Debugf("ClusterMetrics Skip Sum: Data Diff -> %s at %s; Want Size %d, Have Size %d", metric, ser.Hostname, len(collectorData[metric]), len(ser.Data))
} }
} }
} }