Skip to content

Commit

Permalink
feat: handle review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Sep 26, 2023
1 parent 0ceb9bb commit 0acad2c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
37 changes: 19 additions & 18 deletions cmd/collectors/zapi/plugins/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
type Aggregate struct {
*plugin.AbstractPlugin
client *zapi.Client
aggrCloudStoresMap map[string][]string // aggregate-uuid -> slice of cloud stores map
aggrFootprintMap map[string]map[string]string // aggr -> map of footprint metric name and value
aggrCloudStoresMap map[string][]string // aggregate-uuid -> slice of cloud stores map
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
Expand All @@ -43,23 +42,24 @@ func (a *Aggregate) Init() error {
}

a.aggrCloudStoresMap = make(map[string][]string)
a.aggrFootprintMap = make(map[string]map[string]string)
return nil
}

func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {
data := dataMap[a.Object]
var err error

// invoke aggr-object-store-get-iter zapi and populate cloud stores info
if err = a.getCloudStores(); err != nil {
if err := a.getCloudStores(); err != nil {
if errors.Is(err, errs.ErrNoInstance) {
a.Logger.Debug().Err(err).Msg("Failed to collect cloud store data")
}
}

if err = a.getAggrFootprint(); err != nil {
aggrFootprintMap, err := a.getAggrFootprint()
if err != nil {
a.Logger.Error().Err(err).Msg("Failed to update footprint data")
// clean the map in case of the error
aggrFootprintMap = make(map[string]map[string]string)
}

// update aggregate instance label with cloud stores info
Expand All @@ -71,7 +71,7 @@ func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, er

// Handling aggr footprint metrics
aggrName := aggr.GetLabel("aggr")
if af, ok := a.aggrFootprintMap[aggrName]; ok {
if af, ok := aggrFootprintMap[aggrName]; ok {
for afKey, afVal := range af {
vfMetric := data.GetMetric(afKey)
if vfMetric == nil {
Expand Down Expand Up @@ -154,13 +154,14 @@ func (a *Aggregate) getCloudStores() error {
return nil
}

func (a *Aggregate) getAggrFootprint() error {
func (a *Aggregate) getAggrFootprint() (map[string]map[string]string, error) {
var (
result []*node.Node
err error
result []*node.Node
aggrFootprintMap map[string]map[string]string
err error
)

a.aggrFootprintMap = make(map[string]map[string]string)
aggrFootprintMap = make(map[string]map[string]string)
request := node.NewXMLS("aggr-space-get-iter")
request.NewChildS("max-records", collectors.DefaultBatchSize)
desired := node.NewXMLS("desired-attributes")
Expand All @@ -172,24 +173,24 @@ func (a *Aggregate) getAggrFootprint() error {
request.AddChild(desired)

if result, err = a.client.InvokeZapiCall(request); err != nil {
return err
return nil, err
}

if len(result) == 0 {
return nil
return aggrFootprintMap, nil
}

for _, footprint := range result {
footprintMatrics := make(map[string]string)
footprintMetrics := make(map[string]string)
aggr := footprint.GetChildContentS("aggregate")
performanceTierUsed := footprint.GetChildContentS("volume-footprints")
performanceTierUsedPerc := footprint.GetChildContentS("volume-footprints-percent")
if performanceTierUsed != "" || performanceTierUsedPerc != "" {
footprintMatrics["space_performance_tier_used"] = performanceTierUsed
footprintMatrics["space_performance_tier_used_percent"] = performanceTierUsedPerc
a.aggrFootprintMap[aggr] = footprintMatrics
footprintMetrics["space_performance_tier_used"] = performanceTierUsed
footprintMetrics["space_performance_tier_used_percent"] = performanceTierUsedPerc
aggrFootprintMap[aggr] = footprintMetrics
}
}

return nil
return aggrFootprintMap, nil
}
46 changes: 24 additions & 22 deletions cmd/collectors/zapi/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (

type Volume struct {
*plugin.AbstractPlugin
currentVal int
client *zapi.Client
aggrsMap map[string]string // aggregate-uuid -> aggregate-name map
volumeFootprintMap map[string]map[string]string // volume+svm -> map of footprint metric name and value
currentVal int
client *zapi.Client
aggrsMap map[string]string // aggregate-uuid -> aggregate-name map
}

type aggrData struct {
Expand Down Expand Up @@ -56,7 +55,6 @@ func (v *Volume) Init() error {
}

v.aggrsMap = make(map[string]string)
v.volumeFootprintMap = make(map[string]map[string]string)

// Assigned the value to currentVal so that plugin would be invoked first time to populate cache.
v.currentVal = v.SetPluginInterval()
Expand Down Expand Up @@ -98,18 +96,21 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error
v.Logger.Error().Err(err).Msg("Failed to update clone data")
}

if err := v.getVolumeFootprint(); err != nil {
volumeFootprintMap, err := v.getVolumeFootprint()
if err != nil {
v.Logger.Error().Err(err).Msg("Failed to update footprint data")
// clean the map in case of the error
volumeFootprintMap = make(map[string]map[string]string)
}

// update volume instance labels
v.updateVolumeLabels(data, volumeCloneMap)
v.updateVolumeLabels(data, volumeCloneMap, volumeFootprintMap)

v.currentVal++
return nil, nil
}

func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[string]volumeClone) {
func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[string]volumeClone, volumeFootprintMap map[string]map[string]string) {
var err error
for _, volume := range data.GetInstances() {
if !volume.IsExportable() {
Expand Down Expand Up @@ -150,7 +151,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri
}

// Handling volume footprint metrics
if vf, ok := v.volumeFootprintMap[key]; ok {
if vf, ok := volumeFootprintMap[key]; ok {
for vfKey, vfVal := range vf {
vfMetric := data.GetMetric(vfKey)
if vfMetric == nil {
Expand Down Expand Up @@ -216,13 +217,14 @@ func (v *Volume) getVolumeCloneInfo() (map[string]volumeClone, error) {
return volumeCloneMap, nil
}

func (v *Volume) getVolumeFootprint() error {
func (v *Volume) getVolumeFootprint() (map[string]map[string]string, error) {
var (
result []*node.Node
err error
result []*node.Node
volumeFootprintMap map[string]map[string]string
err error
)

v.volumeFootprintMap = make(map[string]map[string]string)
volumeFootprintMap = make(map[string]map[string]string)
request := node.NewXMLS("volume-footprint-get-iter")
request.NewChildS("max-records", collectors.DefaultBatchSize)
desired := node.NewXMLS("desired-attributes")
Expand All @@ -237,29 +239,29 @@ func (v *Volume) getVolumeFootprint() error {
request.AddChild(desired)

if result, err = v.client.InvokeZapiCall(request); err != nil {
return err
return nil, err
}

if len(result) == 0 {
return nil
return volumeFootprintMap, nil
}

for _, footprint := range result {
footprintMatrics := make(map[string]string)
footprintMetrics := make(map[string]string)
volume := footprint.GetChildContentS("volume")
svm := footprint.GetChildContentS("vserver")
performanceTierFootprint := footprint.GetChildContentS("volume-blocks-footprint-bin0")
performanceTierFootprintPerc := footprint.GetChildContentS("volume-blocks-footprint-bin0-percent")
capacityTierFootprint := footprint.GetChildContentS("volume-blocks-footprint-bin1")
capacityTierFootprintPerc := footprint.GetChildContentS("volume-blocks-footprint-bin1-percent")
footprintMatrics["performance_tier_footprint"] = performanceTierFootprint
footprintMatrics["performance_tier_footprint_percent"] = performanceTierFootprintPerc
footprintMatrics["capacity_tier_footprint"] = capacityTierFootprint
footprintMatrics["capacity_tier_footprint_percent"] = capacityTierFootprintPerc
v.volumeFootprintMap[volume+svm] = footprintMatrics
footprintMetrics["performance_tier_footprint"] = performanceTierFootprint
footprintMetrics["performance_tier_footprint_percent"] = performanceTierFootprintPerc
footprintMetrics["capacity_tier_footprint"] = capacityTierFootprint
footprintMetrics["capacity_tier_footprint_percent"] = capacityTierFootprintPerc
volumeFootprintMap[volume+svm] = footprintMetrics
}

return nil
return volumeFootprintMap, nil
}

func (v *Volume) getEncryptedDisks() ([]string, error) {
Expand Down

0 comments on commit 0acad2c

Please sign in to comment.