You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by wa...@apache.org on 2023/12/11 12:27:21 UTC

(incubator-pegasus) branch master updated: fix(collector): fix lint and build errors for go collector (#1762)

This is an automated email from the ASF dual-hosted git repository.

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new d85837c2e fix(collector): fix lint and build errors for go collector (#1762)
d85837c2e is described below

commit d85837c2e0c621714ed3bcc16d1794185c3b5193
Author: Dan Wang <wa...@apache.org>
AuthorDate: Mon Dec 11 20:27:15 2023 +0800

    fix(collector): fix lint and build errors for go collector (#1762)
    
    https://github.com/apache/incubator-pegasus/issues/1761
    
    Fix lint and build errors for go collector, including:
    - upgrade go version to 1.17 to fix undefined time.Now().UnixMilli
    - fix format error ("File is not `gofmt`-ed with `-s` (gofmt)") of go source files by `gofmt -s -w
    - fix format string error ("Sprintf/Errorf format %s has arg addr of wrong type int (govet)") by a skipped index for `range`
---
 .github/workflows/lint_and_test_collector.yml |  7 ++--
 collector/avail/detector.go                   |  4 +--
 collector/metrics/metric_collector.go         | 48 +++++++++++++--------------
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/.github/workflows/lint_and_test_collector.yml b/.github/workflows/lint_and_test_collector.yml
index 63909e0ae..98eb13e97 100644
--- a/.github/workflows/lint_and_test_collector.yml
+++ b/.github/workflows/lint_and_test_collector.yml
@@ -29,7 +29,8 @@ on:
       - ci-test # testing branch for github action
       - '*dev'
     paths:
-      - collector/**
+      - '.github/workflows/lint_and_test_collector.yml'
+      - 'collector/**'
 
   # for manually triggering workflow
   workflow_dispatch:
@@ -47,7 +48,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v4
         with:
-          go-version: 1.14
+          go-version: 1.17
           cache: false
       - name: Lint
         uses: golangci/golangci-lint-action@v3
@@ -66,7 +67,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v2
         with:
-          go-version: 1.14
+          go-version: 1.17
       - name: Build
         working-directory: ./collector
         run: make
diff --git a/collector/avail/detector.go b/collector/avail/detector.go
index a4f535394..2b93da9f2 100644
--- a/collector/avail/detector.go
+++ b/collector/avail/detector.go
@@ -91,9 +91,9 @@ type pegasusDetector struct {
 	detectTableName string
 	detectInterval  time.Duration
 	// timeout of a single detect.
-	detectTimeout	time.Duration
+	detectTimeout time.Duration
 	// partition count.
-	partitionCount	int
+	partitionCount int
 }
 
 func (d *pegasusDetector) Start(tom *tomb.Tomb) error {
diff --git a/collector/metrics/metric_collector.go b/collector/metrics/metric_collector.go
index 9dd8e75e9..0c3d1de0b 100644
--- a/collector/metrics/metric_collector.go
+++ b/collector/metrics/metric_collector.go
@@ -102,7 +102,7 @@ func (collector *Collector) Start(tom *tomb.Tomb) error {
 func getReplicaAddrs() ([]string, error) {
 	addrs := viper.GetStringSlice("meta_servers")
 	var rserverAddrs []string
-	for addr := range addrs {
+	for _, addr := range addrs {
 		url := fmt.Sprintf("http://%s/meta/nodes", addr)
 		resp, err := http.Get(url)
 		if err == nil && resp.StatusCode != http.StatusOK {
@@ -291,29 +291,29 @@ func updateClusterLevelTableMetrics(metricsByTableID map[string]Metrics) {
 func updateMetric(metric Metric, endpoint string, level string, title string) {
 	role := RoleByDataSource[DataSource]
 	switch metric.mtype {
-		case "Counter":
-			if counter, ok := CounterMetricsMap[metric.name]; ok {
-				counter.With(
-					prometheus.Labels{"endpoint": endpoint,
-						"role": role, "level": level,
-						"title": title}).Add(float64(metric.value))
-			} else {
-				log.Warnf("Unknown metric name %s", metric.name)
-			}
-		case "Gauge":
-			if gauge, ok := GaugeMetricsMap[metric.name]; ok {
-				gauge.With(
-					prometheus.Labels{"endpoint": endpoint,
-						"role": role, "level": level,
-						"title": title}).Set(float64(metric.value))
-			} else {
-				log.Warnf("Unknown metric name %s", metric.name)
-			}
-		case "Percentile":
-			log.Warnf("Todo metric type %s", metric.mtype)
-		case "Histogram":
-		default:
-			log.Warnf("Unsupport metric type %s", metric.mtype)
+	case "Counter":
+		if counter, ok := CounterMetricsMap[metric.name]; ok {
+			counter.With(
+				prometheus.Labels{"endpoint": endpoint,
+					"role": role, "level": level,
+					"title": title}).Add(float64(metric.value))
+		} else {
+			log.Warnf("Unknown metric name %s", metric.name)
+		}
+	case "Gauge":
+		if gauge, ok := GaugeMetricsMap[metric.name]; ok {
+			gauge.With(
+				prometheus.Labels{"endpoint": endpoint,
+					"role": role, "level": level,
+					"title": title}).Set(float64(metric.value))
+		} else {
+			log.Warnf("Unknown metric name %s", metric.name)
+		}
+	case "Percentile":
+		log.Warnf("Todo metric type %s", metric.mtype)
+	case "Histogram":
+	default:
+		log.Warnf("Unsupport metric type %s", metric.mtype)
 	}
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org