Skip to content

Commit 1626b2d

Browse files
committed
Merge remote-tracking branch 'prometheus/main' into add-unit
Signed-off-by: Arianna Vespri <[email protected]>
2 parents df66a89 + 7e44242 commit 1626b2d

40 files changed

+539
-416
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ on:
1212
- ".golangci.yml"
1313
pull_request:
1414

15+
permissions: # added using https://github.com/step-security/secure-repo
16+
contents: read
17+
1518
jobs:
1619
golangci:
20+
permissions:
21+
contents: read # for actions/checkout to fetch code
22+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
1723
name: lint
1824
runs-on: ubuntu-latest
1925
steps:
2026
- name: Checkout repository
2127
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2228
- name: install Go
23-
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
29+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
2430
with:
2531
go-version: 1.21.x
2632
- name: Install snmp_exporter/generator dependencies
@@ -29,4 +35,4 @@ jobs:
2935
- name: Lint
3036
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
3137
with:
32-
version: v1.54.2
38+
version: v1.55.2

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
linters:
22
enable:
3+
- errorlint
4+
- gofumpt
5+
- goimports
36
- misspell
47
- revive
8+
- testifylint
59

610
issues:
711
exclude-rules:
812
- path: _test.go
913
linters:
1014
- errcheck
15+
max-issues-per-linter: 0
16+
max-same-issues: 0
1117

1218
linters-settings:
19+
goimports:
20+
local-prefixes: github.com/prometheus/common
1321
revive:
1422
rules:
1523
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
1624
- name: unused-parameter
1725
severity: warning
1826
disabled: true
27+
testifylint:
28+
disable:
29+
- float-compare
30+
- go-require
31+
enable:
32+
- bool-compare
33+
- compares
34+
- empty
35+
- error-is-as
36+
- error-nil
37+
- expected-actual
38+
- len
39+
- require-error
40+
- suite-dont-use-pkg
41+
- suite-extra-assert-call

Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.54.2
64+
GOLANGCI_LINT_VERSION ?= v1.55.2
6565
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
6666
# windows isn't included here because of the path separator being different.
6767
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

config/http_config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,10 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
546546

547547
// If a authorization_credentials is provided, create a round tripper that will set the
548548
// Authorization header correctly on each request.
549-
if cfg.Authorization != nil && len(cfg.Authorization.Credentials) > 0 {
550-
rt = NewAuthorizationCredentialsRoundTripper(cfg.Authorization.Type, cfg.Authorization.Credentials, rt)
551-
} else if cfg.Authorization != nil && len(cfg.Authorization.CredentialsFile) > 0 {
549+
if cfg.Authorization != nil && len(cfg.Authorization.CredentialsFile) > 0 {
552550
rt = NewAuthorizationCredentialsFileRoundTripper(cfg.Authorization.Type, cfg.Authorization.CredentialsFile, rt)
551+
} else if cfg.Authorization != nil {
552+
rt = NewAuthorizationCredentialsRoundTripper(cfg.Authorization.Type, cfg.Authorization.Credentials, rt)
553553
}
554554
// Backwards compatibility, be nice with importers who would not have
555555
// called Validate().
@@ -630,7 +630,7 @@ func (rt *authorizationCredentialsFileRoundTripper) RoundTrip(req *http.Request)
630630
if len(req.Header.Get("Authorization")) == 0 {
631631
b, err := os.ReadFile(rt.authCredentialsFile)
632632
if err != nil {
633-
return nil, fmt.Errorf("unable to read authorization credentials file %s: %s", rt.authCredentialsFile, err)
633+
return nil, fmt.Errorf("unable to read authorization credentials file %s: %w", rt.authCredentialsFile, err)
634634
}
635635
authCredentials := strings.TrimSpace(string(b))
636636

@@ -670,7 +670,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
670670
if rt.usernameFile != "" {
671671
usernameBytes, err := os.ReadFile(rt.usernameFile)
672672
if err != nil {
673-
return nil, fmt.Errorf("unable to read basic auth username file %s: %s", rt.usernameFile, err)
673+
return nil, fmt.Errorf("unable to read basic auth username file %s: %w", rt.usernameFile, err)
674674
}
675675
username = strings.TrimSpace(string(usernameBytes))
676676
} else {
@@ -679,7 +679,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
679679
if rt.passwordFile != "" {
680680
passwordBytes, err := os.ReadFile(rt.passwordFile)
681681
if err != nil {
682-
return nil, fmt.Errorf("unable to read basic auth password file %s: %s", rt.passwordFile, err)
682+
return nil, fmt.Errorf("unable to read basic auth password file %s: %w", rt.passwordFile, err)
683683
}
684684
password = strings.TrimSpace(string(passwordBytes))
685685
} else {
@@ -723,7 +723,7 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
723723
if rt.config.ClientSecretFile != "" {
724724
data, err := os.ReadFile(rt.config.ClientSecretFile)
725725
if err != nil {
726-
return nil, fmt.Errorf("unable to read oauth2 client secret file %s: %s", rt.config.ClientSecretFile, err)
726+
return nil, fmt.Errorf("unable to read oauth2 client secret file %s: %w", rt.config.ClientSecretFile, err)
727727
}
728728
secret = strings.TrimSpace(string(data))
729729
rt.mtx.RLock()
@@ -977,7 +977,7 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
977977
if c.CertFile != "" {
978978
certData, err = os.ReadFile(c.CertFile)
979979
if err != nil {
980-
return nil, fmt.Errorf("unable to read specified client cert (%s): %s", c.CertFile, err)
980+
return nil, fmt.Errorf("unable to read specified client cert (%s): %w", c.CertFile, err)
981981
}
982982
} else {
983983
certData = []byte(c.Cert)
@@ -986,15 +986,15 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
986986
if c.KeyFile != "" {
987987
keyData, err = os.ReadFile(c.KeyFile)
988988
if err != nil {
989-
return nil, fmt.Errorf("unable to read specified client key (%s): %s", c.KeyFile, err)
989+
return nil, fmt.Errorf("unable to read specified client key (%s): %w", c.KeyFile, err)
990990
}
991991
} else {
992992
keyData = []byte(c.Key)
993993
}
994994

995995
cert, err := tls.X509KeyPair(certData, keyData)
996996
if err != nil {
997-
return nil, fmt.Errorf("unable to use specified client cert (%s) & key (%s): %s", c.CertFile, c.KeyFile, err)
997+
return nil, fmt.Errorf("unable to use specified client cert (%s) & key (%s): %w", c.CertFile, c.KeyFile, err)
998998
}
999999

10001000
return &cert, nil
@@ -1004,7 +1004,7 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
10041004
func readCAFile(f string) ([]byte, error) {
10051005
data, err := os.ReadFile(f)
10061006
if err != nil {
1007-
return nil, fmt.Errorf("unable to load specified CA cert %s: %s", f, err)
1007+
return nil, fmt.Errorf("unable to load specified CA cert %s: %w", f, err)
10081008
}
10091009
return data, nil
10101010
}

0 commit comments

Comments
 (0)