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: Network Port templates #1231

Merged
merged 1 commit into from
Aug 26, 2022
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
10 changes: 9 additions & 1 deletion 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/pkg/errs"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"github.com/netapp/harvest/v2/pkg/util"
"github.com/tidwall/gjson"
"os"
"sort"
Expand All @@ -25,6 +26,11 @@ import (
"time"
)

var (
//ignore missing label warning in log. In Rest, some fields are not present in response when not applicable.
rahulguptajss marked this conversation as resolved.
Show resolved Hide resolved
ignoreLabelMissingWarning = []string{"NetPort"}
)

type Rest struct {
*collector.AbstractCollector
Client *rest.Client
Expand Down Expand Up @@ -443,7 +449,9 @@ func (r *Rest) HandleResults(result []gjson.Result, prop *prop, allowInstanceCre
}
count++
} else {
r.Logger.Warn().Str("Instance key", instanceKey).Str("label", label).Msg("Missing label value")
if !util.Contains(ignoreLabelMissingWarning, r.GetObject()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor but a map would be better than a list. On the other hand, this list only has one item so meh.
Doesn't this change suppress all labels warnings for NetPort?
If so, doesn't that make it easy to miss a mistyped label?
Can the bigger problem be solved by explicitly specifying the labels instead of using include_all_labels: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, all label warnings for NetPort will be suppressed. include_all_labels: true is used in prometheus.go and not during the collector. A solution would be to parse schema and compare if label is mistyped. I'll open a story to track it.

r.Logger.Warn().Str("Instance key", instanceKey).Str("label", label).Msg("Missing label value")
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions conf/rest/9.12.0/netPort.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: NetPort
query: api/network/ethernet/ports
object: net_port

counters:
- ^^name => port
- ^^node.name => node
- ^broadcast_domain.name => broadcast
- ^lag.distribution_policy => lag_distribution_policy
- ^lag.mode => lag_mode
- ^lag.active_ports.name => lag_port
- ^broadcast_domain.ipspace.name => ipspace
- ^enabled => admin_up
- ^state => status
- ^vlan.tag => vlan_id
- ^vlan.base_port.node.name => vlan_node
- ^vlan.base_port.name => vlan_port
- mtu => mtu
- operational-speed => op_speed

plugins:
LabelAgent:
value_to_num:
- status status up up `0`

export_options:
include_all_labels: true
1 change: 1 addition & 0 deletions conf/rest/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ objects:
# ClusterPeer: clusterpeer.yaml
# Disk: disk.yaml
# Lun: lun.yaml
# NetPort: netPort.yaml
# Node: node.yaml
# NtpServer: ntpserver.yaml
# Port: port.yaml
Expand Down
28 changes: 28 additions & 0 deletions conf/zapi/cdot/9.8.0/netPort.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: NetPort
query: net-port-get-iter
object: net_port

counters:
net-port-info:
- ^^port => port
- ^^node => node
- ^broadcast-domain => broadcast
- ^ifgrp-distribution-function => lag_distribution_policy
- ^ifgrp-mode => lag_mode
- ^ifgrp-port => lag_port
- ^ipspace => ipspace
- ^is-administrative-up => admin_up
- ^link-status => status
- ^vlan-id => vlan_id
- ^vlan-node => vlan_node
- ^vlan-port => vlan_port
- mtu => mtu
- operational-speed => op_speed

plugins:
LabelAgent:
value_to_num:
- status status up up `0`

export_options:
include_all_labels: true
1 change: 1 addition & 0 deletions conf/zapi/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ objects:
ClusterPeer: clusterpeer.yaml
Disk: disk.yaml
Lun: lun.yaml
# NetPort: netPort.yaml
Node: node.yaml
NtpServer: ntpserver.yaml
Qtree: qtree.yaml
Expand Down