Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prometheus/common
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.45.0
Choose a base ref
...
head repository: prometheus/common
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.48.0
Choose a head ref
Loading
Showing with 2,486 additions and 737 deletions.
  1. +10 −4 .github/workflows/golangci-lint.yml
  2. +41 −0 .golangci.yml
  3. +1 −1 Makefile.common
  4. +3 −4 config/generate.go
  5. +15 −19 config/http_config.go
  6. +282 −98 config/http_config_test.go
  7. +0 −3 config/testdata/http.conf.oauth2-no-client-secret.bad.yaml
  8. +19 −12 config/tls_config_test.go
  9. +22 −10 expfmt/bench_test.go
  10. +15 −12 expfmt/decode.go
  11. +65 −19 expfmt/decode_test.go
  12. +52 −26 expfmt/encode.go
  13. +200 −18 expfmt/encode_test.go
  14. +134 −10 expfmt/expfmt.go
  15. +58 −27 expfmt/openmetrics_create.go
  16. +199 −76 expfmt/openmetrics_create_test.go
  17. +87 −31 expfmt/text_create.go
  18. +120 −69 expfmt/text_create_test.go
  19. +5 −3 expfmt/text_parse.go
  20. +52 −53 expfmt/text_parse_test.go
  21. +10 −10 go.mod
  22. +20 −21 go.sum
  23. +2 −2 model/alert.go
  24. +1 −1 model/alert_test.go
  25. +0 −1 model/fingerprinting_test.go
  26. +15 −7 model/labels.go
  27. +44 −25 model/labels_test.go
  28. +1 −2 model/labelset_test.go
  29. +28 −0 model/metadata.go
  30. +361 −7 model/metric.go
  31. +472 −29 model/metric_test.go
  32. +2 −4 model/signature.go
  33. +7 −7 model/signature_test.go
  34. +1 −1 model/silence.go
  35. +47 −17 model/silence_test.go
  36. +28 −18 model/time_test.go
  37. +7 −9 model/value.go
  38. +6 −8 model/value_float.go
  39. +0 −1 model/value_test.go
  40. +9 −4 promlog/flag/flag.go
  41. +3 −0 promlog/log.go
  42. +0 −1 server/static_file_server_test.go
  43. +10 −11 sigv4/go.mod
  44. +19 −45 sigv4/go.sum
  45. +6 −6 version/info.go
  46. +1 −1 version/info_default.go
  47. +6 −4 version/info_go118.go
14 changes: 10 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -12,21 +12,27 @@ on:
- ".golangci.yml"
pull_request:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: install Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: v1.54.2
version: v1.55.2
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
linters:
enable:
- errorlint
- gofumpt
- goimports
- misspell
- revive
- testifylint

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
max-issues-per-linter: 0
max-same-issues: 0

linters-settings:
goimports:
local-prefixes: github.com/prometheus/common
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
testifylint:
disable:
- float-compare
- go-require
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.54.2
GOLANGCI_LINT_VERSION ?= v1.55.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
7 changes: 3 additions & 4 deletions config/generate.go
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@ func SerialNumber() *big.Int {
serialNumber.Add(&serial, big.NewInt(1))

return &serial

}

func GenerateCertificateAuthority(commonName string, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, *rsa.PrivateKey, error) {
@@ -170,7 +169,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0o644); err != nil {
return err
}

@@ -179,7 +178,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0o644); err != nil {
return err
}

@@ -239,7 +238,7 @@ func main() {
log.Fatal(err)
}

if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0644); err != nil {
if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0o644); err != nil {
log.Fatal(err)
}
}
34 changes: 15 additions & 19 deletions config/http_config.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ import (
"sync"
"time"

"github.com/mwitkow/go-conntrack"
conntrack "github.com/mwitkow/go-conntrack"
"golang.org/x/net/http/httpproxy"
"golang.org/x/net/http2"
"golang.org/x/oauth2"
@@ -378,9 +378,6 @@ func (c *HTTPClientConfig) Validate() error {
if len(c.OAuth2.ClientID) == 0 {
return fmt.Errorf("oauth2 client_id must be configured")
}
if len(c.OAuth2.ClientSecret) == 0 && len(c.OAuth2.ClientSecretFile) == 0 {
return fmt.Errorf("either oauth2 client_secret or client_secret_file must be configured")
}
if len(c.OAuth2.TokenURL) == 0 {
return fmt.Errorf("oauth2 token_url must be configured")
}
@@ -546,10 +543,10 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT

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

@@ -670,7 +667,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
if rt.usernameFile != "" {
usernameBytes, err := os.ReadFile(rt.usernameFile)
if err != nil {
return nil, fmt.Errorf("unable to read basic auth username file %s: %s", rt.usernameFile, err)
return nil, fmt.Errorf("unable to read basic auth username file %s: %w", rt.usernameFile, err)
}
username = strings.TrimSpace(string(usernameBytes))
} else {
@@ -679,7 +676,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
if rt.passwordFile != "" {
passwordBytes, err := os.ReadFile(rt.passwordFile)
if err != nil {
return nil, fmt.Errorf("unable to read basic auth password file %s: %s", rt.passwordFile, err)
return nil, fmt.Errorf("unable to read basic auth password file %s: %w", rt.passwordFile, err)
}
password = strings.TrimSpace(string(passwordBytes))
} else {
@@ -723,19 +720,18 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
if rt.config.ClientSecretFile != "" {
data, err := os.ReadFile(rt.config.ClientSecretFile)
if err != nil {
return nil, fmt.Errorf("unable to read oauth2 client secret file %s: %s", rt.config.ClientSecretFile, err)
return nil, fmt.Errorf("unable to read oauth2 client secret file %s: %w", rt.config.ClientSecretFile, err)
}
secret = strings.TrimSpace(string(data))
rt.mtx.RLock()
changed = secret != rt.secret
rt.mtx.RUnlock()
} else {
// Either an inline secret or nothing (use an empty string) was provided.
secret = string(rt.config.ClientSecret)
}

if changed || rt.rt == nil {
if rt.config.ClientSecret != "" {
secret = string(rt.config.ClientSecret)
}

config := &clientcredentials.Config{
ClientID: rt.config.ClientID,
ClientSecret: secret,
@@ -977,7 +973,7 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
if c.CertFile != "" {
certData, err = os.ReadFile(c.CertFile)
if err != nil {
return nil, fmt.Errorf("unable to read specified client cert (%s): %s", c.CertFile, err)
return nil, fmt.Errorf("unable to read specified client cert (%s): %w", c.CertFile, err)
}
} else {
certData = []byte(c.Cert)
@@ -986,15 +982,15 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
if c.KeyFile != "" {
keyData, err = os.ReadFile(c.KeyFile)
if err != nil {
return nil, fmt.Errorf("unable to read specified client key (%s): %s", c.KeyFile, err)
return nil, fmt.Errorf("unable to read specified client key (%s): %w", c.KeyFile, err)
}
} else {
keyData = []byte(c.Key)
}

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

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