Skip to content

Commit 549dce0

Browse files
[+] bump golangci/golangci-lint-action from 6 to 7 (#690)
* Bump golangci/golangci-lint-action from 6 to 7 Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 7. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](golangci/golangci-lint-action@v6...v7) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * migrate .golangci.yml to v2 * fix ST105: capitalized error messages * rewrite complex ifs with switch * use latest version of golangci/golangci-lint-action --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pavlo Golub <pavlo.golub@gmail.com>
1 parent 693d61d commit 549dce0

File tree

7 files changed

+54
-41
lines changed

7 files changed

+54
-41
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454
path: internal/webui/build
5555

5656
- name: GolangCI-Lint
57-
uses: golangci/golangci-lint-action@v6
57+
uses: golangci/golangci-lint-action@v7
5858
with:
59-
version: v1.64
59+
version: latest
6060

6161
test:
6262
if: true # false to skip job during debug

.golangci.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
version: "2"
12
linters:
23
enable:
4+
- misspell
35
- revive
4-
- misspell
56
disable:
67
- gocyclo
7-
8-
9-
linters-settings:
10-
gocyclo:
11-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
12-
min-complexity: 20
13-
14-
issues:
15-
# List of regexps of issue texts to exclude, empty list by default.
16-
# But independently of this option we use default exclude patterns,
17-
# it can be disabled by `exclude-use-default: false`. To list all
18-
# excluded by default patterns execute `golangci-lint run --help`
19-
exclude:
20-
- SA1019 # CPUTimesStat.Total is deprecated
21-
- SA5008 # duplicate struct tag "choice" (staticcheck)
8+
settings:
9+
gocyclo:
10+
min-complexity: 20
11+
exclusions:
12+
generated: lax
13+
presets:
14+
- comments
15+
- common-false-positives
16+
- legacy
17+
- std-error-handling
18+
rules:
19+
- path: (.+)\.go$
20+
text: SA1019 # CPUTimesStat.Total is deprecated
21+
- path: (.+)\.go$
22+
text: SA5008 # duplicate struct tag "choice" (staticcheck)
23+
- path: (.+)\.go$
24+
text: QF1001 # could apply De Morgan's law
25+
paths:
26+
- third_party$
27+
- builtin$
28+
- examples$
29+
formatters:
30+
exclusions:
31+
generated: lax
32+
paths:
33+
- third_party$
34+
- builtin$
35+
- examples$

internal/reaper/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func GetMonitoredDatabaseByUniqueName(name string) (*sources.SourceConn, error)
4949
defer monitoredDbCacheLock.RUnlock()
5050
md, exists := monitoredDbCache[name]
5151
if !exists || md == nil {
52-
return nil, fmt.Errorf("Database %s not found in cache", name)
52+
return nil, fmt.Errorf("database %s not found in cache", name)
5353
}
5454
return md, nil
5555
}

