Skip to content

Commit

Permalink
fix(collector): fix lint and build errors for go collector (#1762)
Browse files Browse the repository at this point in the history
#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`
  • Loading branch information
empiredan authored Dec 11, 2023
1 parent 4dd2b7a commit d85837c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/lint_and_test_collector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions collector/avail/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 24 additions & 24 deletions collector/metrics/metric_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit d85837c

Please sign in to comment.