diff --git a/cmd/collectors/restperf/plugins/volume/volume.go b/cmd/collectors/restperf/plugins/volume/volume.go index 777acfd26..3a9e68b77 100644 --- a/cmd/collectors/restperf/plugins/volume/volume.go +++ b/cmd/collectors/restperf/plugins/volume/volume.go @@ -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" @@ -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 { @@ -105,5 +110,5 @@ func (v *Volume) fetchVolumes() map[string]string { volumesMap[svm+name] = styleExtended } - return volumesMap + return volumesMap, nil } diff --git a/cmd/collectors/volume.go b/cmd/collectors/volume.go index 7801caa32..bfc66b92c 100644 --- a/cmd/collectors/volume.go +++ b/cmd/collectors/volume.go @@ -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 } diff --git a/cmd/collectors/zapiperf/plugins/volume/volume.go b/cmd/collectors/zapiperf/plugins/volume/volume.go index 8409c1356..cf4d793a1 100644 --- a/cmd/collectors/zapiperf/plugins/volume/volume.go +++ b/cmd/collectors/zapiperf/plugins/volume/volume.go @@ -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) @@ -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 @@ -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 { @@ -125,5 +131,5 @@ func (v *Volume) fetchVolumes() map[string]string { } } - return volumesMap + return volumesMap, nil }