Repository: NetApp/harvest
Pull request #1769 (2023-02-23 13:20:42)

feat: enable golanglint "unparam" linter


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 54b77aab..1bef6a41 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -22,6 +22,7 @@ linters:
     - thelper
     - typecheck
     - unconvert
+    - unparam
     - unused
 
 issues:
diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go
index 0cd453e3..8066bfa2 100644
--- a/cmd/collectors/rest/rest.go
+++ b/cmd/collectors/rest/rest.go
@@ -302,11 +302,8 @@ func (r *Rest) PollData() (map[string]*matrix.Matrix, error) {
 	count = r.HandleResults(records, r.Prop, false)
 
 	// process endpoints
-	eCount, err := r.processEndPoints()
+	eCount := r.processEndPoints()
 	count += eCount
-	if err != nil {
-		r.Logger.Error().Err(err).Msg("Error while processing end points")
-	}
 	parseD = time.Since(startTime)
 
 	numRecords := len(r.Matrix[r.Object].GetInstances())
@@ -320,7 +317,7 @@ func (r *Rest) PollData() (map[string]*matrix.Matrix, error) {
 	return r.Matrix, nil
 }
 
-func (r *Rest) processEndPoints() (uint64, error) {
+func (r *Rest) processEndPoints() uint64 {
 	var (
 		err   error
 		count uint64
@@ -353,7 +350,7 @@ func (r *Rest) processEndPoints() (uint64, error) {
 		count = r.HandleResults(records, endpoint.prop, true)
 	}
 
-	return count, nil
+	return count
 }
 
 // returns private if api endpoint has private keyword in it else public
diff --git a/cmd/collectors/restperf/plugins/disk/disk.go b/cmd/collectors/restperf/plugins/disk/disk.go
index 7f76338a..407d542d 100644
--- a/cmd/collectors/restperf/plugins/disk/disk.go
+++ b/cmd/collectors/restperf/plugins/disk/disk.go
@@ -704,10 +704,7 @@ func (d *Disk) handleShelfPower(shelves []gjson.Result, output []*matrix.Matrix)
 		instance.SetLabel("shelfID", shelfID)
 		instance.SetLabel("shelfUID", shelfUID)
 	}
-	err := d.calculateEnvironmentMetrics(data)
-	if err != nil {
-		return output, err
-	}
+	d.calculateEnvironmentMetrics(data)
 
 	output = append(output, data)
 	return output, nil
@@ -748,7 +745,7 @@ func (d *Disk) initMaps() {
 	d.aggrMap = make(map[string]*aggregate)
 }
 
-func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) error {
+func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) {
 	var err error
 	shelfEnvironmentMetricMap := make(map[string]*shelfEnvironmentMetric, 0)
 	for _, o := range d.shelfData {
@@ -894,5 +891,4 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) error {
 			}
 		}
 	}
-	return nil
 }
diff --git a/cmd/collectors/zapiperf/plugins/disk/disk.go b/cmd/collectors/zapiperf/plugins/disk/disk.go
index 461b9149..0ba548c6 100644
--- a/cmd/collectors/zapiperf/plugins/disk/disk.go
+++ b/cmd/collectors/zapiperf/plugins/disk/disk.go
@@ -654,16 +654,13 @@ func (d *Disk) handleShelfPower(shelves []*node.Node, output []*matrix.Matrix) (
 		instance.SetLabel("shelf", shelfName)
 		instance.SetLabel("shelfID", shelfID)
 	}
-	err := d.calculateEnvironmentMetrics(data)
-	if err != nil {
-		return output, err
-	}
+	d.calculateEnvironmentMetrics(data)
 
 	output = append(output, data)
 	return output, nil
 }
 
-func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) error {
+func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) {
 	var err error
 	shelfEnvironmentMetricMap := make(map[string]*shelfEnvironmentMetric, 0)
 	for _, o := range d.shelfData {
@@ -802,7 +799,6 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) error {
 			}
 		}
 	}
