Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
path: internal/webui/build

- name: GolangCI-Lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: v1.64
version: latest

test:
if: true # false to skip job during debug
Expand Down
46 changes: 30 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
version: "2"
linters:
enable:
- misspell
- revive
- misspell
disable:
- gocyclo


linters-settings:
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently of this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- SA1019 # CPUTimesStat.Total is deprecated
- SA5008 # duplicate struct tag "choice" (staticcheck)
settings:
gocyclo:
min-complexity: 20
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- path: (.+)\.go$
text: SA1019 # CPUTimesStat.Total is deprecated
- path: (.+)\.go$
text: SA5008 # duplicate struct tag "choice" (staticcheck)
- path: (.+)\.go$
text: QF1001 # could apply De Morgan's law
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion internal/reaper/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetMonitoredDatabaseByUniqueName(name string) (*sources.SourceConn, error)
defer monitoredDbCacheLock.RUnlock()
md, exists := monitoredDbCache[name]
if !exists || md == nil {
return nil, fmt.Errorf("Database %s not found in cache", name)
return nil, fmt.Errorf("database %s not found in cache", name)
}
return md, nil
}
Expand Down
11 changes: 6 additions & 5 deletions internal/reaper/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func GetMonitoredDatabaseSettings(ctx context.Context, md *sources.SourceConn, n
}
matches := rBouncerAndPgpoolVerMatch.FindStringSubmatch(dbNewSettings.VersionStr)
if len(matches) != 1 {
return dbSettings, fmt.Errorf("Unexpected PgBouncer version input: %s", dbNewSettings.VersionStr)
return dbSettings, fmt.Errorf("unexpected PgBouncer version input: %s", dbNewSettings.VersionStr)
}
dbNewSettings.Version = VersionToInt(matches[0])
case sources.SourcePgPool:
Expand All @@ -164,7 +164,7 @@ func GetMonitoredDatabaseSettings(ctx context.Context, md *sources.SourceConn, n

matches := rBouncerAndPgpoolVerMatch.FindStringSubmatch(dbNewSettings.VersionStr)
if len(matches) != 1 {
return dbSettings, fmt.Errorf("Unexpected PgPool version input: %s", dbNewSettings.VersionStr)
return dbSettings, fmt.Errorf("unexpected PgPool version input: %s", dbNewSettings.VersionStr)
}
dbNewSettings.Version = VersionToInt(matches[0])
default:
Expand Down Expand Up @@ -708,11 +708,12 @@ func FetchMetricsPgpool(ctx context.Context, msg MetricFetchConfig, vme Monitore
retRow[k] = vs
if k == "status" { // was changed from numeric to string at some pgpool version so leave the string
// but also add "status_num" field
if vs == "up" {
switch vs {
case "up":
retRow["status_num"] = 1
} else if vs == "down" {
case "down":
retRow["status_num"] = 0
} else {
default:
i, err := strconv.ParseInt(vs, 10, 64)
if err == nil {
retRow["status_num"] = i
Expand Down
7 changes: 5 additions & 2 deletions internal/sinks/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {

rowsBatched++

if pgw.metricSchema == DbStorageSchemaTimescale {
switch pgw.metricSchema {
case DbStorageSchemaTimescale:
// set min/max timestamps to check/create partitions
bounds, ok := pgPartBounds[msg.MetricName]
if !ok || (ok && epochTime.Before(bounds.StartTime)) {
Expand All @@ -306,7 +307,7 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {
bounds.EndTime = epochTime
pgPartBounds[msg.MetricName] = bounds
}
} else if pgw.metricSchema == DbStorageSchemaPostgres {
case DbStorageSchemaPostgres:
_, ok := pgPartBoundsDbName[msg.MetricName]
if !ok {
pgPartBoundsDbName[msg.MetricName] = make(map[string]ExistingPartitionInfo)
Expand All @@ -320,6 +321,8 @@ func (pgw *PostgresWriter) flush(msgs []metrics.MeasurementEnvelope) {
bounds.EndTime = epochTime
pgPartBoundsDbName[msg.MetricName][msg.DBName] = bounds
}
default:
logger.Fatal("unknown storage schema...")
}
}
}
Expand Down
19 changes: 7 additions & 12 deletions internal/sinks/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net"
"net/http"
"reflect"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -230,21 +229,17 @@ func (promw *PrometheusWriter) MetricStoreMessageToPromMetrics(msg metrics.Measu
tag := k[4:]
labels[tag] = fmt.Sprintf("%v", v)
} else {
dataType := reflect.TypeOf(v).String()
if dataType == "float64" || dataType == "float32" || dataType == "int64" || dataType == "int32" || dataType == "int" {
switch t := v.(type) {
case int, int32, int64, float32, float64:
f, err := strconv.ParseFloat(fmt.Sprintf("%v", v), 64)
if err != nil {
logger.Debugf("Skipping scraping column %s of [%s:%s]: %v", k, msg.DBName, msg.MetricName, err)
logger.Debugf("skipping scraping column %s of [%s:%s]: %v", k, msg.DBName, msg.MetricName, err)
}
fields[k] = f
} else if dataType == "bool" {
if v.(bool) {
fields[k] = 1
} else {
fields[k] = 0
}
} else {
logger.Debugf("Skipping scraping column %s of [%s:%s], unsupported datatype: %s", k, msg.DBName, msg.MetricName, dataType)
case bool:
fields[k] = map[bool]float64{true: 1, false: 0}[t]
default:
logger.Debugf("skipping scraping column %s of [%s:%s], unsupported datatype: %v", k, msg.DBName, msg.MetricName, t)
continue
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/sources/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func getEtcdClusterMembers(s Source) ([]PatroniClusterMember, error) {
var cfg client.Config

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

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

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