Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch cloud_store info in zapi via plugin #2094

Merged
merged 5 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions cmd/collectors/zapi/plugins/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

type Aggregate struct {
*plugin.AbstractPlugin
currentVal int
client *zapi.Client
aggrCloudStoresMap map[string][]string // aggregate-uuid -> slice of cloud stores map
}
Expand All @@ -23,66 +22,59 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Aggregate{AbstractPlugin: p}
}

func (my *Aggregate) Init() error {
func (a *Aggregate) Init() error {

var err error

if err = my.InitAbc(); err != nil {
if err = a.InitAbc(); err != nil {
return err
}

if my.client, err = zapi.New(conf.ZapiPoller(my.ParentParams), my.Auth); err != nil {
my.Logger.Error().Stack().Err(err).Msg("connecting")
if a.client, err = zapi.New(conf.ZapiPoller(a.ParentParams), a.Auth); err != nil {
a.Logger.Error().Stack().Err(err).Msg("connecting")
return err
}

if err = my.client.Init(5); err != nil {
if err = a.client.Init(5); err != nil {
return err
}

my.aggrCloudStoresMap = make(map[string][]string)

// Assigned the value to currentVal so that plugin would be invoked first time to populate cache.
my.currentVal = my.SetPluginInterval()
a.aggrCloudStoresMap = make(map[string][]string)
return nil
}

func (my *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {

data := dataMap[my.Object]
if my.currentVal >= my.PluginInvocationRate {
my.currentVal = 0
func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {
data := dataMap[a.Object]

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return if error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not be. As it's addition of label in aggregate object, even if this call failed or no response or 0 records, aggr_labels should show data.

if errors.Is(err, errs.ErrNoInstance) {
a.Logger.Debug().Err(err).Msg("Failed to collect cloud store data")
} else {
a.Logger.Error().Err(err).Msg("Failed to collect cloud store data")
}
}

// update aggregate instance label with cloud stores
for aggrUUID, aggr := range data.GetInstances() {
aggr.SetLabel("cloud_stores", strings.Join(my.aggrCloudStoresMap[aggrUUID], ","))
// update aggregate instance label with cloud stores info
if len(a.aggrCloudStoresMap) > 0 {
for aggrUUID, aggr := range data.GetInstances() {
aggr.SetLabel("cloud_stores", strings.Join(a.aggrCloudStoresMap[aggrUUID], ","))
}
}

my.currentVal++
return nil, nil
}

func (my *Aggregate) getCloudStores() error {
func (a *Aggregate) getCloudStores() error {
var (
result []*node.Node
err error
)

my.aggrCloudStoresMap = make(map[string][]string)
a.aggrCloudStoresMap = make(map[string][]string)
request := node.NewXMLS("aggr-object-store-get-iter")
request.NewChildS("max-records", collectors.DefaultBatchSize)
Hardikl marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -93,7 +85,7 @@ func (my *Aggregate) getCloudStores() error {
for _, objectStore := range result {
aggregateUUID := objectStore.GetChildContentS("aggregate-uuid")
objectStoreName := objectStore.GetChildContentS("object-store-name")
my.aggrCloudStoresMap[aggregateUUID] = append(my.aggrCloudStoresMap[aggregateUUID], objectStoreName)
a.aggrCloudStoresMap[aggregateUUID] = append(a.aggrCloudStoresMap[aggregateUUID], objectStoreName)
}
return nil
}
4 changes: 1 addition & 3 deletions conf/zapi/cdot/9.8.0/aggr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ counters:
- flexvol-count

plugins:
- Aggregate:
schedule:
- data: 900s # should be multiple of data poll duration
- Aggregate
- LabelAgent:
exclude_equals:
- root_aggr `true`
Expand Down