mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-21 07:17:30 +01:00
Iterate over subCluster MetricConfig directly so that removed metrics are not included
Entire-Checkpoint: efb6f0a96069
This commit is contained in:
@@ -198,36 +198,19 @@ func GetSubCluster(cluster, subcluster string) (*schema.SubCluster, error) {
|
|||||||
func GetMetricConfigSubCluster(cluster, subcluster string) map[string]*schema.Metric {
|
func GetMetricConfigSubCluster(cluster, subcluster string) map[string]*schema.Metric {
|
||||||
metrics := make(map[string]*schema.Metric)
|
metrics := make(map[string]*schema.Metric)
|
||||||
|
|
||||||
for _, c := range Clusters {
|
sc, err := GetSubCluster(cluster, subcluster)
|
||||||
if c.Name == cluster {
|
if err != nil {
|
||||||
for _, m := range c.MetricConfig {
|
return metrics
|
||||||
for _, s := range m.SubClusters {
|
}
|
||||||
if s.Name == subcluster {
|
|
||||||
metrics[m.Name] = &schema.Metric{
|
|
||||||
Name: m.Name,
|
|
||||||
Unit: s.Unit,
|
|
||||||
Peak: s.Peak,
|
|
||||||
Normal: s.Normal,
|
|
||||||
Caution: s.Caution,
|
|
||||||
Alert: s.Alert,
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, ok := metrics[m.Name]
|
for _, m := range sc.MetricConfig {
|
||||||
if !ok {
|
metrics[m.Name] = &schema.Metric{
|
||||||
metrics[m.Name] = &schema.Metric{
|
Name: m.Name,
|
||||||
Name: m.Name,
|
Unit: m.Unit,
|
||||||
Unit: m.Unit,
|
Peak: m.Peak,
|
||||||
Peak: m.Peak,
|
Normal: m.Normal,
|
||||||
Normal: m.Normal,
|
Caution: m.Caution,
|
||||||
Caution: m.Caution,
|
Alert: m.Alert,
|
||||||
Alert: m.Alert,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,3 +37,27 @@ func TestClusterConfig(t *testing.T) {
|
|||||||
// spew.Dump(archive.GlobalMetricList)
|
// spew.Dump(archive.GlobalMetricList)
|
||||||
// t.Fail()
|
// t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetMetricConfigSubClusterRespectsRemovedMetrics(t *testing.T) {
|
||||||
|
if err := archive.Init(json.RawMessage(`{"kind": "file","path": "testdata/archive"}`)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sc, err := archive.GetSubCluster("fritz", "spr2tb")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics := archive.GetMetricConfigSubCluster("fritz", "spr2tb")
|
||||||
|
if len(metrics) != len(sc.MetricConfig) {
|
||||||
|
t.Fatalf("GetMetricConfigSubCluster() returned %d metrics, want %d", len(metrics), len(sc.MetricConfig))
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := metrics["flops_any"]; ok {
|
||||||
|
t.Fatalf("GetMetricConfigSubCluster() returned removed metric flops_any for subcluster spr2tb")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := metrics["cpu_power"]; !ok {
|
||||||
|
t.Fatalf("GetMetricConfigSubCluster() missing active metric cpu_power for subcluster spr2tb")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user