Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions cmd/collectors/restperf/plugins/volume/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -118,44 +117,39 @@ 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() {
currentCount++
}
}

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)
}

Expand Down
36 changes: 34 additions & 2 deletions cmd/collectors/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading