Skip to content

Commit

Permalink
fix: handle volume cache for performance data (#3361)
Browse files Browse the repository at this point in the history
* fix: handle volume cache for performance data
  • Loading branch information
rahulguptajss authored Dec 6, 2024
1 parent f7fdf52 commit b1352ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
20 changes: 12 additions & 8 deletions cmd/collectors/restperf/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,21 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util
opsKeyPrefix := "temp_"
if v.currentVal >= v.PluginInvocationRate {
v.currentVal = 0
// Clean volumesMap map
clear(v.volumesMap)
v.volumesMap = v.fetchVolumes()
// Attempt to fetch new volumes
newVolumesMap, err := v.fetchVolumes()
if err != nil {
v.SLogger.Error("Failed to fetch volumes, retaining cached volumesMap", slog.Any("err", err))
} else {
// Only update volumesMap if fetchVolumes was successful
v.volumesMap = newVolumesMap
}
}

v.currentVal++
return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, v.volumesMap)
}

func (v *Volume) fetchVolumes() map[string]string {
func (v *Volume) fetchVolumes() (map[string]string, error) {
volumesMap := make(map[string]string)
query := "api/private/cli/volume"

Expand All @@ -86,12 +91,11 @@ func (v *Volume) fetchVolumes() map[string]string {

records, err := rest.FetchAll(v.client, href)
if err != nil {
v.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href))
return nil
return nil, err
}

if len(records) == 0 {
return nil
return volumesMap, nil
}

for _, volume := range records {
Expand All @@ -105,5 +109,5 @@ func (v *Volume) fetchVolumes() map[string]string {
volumesMap[svm+name] = styleExtended
}

return volumesMap
return volumesMap, nil
}
2 changes: 1 addition & 1 deletion cmd/collectors/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string
var err error

if volumesMap == nil {
logger.Info("volumes config data not found")
logger.Debug("volumes config data is empty")
return nil, nil, nil
}

Expand Down
23 changes: 14 additions & 9 deletions cmd/collectors/zapiperf/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,27 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util
opsKeyPrefix := "temp_"
if v.currentVal >= v.PluginInvocationRate {
v.currentVal = 0
// Clean volumesMap map
clear(v.volumesMap)
v.volumesMap = v.fetchVolumes()
// Attempt to fetch new volumes
newVolumesMap, err := v.fetchVolumes()
if err != nil {
v.SLogger.Error("Failed to fetch volumes, retaining cached volumesMap", slog.Any("err", err))
} else {
// Only update volumesMap if fetchVolumes was successful
v.volumesMap = newVolumesMap
}
}

v.currentVal++
return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, v.volumesMap)
}

func (v *Volume) fetchVolumes() map[string]string {
func (v *Volume) fetchVolumes() (map[string]string, error) {
var (
result *node.Node
volumes []*node.Node
volumesMap map[string]string
volumesMap = make(map[string]string)
)

volumesMap = make(map[string]string)
query := "volume-get-iter"
tag := "initial"
request := node.NewXMLS(query)
Expand All @@ -101,7 +105,8 @@ func (v *Volume) fetchVolumes() map[string]string {
for {
responseData, err := v.client.InvokeBatchRequest(request, tag, "")
if err != nil {
return nil
v.SLogger.Error("Failed to fetch data", slog.Any("err", err))
return nil, err
}
result = responseData.Result
tag = responseData.Tag
Expand All @@ -114,7 +119,7 @@ func (v *Volume) fetchVolumes() map[string]string {
volumes = x.GetChildren()
}
if len(volumes) == 0 {
return nil
return volumesMap, nil
}

for _, volume := range volumes {
Expand All @@ -125,5 +130,5 @@ func (v *Volume) fetchVolumes() map[string]string {
}
}

return volumesMap
return volumesMap, nil
}

0 comments on commit b1352ac

Please sign in to comment.