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: adding ha_partner info in node #2723

Merged
merged 9 commits into from
Mar 15, 2024
Prev Previous commit
feat: handled reivew comments
  • Loading branch information
Hardikl committed Mar 15, 2024
commit 1e43def6825e7abb3f473e1f1e76eb18a3c7e582
31 changes: 31 additions & 0 deletions cmd/collectors/rest/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package systemnode

import (
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
)

type SystemNode struct {
*plugin.AbstractPlugin
}

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

func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
data := dataMap[s.Object]
nodeStateMap := make(map[string]string)

for _, node := range data.GetInstanceKeys() {
nodeStateMap[node] = data.GetInstance(node).GetLabel("healthy")
}

// update node instance with partner_healthy info
for _, node := range data.GetInstances() {
node.SetLabel("partner_healthy", nodeStateMap[node.GetLabel("ha_partner")])
}

return nil, nil, nil
}
3 changes: 3 additions & 0 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/shelf"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/snapmirror"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/svm"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/systemnode"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/volume"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/volumeanalytics"
"github.com/netapp/harvest/v2/cmd/poller/collector"
Expand Down Expand Up @@ -445,6 +446,8 @@ func (r *Rest) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
return ontaps3service.New(abc)
case "MetroclusterCheck":
return metroclustercheck.New(abc)
case "SystemNode":
return systemnode.New(abc)
default:
r.Logger.Warn().Str("kind", kind).Msg("no rest plugin found ")
}
Expand Down
28 changes: 18 additions & 10 deletions cmd/collectors/zapi/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"github.com/netapp/harvest/v2/pkg/util"
)

type SystemNode struct {
Expand Down Expand Up @@ -38,36 +39,43 @@ func (s *SystemNode) Init() error {
return nil
}

func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {
func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
data := dataMap[s.Object]
s.client.Metadata.Reset()
nodeStateMap := make(map[string]string)

// invoke system-get-node-info-iter zapi and populate node info
partnerNameMap, err := s.getPartnerNodeInfo()
if err != nil {
s.Logger.Error().Err(err).Msg("Failed to collect partner node detail")
}

// update node instance with partner info
for _, node := range data.GetInstanceKeys() {
nodeStateMap[node] = data.GetInstance(node).GetLabel("healthy")
}

// update node instance with partner and partner_healthy info
for nodeName, node := range data.GetInstances() {
node.SetLabel("ha_partner", partnerNameMap[nodeName])
node.SetLabel("partner_healthy", nodeStateMap[node.GetLabel("ha_partner")])
}

// update node metrics with partner info
for _, metric := range data.GetMetrics() {
metric.SetLabel("ha_partner", partnerNameMap[metric.GetLabel("node")])
}
return nil, nil
return nil, s.client.Metadata, nil
}

func (s *SystemNode) getPartnerNodeInfo() (map[string]string, error) {
var (
result []*node.Node
partnerNameMap map[string]string // node-name -> partner name map
err error
result []*node.Node
nodePartnerNodeMap map[string]string // node-name -> partner-node-name map
err error
)

// system-get-node-info-iter zapi
partnerNameMap = make(map[string]string)
nodePartnerNodeMap = make(map[string]string)
request := node.NewXMLS("system-get-node-info-iter")
request.NewChildS("max-records", collectors.DefaultBatchSize)

Expand All @@ -84,13 +92,13 @@ func (s *SystemNode) getPartnerNodeInfo() (map[string]string, error) {

if len(result) == 0 || result == nil {
s.Logger.Debug().Err(err).Msg("no records found")
return partnerNameMap, nil
return nodePartnerNodeMap, nil
}

for _, objectStore := range result {
partnerName := objectStore.GetChildContentS("partner-system-name")
nodeName := objectStore.GetChildContentS("system-name")
partnerNameMap[nodeName] = partnerName
nodePartnerNodeMap[nodeName] = partnerName
}
return partnerNameMap, nil
return nodePartnerNodeMap, nil
}
2 changes: 2 additions & 0 deletions conf/rest/9.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ endpoints:
- cpu_busy_time => cpu_busytime

plugins:
- SystemNode
- LabelAgent:
value_to_num:
- new_status healthy true up `0`
Expand All @@ -52,6 +53,7 @@ export_options:
- max_vol_num
- max_vol_size
- model
- partner_healthy
- state
- uptime
- vendor
Expand Down
1 change: 1 addition & 0 deletions conf/zapi/cdot/9.8.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export_options:
- max_vol_num
- max_vol_size
- model
- partner_healthy
- uptime
- vendor
- version
Expand Down
Loading