Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into hl_quota_invoke
Browse files Browse the repository at this point in the history
# Conflicts:
#	cmd/collectors/commonutils.go
#	cmd/collectors/commonutils_test.go
  • Loading branch information
Hardikl committed Jul 9, 2024
2 parents 3158513 + a6a60b8 commit 596cb0c
Show file tree
Hide file tree
Showing 34 changed files with 260 additions and 1,144 deletions.
21 changes: 17 additions & 4 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,22 @@ func ReadPluginKey(param *node.Node, key string) bool {
return false
}

func RunPlugin(runPluginIfNoData bool, mat map[string]*matrix.Matrix, err error) (map[string]*matrix.Matrix, error) {
if runPluginIfNoData {
return mat, nil
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
}
return nil, err
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
}
76 changes: 52 additions & 24 deletions cmd/collectors/commonutils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package collectors

import (
"errors"
"github.com/netapp/harvest/v2/pkg/errs"
"github.com/netapp/harvest/v2/pkg/logging"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
Expand Down Expand Up @@ -337,33 +335,63 @@ func populateInstance(data *matrix.Matrix, instanceName, healthy, schedule, last
return instance
}

func TestRunPlugin(t *testing.T) {
type test struct {
name string
runPluginIfNoData bool
mat map[string]*matrix.Matrix
err error
wantMatrix bool
wantErr error
}

testMat := make(map[string]*matrix.Matrix)
err := errs.New(errs.ErrConfig, "test Error")

tests := []test{
{"runPluginIfNoData_false", false, testMat, err, false, err},
{"runPluginIfNoData_true", true, testMat, err, true, nil},
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) {
got, err := RunPlugin(tt.runPluginIfNoData, tt.mat, tt.err)
if !errors.Is(err, tt.wantErr) {
t.Errorf("RunPlugin() error = %v, wantErr %v", err, tt.wantErr)
return
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 (got != nil) != tt.wantMatrix {
t.Errorf("RunPlugin() got = %v, wantMatrix %v", got, tt.wantMatrix)
if ok != tt.isValid {
t.Errorf("splitOntapName() got = %v, want %v", ok, tt.isValid)
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/collectors/rest/plugins/securityaccount/securityaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func (s *SecurityAccount) Init() error {
}

clientTimeout := s.ParentParams.GetChildContentS("client_timeout")
timeout, _ := time.ParseDuration(rest.DefaultTimeout)
duration, err := time.ParseDuration(clientTimeout)
if err == nil {
timeout = duration
} else {
s.Logger.Info().Str("timeout", timeout.String()).Msg("Using default timeout")
if clientTimeout == "" {
clientTimeout = rest.DefaultTimeout
}
timeout, err := time.ParseDuration(clientTimeout)
if err != nil {
s.Logger.Info().Str("timeout", rest.DefaultTimeout).Msg("Using default timeout")
}
if s.client, err = rest.New(conf.ZapiPoller(s.ParentParams), timeout, s.Auth); err != nil {
return fmt.Errorf("failed to connect err=%w", err)
Expand Down
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.

10 changes: 0 additions & 10 deletions cmd/harvest/harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,6 @@ func doManageCmd(cmd *cobra.Command, args []string) {
os.Exit(0)
}

table := tw.NewWriter(os.Stdout)
table.SetBorder(false)
table.SetAutoFormatHeaders(false)
if opts.longStatus {
table.SetHeader([]string{"Datacenter", "Poller", "PID", "PromPort", "Profiling", "Status"})
} else {
table.SetHeader([]string{"Datacenter", "Poller", "PID", "PromPort", "Status"})
}
table.SetColumnAlignment([]int{tw.ALIGN_LEFT, tw.ALIGN_LEFT, tw.ALIGN_RIGHT, tw.ALIGN_RIGHT, tw.ALIGN_RIGHT})

statusesByName := getPollersStatus()
switch opts.command {
case "restart":
Expand Down
5 changes: 4 additions & 1 deletion cmd/poller/collector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *AbstractCollector) ImportSubTemplate(model, filename, jitter string, ve
customTemplateErr error
finalTemplate *node.Node
customTemplate *node.Node
importErrs []error
)

if filename == "" {
Expand Down Expand Up @@ -100,6 +101,7 @@ nextFile:
finalTemplate.PreprocessTemplate()
continue nextFile
}
importErrs = append(importErrs, fmt.Errorf("failed to import template: %s file: %w", templatePath, err))
} else {
// any errors w.r.t customTemplate are warnings and should not be returned to caller
customTemplate, customTemplateErr = tree.ImportYaml(templatePath)
Expand All @@ -119,7 +121,8 @@ nextFile:
if c.Object == "Status_7mode" && model == "cdot" {
return nil, "", errs.New(errs.ErrWrongTemplate, "unable to load status_7.yaml on cdot")
}
return nil, "", fmt.Errorf("no best-fit template for %s on %s", filename, c.Options.ConfPath)
return nil, "", fmt.Errorf("no best-fit template for %s on confPath %s %w",
filename, c.Options.ConfPath, errors.Join(importErrs...))
}
}

Expand Down
7 changes: 4 additions & 3 deletions docs/prepare-fsx-clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ some panels may be missing information.

The dashboards that work with FSx are tagged with `fsx` and listed below:

* ONTAP: cDOT
* ONTAP: Cluster
* ONTAP: Compliance
* ONTAP: Data Protection Snapshots
* ONTAP: Datacenter
* ONTAP: FlexGroup
* ONTAP: LUN
* ONTAP: NFS Troubleshooting
* ONTAP: SVM
* ONTAP: Quota
* ONTAP: Security
* ONTAP: SVM
* ONTAP: Volume
* ONTAP: Volume Deep Dive
* ONTAP: Volume by SVM
* ONTAP: cDOT
* ONTAP: Volume Deep Dive
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.22
require (
github.com/go-openapi/spec v0.21.0
github.com/google/go-cmp v0.6.0
github.com/mattn/go-runewidth v0.0.15
github.com/rivo/uniseg v0.4.7
github.com/rs/zerolog v1.33.0
github.com/shirou/gopsutil/v4 v4.24.6
github.com/spf13/cobra v1.8.1
github.com/tidwall/gjson v1.17.1
github.com/zekroTJA/timedmap/v2 v2.0.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/sys v0.21.0
golang.org/x/term v0.21.0
golang.org/x/exp v0.0.0-20240707233637-46b078467d37
golang.org/x/sys v0.22.0
golang.org/x/term v0.22.0
golang.org/x/text v0.16.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -31,7 +31,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down
Loading

0 comments on commit 596cb0c

Please sign in to comment.