internal/reaper/database.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func GetMonitoredDatabaseSettings(ctx context.Context, md *sources.SourceConn, n
154154
}
155155
matches := rBouncerAndPgpoolVerMatch.FindStringSubmatch(dbNewSettings.VersionStr)
156156
if len(matches) != 1 {
157-
return dbSettings, fmt.Errorf("Unexpected PgBouncer version input: %s", dbNewSettings.VersionStr)
157+
return dbSettings, fmt.Errorf("unexpected PgBouncer version input: %s", dbNewSettings.VersionStr)
158158
}
159159
dbNewSettings.Version = VersionToInt(matches[0])
160160
case sources.SourcePgPool:
@@ -164,7 +164,7 @@ func GetMonitoredDatabaseSettings(ctx context.Context, md *sources.SourceConn, n
164164

165165
matches := rBouncerAndPgpoolVerMatch.FindStringSubmatch(dbNewSettings.VersionStr)
166166
if len(matches) != 1 {
167-
return dbSettings, fmt.Errorf("Unexpected PgPool version input: %s", dbNewSettings.VersionStr)
167+
return dbSettings, fmt.Errorf("unexpected PgPool version input: %s", dbNewSettings.VersionStr)
168168
}
169169
dbNewSettings.Version = VersionToInt(matches[0])
170170
default:
@@ -708,11 +708,12 @@ func FetchMetricsPgpool(ctx context.Context, msg MetricFetchConfig, vme Monitore
708708
retRow[k] = vs
709709
if k == "status" { // was changed from numeric to string at some pgpool version so leave the string
710710
// but also add "status_num" field
711-
if vs == "up" {
711+
switch vs {
712+
case "up":
712713
retRow["status_num"] = 1
713-
} else if vs == "down" {
714+
case "down":
714715
retRow["status_num"] = 0
715-
} else {
716+
default:
716717
i, err := strconv.ParseInt(vs, 10, 64)
717718
if err == nil {
718719
retRow["status_num"] = i

internal/sinks/postgres.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {
295295

296296
rowsBatched++
297297

298-
if pgw.metricSchema == DbStorageSchemaTimescale {
298+
switch pgw.metricSchema {
299+
case DbStorageSchemaTimescale:
299300
// set min/max timestamps to check/create partitions
300301
bounds, ok := pgPartBounds[msg.MetricName]
301302
if !ok || (ok && epochTime.Before(bounds.StartTime)) {
@@ -306,7 +307,7 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {
306307
bounds.EndTime = epochTime
307308
pgPartBounds[msg.MetricName] = bounds
308309
}
309-
} else if pgw.metricSchema == DbStorageSchemaPostgres {
310+
case DbStorageSchemaPostgres:
310311
_, ok := pgPartBoundsDbName[msg.MetricName]
311312
if !ok {
312313
pgPartBoundsDbName[msg.MetricName] = make(map[string]ExistingPartitionInfo)
@@ -320,6 +321,8 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {
320321
bounds.EndTime = epochTime
321322
pgPartBoundsDbName[msg.MetricName][msg.DBName] = bounds
322323
}
324+
default:
325+
logger.Fatal("unknown storage schema...")
323326
}
324327
}
325328
}

internal/sinks/prometheus.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"net"
77
"net/http"
8-
"reflect"
98
"slices"
109
"strconv"
1110
"strings"
@@ -230,21 +229,17 @@ func (promw *PrometheusWriter) MetricStoreMessageToPromMetrics(msg metrics.Measu
230229
tag := k[4:]
231230
labels[tag] = fmt.Sprintf("%v", v)
232231
} else {
233-
dataType := reflect.TypeOf(v).String()
234-
if dataType == "float64" || dataType == "float32" || dataType == "int64" || dataType == "int32" || dataType == "int" {
232+
switch t := v.(type) {
233+
case int, int32, int64, float32, float64:
235234
f, err := strconv.ParseFloat(fmt.Sprintf("%v", v), 64)
236235
if err != nil {
237-
logger.Debugf("Skipping scraping column %s of [%s:%s]: %v", k, msg.DBName, msg.MetricName, err)
236+
logger.Debugf("skipping scraping column %s of [%s:%s]: %v", k, msg.DBName, msg.MetricName, err)
238237
}
239238
fields[k] = f
240-
} else if dataType == "bool" {
241-
if v.(bool) {
242-
fields[k] = 1
243-
} else {
244-
fields[k] = 0
245-
}
246-
} else {
247-
logger.Debugf("Skipping scraping column %s of [%s:%s], unsupported datatype: %s", k, msg.DBName, msg.MetricName, dataType)
239+
case bool:
240+
fields[k] = map[bool]float64{true: 1, false: 0}[t]
241+
default:
242+
logger.Debugf("skipping scraping column %s of [%s:%s], unsupported datatype: %v", k, msg.DBName, msg.MetricName, t)
248243
continue
249244
}
250245
}

internal/sources/resolver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func getEtcdClusterMembers(s Source) ([]PatroniClusterMember, error) {
139139
var cfg client.Config
140140

141141
if len(s.HostConfig.DcsEndpoints) == 0 {
142-
return ret, errors.New("Missing ETCD connect info, make sure host config has a 'dcs_endpoints' key")
142+
return ret, errors.New("missing ETCD connect info, make sure host config has a 'dcs_endpoints' key")
143143
}
144144

145145
tlsConfig, err := getTransport(s.HostConfig)
@@ -168,10 +168,10 @@ func getEtcdClusterMembers(s Source) ([]PatroniClusterMember, error) {
168168

169169
if s.Kind == SourcePatroniNamespace { // all scopes, all DBs (regex filtering applies if defined)
170170
if len(s.GetDatabaseName()) > 0 {
171-
return ret, fmt.Errorf("Skipping Patroni entry %s - cannot specify a DB name when monitoring all scopes (regex patterns are supported though)", s.Name)
171+
return ret, fmt.Errorf("skipping Patroni entry %s - cannot specify a DB name when monitoring all scopes (regex patterns are supported though)", s.Name)
172172
}
173173
if s.HostConfig.Namespace == "" {
174-
return ret, fmt.Errorf("Skipping Patroni entry %s - search 'namespace' not specified", s.Name)
174+
return ret, fmt.Errorf("skipping Patroni entry %s - search 'namespace' not specified", s.Name)
175175
}
176176
resp, err := kapi.Get(ctx, s.HostConfig.Namespace, client.WithPrefix(), client.WithKeysOnly())
177177
if err != nil {

0 commit comments

Comments
 (0)