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

fix: vscan plugin should handle IPv6 scanners #3034

Merged
merged 1 commit into from
Jul 4, 2024
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
20 changes: 20 additions & 0 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ func ReadPluginKey(param *node.Node, key string) bool {
}
return false
}

func SplitVscanName(ontapName string) (string, string, string, bool) {
// colon separated list of fields
// svm : scanner : node
// vs_test4 : 2.2.2.2 : umeng-aff300-05
// moon-ad : 2a03:1e80:a15:60c::1:2a5 : moon-02

firstColon := strings.Index(ontapName, ":")
if firstColon == -1 {
return "", "", "", false
}
lastColon := strings.LastIndex(ontapName, ":")
if lastColon == -1 {
return "", "", "", false
}
if firstColon == lastColon {
return "", "", "", false
}
return ontapName[:firstColon], ontapName[firstColon+1 : lastColon], ontapName[lastColon+1:], true
}
62 changes: 62 additions & 0 deletions cmd/collectors/commonutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,65 @@ func populateInstance(data *matrix.Matrix, instanceName, healthy, schedule, last
}
return instance
}

func Test_SplitVscanName(t *testing.T) {
tests := []struct {
name string
ontapName string
svm string
scanner string
node string
isValid bool
}{
{
name: "valid",
ontapName: "svm:scanner:node",
svm: "svm",
scanner: "scanner",
node: "node",
isValid: true,
},
{
name: "ipv6",
ontapName: "moon-ad:2a03:1e80:a15:60c::1:2a5:moon-02",
svm: "moon-ad",
scanner: "2a03:1e80:a15:60c::1:2a5",
node: "moon-02",
isValid: true,
},
{
name: "invalid zero colon",
ontapName: "svm",
svm: "",
scanner: "",
node: "",
isValid: false,
},
{
name: "invalid one colon",
ontapName: "svm:scanner",
svm: "",
scanner: "",
node: "",
isValid: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotSVM, gotScanner, gotNode, ok := SplitVscanName(tt.ontapName)
if gotSVM != tt.svm {
t.Errorf("splitOntapName() got = %v, want %v", gotSVM, tt.svm)
}
if gotScanner != tt.scanner {
t.Errorf("splitOntapName() got = %v, want %v", gotScanner, tt.scanner)
}
if gotNode != tt.node {
t.Errorf("splitOntapName() got = %v, want %v", gotNode, tt.node)
}
if ok != tt.isValid {
t.Errorf("splitOntapName() got = %v, want %v", ok, tt.isValid)
}
})
}
}
15 changes: 7 additions & 8 deletions cmd/collectors/restperf/plugins/vscan/vscan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vscan

import (
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
Expand Down Expand Up @@ -41,16 +42,14 @@ func (v *Vscan) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.
func (v *Vscan) addSvmAndScannerLabels(data *matrix.Matrix) {
for _, instance := range data.GetInstances() {
ontapName := instance.GetLabel("id")
// colon separated list of fields
// A900-node1 : vs0 : 2.2.2.2
// node : svm : scanner
if split := strings.Split(ontapName, ":"); len(split) >= 3 {
instance.SetLabel("node", split[0])
instance.SetLabel("svm", split[1])
instance.SetLabel("scanner", split[2])
} else {
svm, scanner, node, ok := collectors.SplitVscanName(ontapName)
if !ok {
v.Logger.Warn().Str("ontapName", ontapName).Msg("Failed to parse svm and scanner labels")
continue
}
instance.SetLabel("svm", svm)
instance.SetLabel("scanner", scanner)
instance.SetLabel("node", node)
}
}

Expand Down
23 changes: 2 additions & 21 deletions cmd/collectors/zapiperf/plugins/vscan/vscan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vscan

import (
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (v *Vscan) addSvmAndScannerLabels(data *matrix.Matrix) {
continue
}
ontapName := instance.GetLabel("instance_uuid")
svm, scanner, node, ok := splitOntapName(ontapName)
svm, scanner, node, ok := collectors.SplitVscanName(ontapName)
if !ok {
v.Logger.Warn().Str("ontapName", ontapName).Msg("Failed to parse svm and scanner labels")
continue
Expand All @@ -55,26 +56,6 @@ func (v *Vscan) addSvmAndScannerLabels(data *matrix.Matrix) {
}
}

func splitOntapName(ontapName string) (string, string, string, bool) {
// colon separated list of fields
// svm : scanner : node
// vs_test4 : 2.2.2.2 : umeng-aff300-05
// moon-ad : 2a03:1e80:a15:60c::1:2a5 : moon-02

firstColon := strings.Index(ontapName, ":")
if firstColon == -1 {
return "", "", "", false
}
lastColon := strings.LastIndex(ontapName, ":")
if lastColon == -1 {
return "", "", "", false
}
if firstColon == lastColon {
return "", "", "", false
}
return ontapName[:firstColon], ontapName[firstColon+1 : lastColon], ontapName[lastColon+1:], true
}

func (v *Vscan) aggregatePerScanner(data *matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
// When isPerScanner=true, Harvest 1.6 uses this form:
// netapp.perf.dev.nltl-fas2520.vscan.scanner.10_64_30_62.scanner_stats_pct_mem_used 18 1501765640
Expand Down
65 changes: 0 additions & 65 deletions cmd/collectors/zapiperf/plugins/vscan/vscan_test.go

This file was deleted.