Skip to content

Commit

Permalink
fix: handle volume cache for performance data
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Dec 6, 2024
1 parent e435bd1 commit b4cb8c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
21 changes: 13 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,22 @@ 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
clear(v.volumesMap)
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 +92,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 +110,5 @@ func (v *Volume) fetchVolumes() map[string]string {
volumesMap[svm+name] = styleExtended
}

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

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

Expand Down
24 changes: 15 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,28 @@ 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
clear(v.volumesMap)
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 +106,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 +120,7 @@ func (v *Volume) fetchVolumes() map[string]string {
volumes = x.GetChildren()
}
if len(volumes) == 0 {
return nil
break
}

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

return volumesMap
return volumesMap, nil
}

0 comments on commit b4cb8c2

Please sign in to comment.