diff --git a/cmd/collectors/zapi/plugins/qtree/qtree.go b/cmd/collectors/zapi/plugins/qtree/qtree.go index 5d64a45b3..89f2ed1a7 100644 --- a/cmd/collectors/zapi/plugins/qtree/qtree.go +++ b/cmd/collectors/zapi/plugins/qtree/qtree.go @@ -269,11 +269,10 @@ func (q *Qtree) handlingQuotaMetrics(quotas []*node.Node, data *matrix.Matrix, q continue } case quotaType == "tree": - if tree == "" { + if !q.historicalLabels && tree == "" { continue } } - *quotaCount++ // In 22.05, populate metrics with qtree labels if q.historicalLabels { @@ -294,6 +293,7 @@ func (q *Qtree) handlingQuotaMetrics(quotas []*node.Node, data *matrix.Matrix, q continue } } + *quotaCount++ for attribute, m := range q.data.GetMetrics() { objectElem := quota.GetChildS(attribute) diff --git a/cmd/collectors/zapi/plugins/qtree/qtree_test.go b/cmd/collectors/zapi/plugins/qtree/qtree_test.go index 704211ba4..75525253e 100644 --- a/cmd/collectors/zapi/plugins/qtree/qtree_test.go +++ b/cmd/collectors/zapi/plugins/qtree/qtree_test.go @@ -42,20 +42,6 @@ func TestHandlingQuotaMetrics(t *testing.T) { quotas = x.GetChildren() } - // Case 1: with historicalLabels = false - q1 := NewQtree() - q1.historicalLabels = false - testLabels(t, q1, quotas, nil, "astra_300.trident_qtree_pool_trident_TIXRBILLKA.trident_pvc_2a6d71d9_1c78_4e9a_84a2_59d316adfae9..disk-limit.tree", 3, 6, 5) - - // Case 2: with historicalLabels = true - q2 := NewQtree() - data := matrix.New(q2.Parent+".Qtree", "qtree", "qtree") - qtreeInstance, _ := data.NewInstance("" + "." + "abcd_root" + "." + "abcde") - qtreeInstance.SetLabel("export_policy", "default") - qtreeInstance.SetLabel("oplocks", "enabled") - qtreeInstance.SetLabel("security_style", "unix") - qtreeInstance.SetLabel("status", "normal") - exportOptions := node.NewS("export_options") instanceKeys := exportOptions.NewChildS("instance_keys", "") // apply all instance keys, instance labels from qtree.yaml to all quota metrics @@ -63,28 +49,59 @@ func TestHandlingQuotaMetrics(t *testing.T) { for _, key := range keys { instanceKeys.NewChildS("", key) } - q2.data.SetExportOptions(exportOptions) - q2.historicalLabels = true - testLabels(t, q2, quotas, data, "abcde.abcd_root..root.disk-used.user", 3, 4, 10) + + // Case 1: with historicalLabels = false, total 4 quotas, 2 user/group quota, 1 empty qtree tree quota and 1 non-empty tree quota, + // 1 empty tree quota will be skipped and 5 labels[qtree, svm, type, unit, volume] would be exported for tree quota. + q1 := NewQtree() + testLabels(t, q1, false, quotas, nil, "astra_300.trident_qtree_pool_trident_TIXRBILLKA.trident_pvc_2a6d71d9_1c78_4e9a_84a2_59d316adfae9..disk-limit.tree", 3, 6, 5) + + // Case 2: with historicalLabels = true, total 4 quotas, 2 user/group quota, 1 empty qtree tree quota and 1 non-empty tree quota, + // 1 empty tree quota will be skipped and 6 labels[qtree, svm, type, unit, user, volume] would be exported for user/group quota. + q2 := NewQtree() + testLabels(t, q2, false, quotas, nil, "abcde.abcd_root..root.disk-used.user", 3, 6, 6) + + // Case 3: with historicalLabels = true, total 4 quotas, 2 user/group quota, 1 empty qtree tree quota and 1 non-empty tree quota, + // all quotas with 9 labels [export_policy, oplocks, qtree, security_style, status, svm, type, unit, volume] would be exported. + q3 := NewQtree() + data := matrix.New(q3.Parent+".Qtree", "qtree", "qtree") + q3.data.SetExportOptions(exportOptions) + qtreeInstance1, _ := data.NewInstance("" + "." + "volume1" + "." + "svm1") + addLabels(qtreeInstance1) + qtreeInstance2, _ := data.NewInstance("trident_pvc_2a6d71d9_1c78_4e9a_84a2_59d316adfae9" + "." + "trident_qtree_pool_trident_TIXRBILLKA" + "." + "astra_300") + addLabels(qtreeInstance2) + qtreeInstance3, _ := data.NewInstance("" + "." + "abcd_root" + "." + "abcde") + addLabels(qtreeInstance3) + testLabels(t, q3, true, quotas, data, "svm1.volume1...disk-used.tree", 4, 8, 9) +} + +func addLabels(qtreeInstance *matrix.Instance) { + qtreeInstance.SetLabel("export_policy", "default") + qtreeInstance.SetLabel("oplocks", "enabled") + qtreeInstance.SetLabel("security_style", "unix") + qtreeInstance.SetLabel("status", "normal") } -func testLabels(t *testing.T, q *Qtree, quotas []*node.Node, data *matrix.Matrix, quotaInstanceKey string, expectedQuotaCount int, expectedQuotaMetricCount int, expectedQuotaLabels int) { +func testLabels(t *testing.T, q *Qtree, historicalLabels bool, quotas []*node.Node, data *matrix.Matrix, quotaInstanceKey string, expectedQuotaCount int, expectedQuotaMetricCount int, expectedQuotaLabels int) { quotaCount := 0 numMetrics := 0 - err := q.handlingQuotaMetrics(quotas, data, "aCount, &numMetrics) - if err != nil { + quotaLabels := 0 + + q.historicalLabels = historicalLabels + if err := q.handlingQuotaMetrics(quotas, data, "aCount, &numMetrics); err != nil { t.Errorf("handlingQuotaMetrics returned an error: %v", err) } + if quotaInstance := q.data.GetInstance(quotaInstanceKey); quotaInstance != nil { + quotaLabels = len(quotaInstance.GetLabels()) + } + if quotaCount != expectedQuotaCount { t.Errorf("quotaCount = %d; want %d", quotaCount, expectedQuotaCount) } if numMetrics != expectedQuotaMetricCount { t.Errorf("numMetrics = %d; want %d", numMetrics, expectedQuotaMetricCount) } - - quotaInstance := q.data.GetInstance(quotaInstanceKey) - if len(quotaInstance.GetLabels()) != expectedQuotaLabels { - t.Errorf("labels = %d; want %d", len(quotaInstance.GetLabels()), expectedQuotaLabels) + if quotaLabels != expectedQuotaLabels { + t.Errorf("labels = %d; want %d", quotaLabels, expectedQuotaLabels) } } diff --git a/cmd/collectors/zapi/plugins/qtree/testdata/quotas.xml b/cmd/collectors/zapi/plugins/qtree/testdata/quotas.xml index 110e08664..c7c9e7cb3 100644 --- a/cmd/collectors/zapi/plugins/qtree/testdata/quotas.xml +++ b/cmd/collectors/zapi/plugins/qtree/testdata/quotas.xml @@ -4,7 +4,6 @@ - 8388608 198532 @@ -62,7 +61,21 @@ abcd_root abcde + + 1024000 + 198532 + - + 6 + + tree + - + - + - + + volume1 + svm1 + - 3 + 4 \ No newline at end of file