mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-04-18 12:24:07 +03:00
Update Go (#1147)
* Update Go to 1.24. * Update golangci-lint to v2. * Fixup linting issues. Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
9e86f1ee38
commit
8d5ec4b3ea
@ -8,7 +8,7 @@ executors:
|
|||||||
# This must match .promu.yml.
|
# This must match .promu.yml.
|
||||||
golang:
|
golang:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/go:1.23
|
- image: cimg/go:1.24
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@ -23,7 +23,7 @@ jobs:
|
|||||||
|
|
||||||
integration:
|
integration:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/go:1.23
|
- image: cimg/go:1.24
|
||||||
- image: << parameters.postgres_image >>
|
- image: << parameters.postgres_image >>
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: circle_test
|
POSTGRES_DB: circle_test
|
||||||
|
4
.github/workflows/golangci-lint.yml
vendored
4
.github/workflows/golangci-lint.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
||||||
if: github.repository == 'prometheus/snmp_exporter'
|
if: github.repository == 'prometheus/snmp_exporter'
|
||||||
- name: Lint
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
|
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
|
||||||
with:
|
with:
|
||||||
args: --verbose
|
args: --verbose
|
||||||
version: v1.64.6
|
version: v2.0.2
|
||||||
|
@ -1,23 +1,36 @@
|
|||||||
---
|
version: "2"
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- misspell
|
- misspell
|
||||||
- revive
|
- revive
|
||||||
|
settings:
|
||||||
issues:
|
errcheck:
|
||||||
exclude-rules:
|
exclude-functions:
|
||||||
- path: _test.go
|
- (github.com/go-kit/log.Logger).Log
|
||||||
linters:
|
revive:
|
||||||
- errcheck
|
rules:
|
||||||
|
- name: unused-parameter
|
||||||
linters-settings:
|
severity: warning
|
||||||
errcheck:
|
disabled: true
|
||||||
exclude-functions:
|
exclusions:
|
||||||
# Never check for logger errors.
|
generated: lax
|
||||||
- (github.com/go-kit/log.Logger).Log
|
presets:
|
||||||
revive:
|
- comments
|
||||||
|
- common-false-positives
|
||||||
|
- legacy
|
||||||
|
- std-error-handling
|
||||||
rules:
|
rules:
|
||||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
|
- linters:
|
||||||
- name: unused-parameter
|
- errcheck
|
||||||
severity: warning
|
path: _test.go
|
||||||
disabled: true
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
formatters:
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
go:
|
go:
|
||||||
# This must match .circle/config.yml.
|
# This must match .circle/config.yml.
|
||||||
version: 1.23
|
version: 1.24
|
||||||
repository:
|
repository:
|
||||||
path: github.com/prometheus-community/postgres_exporter
|
path: github.com/prometheus-community/postgres_exporter
|
||||||
build:
|
build:
|
||||||
|
@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
|
|||||||
SKIP_GOLANGCI_LINT :=
|
SKIP_GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT :=
|
GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT_OPTS ?=
|
GOLANGCI_LINT_OPTS ?=
|
||||||
GOLANGCI_LINT_VERSION ?= v1.64.6
|
GOLANGCI_LINT_VERSION ?= v2.0.2
|
||||||
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
|
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
|
||||||
# windows isn't included here because of the path separator being different.
|
# windows isn't included here because of the path separator being different.
|
||||||
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
||||||
|
@ -67,7 +67,7 @@ type pgSetting struct {
|
|||||||
func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
|
func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
name = strings.Replace(strings.Replace(s.name, ".", "_", -1), "-", "_", -1)
|
name = strings.ReplaceAll(strings.ReplaceAll(s.name, ".", "_"), "-", "_")
|
||||||
unit = s.unit // nolint: ineffassign
|
unit = s.unit // nolint: ineffassign
|
||||||
shortDesc = fmt.Sprintf("Server Parameter: %s", s.name)
|
shortDesc = fmt.Sprintf("Server Parameter: %s", s.name)
|
||||||
subsystem = "settings"
|
subsystem = "settings"
|
||||||
@ -131,7 +131,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
|
|||||||
case "B", "kB", "MB", "GB", "TB", "1kB", "2kB", "4kB", "8kB", "16kB", "32kB", "64kB", "16MB", "32MB", "64MB":
|
case "B", "kB", "MB", "GB", "TB", "1kB", "2kB", "4kB", "8kB", "16kB", "32kB", "64kB", "16MB", "32MB", "64MB":
|
||||||
unit = "bytes"
|
unit = "bytes"
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
|
err = fmt.Errorf("unknown unit for runtime variable: %q", s.unit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ var fixtures = []fixture{
|
|||||||
n: normalised{
|
n: normalised{
|
||||||
val: 10,
|
val: 10,
|
||||||
unit: "",
|
unit: "",
|
||||||
err: `Unknown unit for runtime variable: "nonexistent"`,
|
err: `unknown unit for runtime variable: "nonexistent"`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ func (s *PgSettingSuite) TestNormaliseUnit(c *C) {
|
|||||||
func (s *PgSettingSuite) TestMetric(c *C) {
|
func (s *PgSettingSuite) TestMetric(c *C) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
if r.(error).Error() != `Unknown unit for runtime variable: "nonexistent"` {
|
if r.(error).Error() != `unknown unit for runtime variable: "nonexistent"` {
|
||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,15 +48,15 @@ func readMetric(m prometheus.Metric) MetricResult {
|
|||||||
|
|
||||||
func sanitizeQuery(q string) string {
|
func sanitizeQuery(q string) string {
|
||||||
q = strings.Join(strings.Fields(q), " ")
|
q = strings.Join(strings.Fields(q), " ")
|
||||||
q = strings.Replace(q, "(", "\\(", -1)
|
q = strings.ReplaceAll(q, "(", "\\(")
|
||||||
q = strings.Replace(q, "?", "\\?", -1)
|
q = strings.ReplaceAll(q, "?", "\\?")
|
||||||
q = strings.Replace(q, ")", "\\)", -1)
|
q = strings.ReplaceAll(q, ")", "\\)")
|
||||||
q = strings.Replace(q, "[", "\\[", -1)
|
q = strings.ReplaceAll(q, "[", "\\[")
|
||||||
q = strings.Replace(q, "]", "\\]", -1)
|
q = strings.ReplaceAll(q, "]", "\\]")
|
||||||
q = strings.Replace(q, "{", "\\{", -1)
|
q = strings.ReplaceAll(q, "{", "\\{")
|
||||||
q = strings.Replace(q, "}", "\\}", -1)
|
q = strings.ReplaceAll(q, "}", "\\}")
|
||||||
q = strings.Replace(q, "*", "\\*", -1)
|
q = strings.ReplaceAll(q, "*", "\\*")
|
||||||
q = strings.Replace(q, "^", "\\^", -1)
|
q = strings.ReplaceAll(q, "^", "\\^")
|
||||||
q = strings.Replace(q, "$", "\\$", -1)
|
q = strings.ReplaceAll(q, "$", "\\$")
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
@ -79,14 +79,14 @@ func (ch *Handler) ReloadConfig(f string, logger *slog.Logger) error {
|
|||||||
|
|
||||||
yamlReader, err := os.Open(f)
|
yamlReader, err := os.Open(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error opening config file %q: %s", f, err)
|
return fmt.Errorf("error opening config file %q: %s", f, err)
|
||||||
}
|
}
|
||||||
defer yamlReader.Close()
|
defer yamlReader.Close()
|
||||||
decoder := yaml.NewDecoder(yamlReader)
|
decoder := yaml.NewDecoder(yamlReader)
|
||||||
decoder.KnownFields(true)
|
decoder.KnownFields(true)
|
||||||
|
|
||||||
if err = decoder.Decode(config); err != nil {
|
if err = decoder.Decode(config); err != nil {
|
||||||
return fmt.Errorf("Error parsing config file %q: %s", f, err)
|
return fmt.Errorf("error parsing config file %q: %s", f, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.Lock()
|
ch.Lock()
|
||||||
|
@ -24,7 +24,7 @@ func TestLoadConfig(t *testing.T) {
|
|||||||
|
|
||||||
err := ch.ReloadConfig("testdata/config-good.yaml", nil)
|
err := ch.ReloadConfig("testdata/config-good.yaml", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error loading config: %s", err)
|
t.Errorf("error loading config: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +39,11 @@ func TestLoadBadConfigs(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
input: "testdata/config-bad-auth-module.yaml",
|
input: "testdata/config-bad-auth-module.yaml",
|
||||||
want: "Error parsing config file \"testdata/config-bad-auth-module.yaml\": yaml: unmarshal errors:\n line 3: field pretendauth not found in type config.AuthModule",
|
want: "error parsing config file \"testdata/config-bad-auth-module.yaml\": yaml: unmarshal errors:\n line 3: field pretendauth not found in type config.AuthModule",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "testdata/config-bad-extra-field.yaml",
|
input: "testdata/config-bad-extra-field.yaml",
|
||||||
want: "Error parsing config file \"testdata/config-bad-extra-field.yaml\": yaml: unmarshal errors:\n line 8: field doesNotExist not found in type config.AuthModule",
|
want: "error parsing config file \"testdata/config-bad-extra-field.yaml\": yaml: unmarshal errors:\n line 8: field doesNotExist not found in type config.AuthModule",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user