-	return nil
 }
 
 func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) {
diff --git a/cmd/exporters/prometheus/httpd.go b/cmd/exporters/prometheus/httpd.go
index 86013b6f..f09174f2 100644
--- a/cmd/exporters/prometheus/httpd.go
+++ b/cmd/exporters/prometheus/httpd.go
@@ -106,12 +106,9 @@ func (p *Prometheus) ServeMetrics(w http.ResponseWriter, r *http.Request) {
 
 	// serve our own metadata
 	// notice that some values are always taken from previous session
-	if md, err := p.render(p.Metadata); err == nil {
-		data = append(data, md...)
-		count += len(md)
-	} else {
-		p.Logger.Error().Stack().Err(err).Msg("(httpd) render metadata")
-	}
+	md := p.render(p.Metadata)
+	data = append(data, md...)
+	count += len(md)
 	/*
 
 		e.Metadata.SetValueSS("count", "render", float64(count))
diff --git a/cmd/exporters/prometheus/prometheus.go b/cmd/exporters/prometheus/prometheus.go
index 625f8a67..55ac0b01 100644
--- a/cmd/exporters/prometheus/prometheus.go
+++ b/cmd/exporters/prometheus/prometheus.go
@@ -212,9 +212,8 @@ func (p *Prometheus) Export(data *matrix.Matrix) error {
 
 	// render metrics into Prometheus format
 	start := time.Now()
-	if metrics, err = p.render(data); err != nil {
-		return err
-	}
+	metrics = p.render(data)
+
 	// fix render time for metadata
 	d := time.Since(start)
 
@@ -266,7 +265,7 @@ func (p *Prometheus) Export(data *matrix.Matrix) error {
 // volume_read_ops{node="my-node",vol="some_vol"} 2523
 // fcp_lif_read_ops{vserver="nas_svm",port_id="e02"} 771
 
-func (p *Prometheus) render(data *matrix.Matrix) ([][]byte, error) {
+func (p *Prometheus) render(data *matrix.Matrix) [][]byte {
 	var (
 		rendered         [][]byte
 		tagged           *set.Set
@@ -556,7 +555,7 @@ func (p *Prometheus) render(data *matrix.Matrix) ([][]byte, error) {
 		Int("rendered", len(rendered)).
 		Int("instances", len(data.GetInstances())).
 		Msg("Rendered data points for instances")
-	return rendered, nil
+	return rendered
 }
 
 var numAndUnitRe = regexp.MustCompile(`(\d+)\s*(\w+)`)
diff --git a/cmd/tools/grafana/grafana.go b/cmd/tools/grafana/grafana.go
index 897b1db7..75fe237a 100644
--- a/cmd/tools/grafana/grafana.go
+++ b/cmd/tools/grafana/grafana.go
@@ -336,10 +336,7 @@ func doImport(_ *cobra.Command, _ []string) {
 	initImportVars()
 
 	fmt.Printf("preparing to import dashboards...\n")
-	if err := importDashboards(opts); err != nil {
-		fmt.Println(err)
-		os.Exit(1)
-	}
+	importDashboards(opts)
 }
 
 func validateImport() {
@@ -414,11 +411,10 @@ func exitIfExist(fp string, s string) {
 	}
 }
 
-func importDashboards(opts *options) error {
+func importDashboards(opts *options) {
 	for k, v := range opts.dirGrafanaFolderMap {
 		importFiles(k, v)
 	}
-	return nil
 }
 
 func importFiles(dir string, folder *Folder) {


Test patch:
diff --git a/cmd/tools/grafana/dashboard_test.go b/cmd/tools/grafana/dashboard_test.go
index e810692c..cba0d252 100644
--- a/cmd/tools/grafana/dashboard_test.go
+++ b/cmd/tools/grafana/dashboard_test.go
@@ -184,10 +184,10 @@ var metricDivideMetric2 = regexp.MustCompile(`(\w+)/.*?(\w+){`)
 // detects arrays
 var metricWithArray = regexp.MustCompile(`metric=~*"(.*?)"`)
 
-func doPanel(t *testing.T, pathPrefix string, key gjson.Result, value gjson.Result, mt *metricsTable, dashboardPath string) bool {
+func doPanel(t *testing.T, pathPrefix string, key gjson.Result, value gjson.Result, mt *metricsTable, dashboardPath string) {
 	kind := value.Get("type").String()
 	if kind == "row" {
-		return true
+		return
 	}
 	path := fmt.Sprintf("%spanels[%d]", pathPrefix, key.Int())
 	defaultUnit := value.Get("fieldConfig.defaults.unit").String()
@@ -298,7 +298,6 @@ func doPanel(t *testing.T, pathPrefix string, key gjson.Result, value gjson.Resu
 		unit := unitForExpr(e, overrides, defaultUnit, valueToName, numExpressions)
 		mt.addMetric(e.metric, unit, path, sPath, title)
 	}
-	return true
 }
 
 func unitForExpr(e expression, overrides []override, defaultUnit string,