From b1352acac18b87bd9ec5ecaac25c83ac608acb1d Mon Sep 17 00:00:00 2001 From: Rahul Date: Fri, 6 Dec 2024 18:58:12 +0530 Subject: [PATCH] fix: handle volume cache for performance data (#3361) * fix: handle volume cache for performance data --- .../restperf/plugins/volume/volume.go | 20 +++++++++------- cmd/collectors/volume.go | 2 +- .../zapiperf/plugins/volume/volume.go | 23 +++++++++++-------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/cmd/collectors/restperf/plugins/volume/volume.go b/cmd/collectors/restperf/plugins/volume/volume.go index 777acfd26..bd9e8db40 100644 --- a/cmd/collectors/restperf/plugins/volume/volume.go +++ b/cmd/collectors/restperf/plugins/volume/volume.go @@ -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" @@ -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 { @@ -105,5 +109,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..57fe63147 100644 --- a/cmd/collectors/volume.go +++ b/cmd/collectors/volume.go @@ -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 } diff --git a/cmd/collectors/zapiperf/plugins/volume/volume.go b/cmd/collectors/zapiperf/plugins/volume/volume.go index 8409c1356..981dc05bf 100644 --- a/cmd/collectors/zapiperf/plugins/volume/volume.go +++ b/cmd/collectors/zapiperf/plugins/volume/volume.go @@ -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) @@ -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 @@ -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 { @@ -125,5 +130,5 @@ func (v *Volume) fetchVolumes() map[string]string { } } - return volumesMap + return volumesMap, nil }