Skip to content

Commit

Permalink
fix: handled review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Oct 8, 2024
1 parent 805f750 commit eb7dd26
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
18 changes: 16 additions & 2 deletions cmd/collectors/restperf/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmd/collectors/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 15 additions & 2 deletions cmd/collectors/zapiperf/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")

Expand All @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions cmd/poller/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit eb7dd26

Please sign in to comment.