diff --git a/cmd/collectors/restperf/plugins/volume/volume_test.go b/cmd/collectors/restperf/plugins/volume/volume_test.go index b44d41800..b1ce14d59 100644 --- a/cmd/collectors/restperf/plugins/volume/volume_test.go +++ b/cmd/collectors/restperf/plugins/volume/volume_test.go @@ -92,13 +92,12 @@ func runVolumeTest(t *testing.T, createVolume func(params *node.Node) plugin.Plu assert.Nil(t, err) // Verify the output - assert.Equal(t, len(output), 2) + assert.Equal(t, len(output), 1) - cache := output[0] - volumeAggrmetric := output[1] + volumeAggrmetric := output[0] - // Check for flexgroup instance - flexgroupInstance := cache.GetInstance("svm1.RahulTest") + // Check for flexgroup instance in the modified data matrix + flexgroupInstance := data.GetInstance("svm1.RahulTest") assert.NotNil(t, flexgroupInstance) // Check for flexgroup constituents @@ -118,30 +117,31 @@ func runVolumeTest(t *testing.T, createVolume func(params *node.Node) plugin.Plu // Verify aggregated ops metric if setMetricNaN { assert.True(t, flexgroupMetricInstance.IsExportable()) - _, ok := cache.GetMetric("read_ops").GetValueFloat64(flexgroupInstance) + _, ok := data.GetMetric("read_ops").GetValueFloat64(flexgroupInstance) assert.False(t, ok) } else { - value, ok := cache.GetMetric("read_ops").GetValueFloat64(flexgroupInstance) + value, ok := data.GetMetric("read_ops").GetValueFloat64(flexgroupInstance) assert.True(t, ok) assert.Equal(t, value, 20.0) } // Verify aggregated latency metric (weighted average) if setMetricNaN { - _, ok := cache.GetMetric("read_latency").GetValueFloat64(flexgroupInstance) + _, ok := data.GetMetric("read_latency").GetValueFloat64(flexgroupInstance) assert.False(t, ok) } else { expectedLatency := (20*4 + 30*6 + 40*10) / 20.0 - value, ok := cache.GetMetric("read_latency").GetValueFloat64(flexgroupInstance) + value, ok := data.GetMetric("read_latency").GetValueFloat64(flexgroupInstance) assert.True(t, ok) assert.Equal(t, value, expectedLatency) } // Check for simple volume instance - simpleVolumeInstance := cache.GetInstance("svm1.SimpleVolume") - assert.Nil(t, simpleVolumeInstance) + simpleVolumeInstance := data.GetInstance("SimpleVolume") + assert.NotNil(t, simpleVolumeInstance) + assert.Equal(t, simpleVolumeInstance.GetLabel(StyleType), "flexvol") - // count instances in both data and cache + // count exportable instances currentCount := 0 for _, i := range data.GetInstances() { if i.IsExportable() { @@ -149,13 +149,7 @@ func runVolumeTest(t *testing.T, createVolume func(params *node.Node) plugin.Plu } } - for _, i := range cache.GetInstances() { - if i.IsExportable() { - currentCount++ - } - } - - // Verify the number of instances in the cache + // Verify the number of exportable instances in the data matrix assert.Equal(t, currentCount, expectedCount) } diff --git a/cmd/collectors/volume.go b/cmd/collectors/volume.go index bbfaa2951..beb4ca32b 100644 --- a/cmd/collectors/volume.go +++ b/cmd/collectors/volume.go @@ -222,10 +222,42 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string } } + // Merge FlexGroup instances from cache back to data matrix for downstream plugins like topclients + for fgKey, fgInstance := range cache.GetInstances() { + if !fgInstance.IsExportable() { + continue + } + + dataInstance := data.GetInstance(fgKey) + if dataInstance == nil { + if dataInstance, err = data.NewInstance(fgKey); err != nil { + logger.Error("Failed to create instance in data matrix", slogx.Err(err), slog.String("key", fgKey)) + continue + } + dataInstance.SetLabels(fgInstance.GetLabels()) + } + + for metricKey, cacheMetric := range cache.GetMetrics() { + if !cacheMetric.IsExportable() { + continue + } + + dataMetric := data.GetMetric(metricKey) + if dataMetric == nil { + logger.Warn("Metric not found in data matrix, skipping", slog.String("metric", metricKey)) + continue + } + + if value, ok := cacheMetric.GetValueFloat64(fgInstance); ok { + dataMetric.SetValueFloat64(dataInstance, value) + } + } + } + if enableVolumeAggrMatrix { - return []*matrix.Matrix{cache, volumeAggrMatrix}, nil, nil + return []*matrix.Matrix{volumeAggrMatrix}, nil, nil } - return []*matrix.Matrix{cache}, nil, nil + return nil, nil, nil } func ProcessFlexGroupFootPrint(data *matrix.Matrix, logger *slog.Logger) *matrix.Matrix {