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 all 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
4 changes: 3 additions & 1 deletion cmd/collectors/zapi/collector/zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package zapi

import (
"fmt"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/aggregate"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/certificate"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/qospolicyadaptive"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/qospolicyfixed"
Expand Down Expand Up @@ -156,7 +157,8 @@ func (z *Zapi) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
return qospolicyfixed.New(abc)
case "QosPolicyAdaptive":
return qospolicyadaptive.New(abc)

case "Aggregate":
return aggregate.New(abc)
default:
z.Logger.Info().Msgf("no zapi plugin found for %s", kind)
}
Expand Down
98 changes: 98 additions & 0 deletions cmd/collectors/zapi/plugins/aggregate/aggregate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package aggregate

import (
"errors"
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/api/ontapi/zapi"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/errs"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"strings"
)

type Aggregate struct {
*plugin.AbstractPlugin
client *zapi.Client
aggrCloudStoresMap map[string][]string // aggregate-uuid -> slice of cloud stores map
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Aggregate{AbstractPlugin: p}
}

func (a *Aggregate) Init() error {

var err error

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

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 = a.client.Init(5); err != nil {
return err
}

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

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 := 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")
return nil, nil
}
return nil, err
}

// 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], ","))
}
}
return nil, nil
}

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

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

desired := node.NewXMLS("desired-attributes")
objectStoreInfo := node.NewXMLS("object-store-information")
objectStoreInfo.NewChildS("aggregate-uuid", "")
objectStoreInfo.NewChildS("object-store-name", "")
desired.AddChild(objectStoreInfo)
request.AddChild(desired)

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

if len(result) == 0 || result == nil {
return errs.New(errs.ErrNoInstance, "no records found")
}

for _, objectStore := range result {
aggregateUUID := objectStore.GetChildContentS("aggregate-uuid")
objectStoreName := objectStore.GetChildContentS("object-store-name")
a.aggrCloudStoresMap[aggregateUUID] = append(a.aggrCloudStoresMap[aggregateUUID], objectStoreName)
}
return nil
}
4 changes: 3 additions & 1 deletion conf/zapi/cdot/9.8.0/aggr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ counters:
- flexvol-count

plugins:
LabelAgent:
- Aggregate
- LabelAgent:
exclude_equals:
- root_aggr `true`
# metric label zapi_value rest_value `default_value`
Expand All @@ -73,6 +74,7 @@ export_options:
- aggr
- node
instance_labels:
- cloud_stores
- is_encrypted
- state
- type