From eb7dd269c9486ce8c5fe15b7aa5d245852f43b66 Mon Sep 17 00:00:00 2001 From: hardikl Date: Tue, 8 Oct 2024 16:04:59 +0530 Subject: [PATCH] fix: handled review comments --- .../restperf/plugins/volume/volume.go | 18 ++++++++++++++++-- cmd/collectors/volume.go | 5 +++++ .../zapiperf/plugins/volume/volume.go | 17 +++++++++++++++-- cmd/poller/plugin/plugin.go | 15 +++++++++------ 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/cmd/collectors/restperf/plugins/volume/volume.go b/cmd/collectors/restperf/plugins/volume/volume.go index 1b0357361..6efa204f9 100644 --- a/cmd/collectors/restperf/plugins/volume/volume.go +++ b/cmd/collectors/restperf/plugins/volume/volume.go @@ -13,9 +13,11 @@ import ( type Volume struct { *plugin.AbstractPlugin + currentVal int styleType string includeConstituents bool client *rest.Client + volumesMap map[string]string // volume-name -> volume-extended-style map } func New(p *plugin.AbstractPlugin) plugin.Plugin { @@ -34,6 +36,11 @@ func (v *Volume) Init() error { v.styleType = "type" } + v.volumesMap = make(map[string]string) + + // Assigned the value to currentVal so that plugin would be invoked first time to populate cache. + v.currentVal = v.SetPluginInterval() + // Read template to decide inclusion of flexgroup constituents v.includeConstituents = collectors.ReadPluginKey(v.Params, "include_constituents") @@ -55,9 +62,15 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util data := dataMap[v.Object] style := v.styleType opsKeyPrefix := "temp_" - volumesMap := v.fetchVolumes() + if v.currentVal >= v.PluginInvocationRate { + v.currentVal = 0 + // Clean volumesMap map + clear(v.volumesMap) + v.volumesMap = v.fetchVolumes() + } - return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, volumesMap) + v.currentVal++ + return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, v.volumesMap) } func (v *Volume) fetchVolumes() map[string]string { @@ -67,6 +80,7 @@ func (v *Volume) fetchVolumes() map[string]string { href := rest.NewHrefBuilder(). APIPath(query). Fields([]string{"volume", "volume_style_extended"}). + MaxRecords(collectors.DefaultBatchSize). Build() records, err := rest.FetchAll(v.client, href) diff --git a/cmd/collectors/volume.go b/cmd/collectors/volume.go index c2fb943b3..6284f2297 100644 --- a/cmd/collectors/volume.go +++ b/cmd/collectors/volume.go @@ -16,6 +16,11 @@ var flexgroupRegex = regexp.MustCompile(`^(.*)__(\d{4})$`) func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string, includeConstituents bool, opsKeyPrefix string, volumesMap map[string]string) ([]*matrix.Matrix, *util.Metadata, error) { var err error + if volumesMap == nil { + logger.Info("volumes config data not found") + return nil, nil, nil + } + fgAggrMap := make(map[string]*set.Set) flexgroupAggrsMap := make(map[string]*set.Set) diff --git a/cmd/collectors/zapiperf/plugins/volume/volume.go b/cmd/collectors/zapiperf/plugins/volume/volume.go index 8d5a10119..5af6eaea5 100644 --- a/cmd/collectors/zapiperf/plugins/volume/volume.go +++ b/cmd/collectors/zapiperf/plugins/volume/volume.go @@ -19,9 +19,11 @@ const batchSize = "500" type Volume struct { *plugin.AbstractPlugin + currentVal int styleType string includeConstituents bool client *zapi.Client + volumesMap map[string]string // volume-name -> volume-extended-style map } func New(p *plugin.AbstractPlugin) plugin.Plugin { @@ -44,6 +46,11 @@ func (v *Volume) Init() error { return nil } + v.volumesMap = make(map[string]string) + + // Assigned the value to currentVal so that plugin would be invoked first time to populate cache. + v.currentVal = v.SetPluginInterval() + // Read template to decide inclusion of flexgroup constituents v.includeConstituents = collectors.ReadPluginKey(v.Params, "include_constituents") @@ -58,9 +65,15 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util data := dataMap[v.Object] style := v.styleType opsKeyPrefix := "temp_" - volumesMap := v.fetchVolumes() + if v.currentVal >= v.PluginInvocationRate { + v.currentVal = 0 + // Clean volumesMap map + clear(v.volumesMap) + v.volumesMap = v.fetchVolumes() + } - return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, volumesMap) + v.currentVal++ + return collectors.ProcessFlexGroupData(v.SLogger, data, style, v.includeConstituents, opsKeyPrefix, v.volumesMap) } func (v *Volume) fetchVolumes() map[string]string { diff --git a/cmd/poller/plugin/plugin.go b/cmd/poller/plugin/plugin.go index ccd4ae738..ea69207ae 100644 --- a/cmd/poller/plugin/plugin.go +++ b/cmd/poller/plugin/plugin.go @@ -167,15 +167,18 @@ func (p *AbstractPlugin) SetPluginInterval() int { } func GetInterval(param *node.Node, defaultInterval time.Duration) float64 { - schedule := param.GetChildS("schedule") - if schedule != nil { - dataInterval := schedule.GetChildContentS("data") - if dataInterval != "" { - if durationVal, err := time.ParseDuration(dataInterval); err == nil { - return durationVal.Seconds() + if param != nil { + schedule := param.GetChildS("schedule") + if schedule != nil { + dataInterval := schedule.GetChildContentS("data") + if dataInterval != "" { + if durationVal, err := time.ParseDuration(dataInterval); err == nil { + return durationVal.Seconds() + } } } } + return defaultInterval.Seconds() }