Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump github.com/prometheus/common from 0.61.0 to 0.62.0 #1260

Merged
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
1 change: 1 addition & 0 deletions .github/spellcheck/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ unmarshal
uptime
URI
URIs
utf
UTF
validator
VCS
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/cloudflare/pint/internal/config"
Expand All @@ -27,6 +28,7 @@ func BenchmarkFindEntries(b *testing.B) {
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
parser.PrometheusSchema,
model.UTF8Validation,
nil,
)
for n := 0; n < b.N; n++ {
Expand All @@ -41,6 +43,7 @@ func BenchmarkCheckRules(b *testing.B) {
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
parser.PrometheusSchema,
model.UTF8Validation,
nil,
)
entries, err := finder.Find()
Expand Down
14 changes: 12 additions & 2 deletions cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/prometheus/common/model"

"github.com/cloudflare/pint/internal/checks"
"github.com/cloudflare/pint/internal/config"
"github.com/cloudflare/pint/internal/discovery"
Expand Down Expand Up @@ -102,14 +104,15 @@ func actionCI(c *cli.Context) error {
)

schema := parseSchema(meta.cfg.Parser.Schema)
names := parseNames(meta.cfg.Parser.Names)
allowedOwners := meta.cfg.Owners.CompileAllowed()
var entries []discovery.Entry
entries, err = discovery.NewGlobFinder([]string{"*"}, filter, schema, allowedOwners).Find()
entries, err = discovery.NewGlobFinder([]string{"*"}, filter, schema, names, allowedOwners).Find()
if err != nil {
return err
}

entries, err = discovery.NewGitBranchFinder(git.RunGit, filter, baseBranch, meta.cfg.CI.MaxCommits, schema, allowedOwners).Find(entries)
entries, err = discovery.NewGitBranchFinder(git.RunGit, filter, baseBranch, meta.cfg.CI.MaxCommits, schema, names, allowedOwners).Find(entries)
if err != nil {
return err
}
Expand Down Expand Up @@ -359,3 +362,10 @@ func parseSchema(s string) parser.Schema {
}
return parser.PrometheusSchema
}

func parseNames(s string) model.ValidationScheme {
if s == config.NamesLegacy {
return model.LegacyValidation
}
return model.UTF8Validation
}
1 change: 1 addition & 0 deletions cmd/pint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func actionLint(c *cli.Context) error {
config.MustCompileRegexes(meta.cfg.Parser.Relaxed...),
),
parseSchema(meta.cfg.Parser.Schema),
parseNames(meta.cfg.Parser.Names),
allowedOwners,
)
entries, err := finder.Find()
Expand Down
6 changes: 6 additions & 0 deletions cmd/pint/tests/0166_invalid_label.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cmp stderr stderr.txt

-- stderr.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=INFO msg="Finding all rules to check" paths=["rules"]
level=INFO msg="Checking Prometheus rules" entries=2 workers=10 online=true
rules/1.yaml:7 Fatal: This rule is not a valid Prometheus rule: `invalid annotation name: {{ $value }}`. (yaml/parse)
Expand All @@ -25,3 +26,8 @@ groups:
expr: up == 0
labels:
"{{ $value }}": "down"

-- .pint.hcl --
parser {
names = "legacy"
}
11 changes: 7 additions & 4 deletions cmd/pint/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/model"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -209,12 +210,13 @@ func actionWatch(c *cli.Context, meta actionMeta, f pathFinderFunc) error {
}

schema := parseSchema(meta.cfg.Parser.Schema)
names := parseNames(meta.cfg.Parser.Names)
allowedOwners := meta.cfg.Owners.CompileAllowed()

// start timer to run every $interval
ack := make(chan bool, 1)
mainCtx, mainCancel := context.WithCancel(context.WithValue(context.Background(), config.CommandKey, config.WatchCommand))
stop := startTimer(mainCtx, meta.workers, meta.isOffline, gen, schema, allowedOwners, interval, ack, collector)
stop := startTimer(mainCtx, meta.workers, meta.isOffline, gen, schema, names, allowedOwners, interval, ack, collector)

quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -238,7 +240,7 @@ func actionWatch(c *cli.Context, meta actionMeta, f pathFinderFunc) error {
return nil
}

func startTimer(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, schema parser.Schema, allowedOwners []*regexp.Regexp, interval time.Duration, ack chan bool, collector *problemCollector) chan bool {
func startTimer(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, schema parser.Schema, names model.ValidationScheme, allowedOwners []*regexp.Regexp, interval time.Duration, ack chan bool, collector *problemCollector) chan bool {
ticker := time.NewTicker(time.Second)
stop := make(chan bool, 1)
wasBootstrapped := false
Expand All @@ -252,7 +254,7 @@ func startTimer(ctx context.Context, workers int, isOffline bool, gen *config.Pr
ticker.Reset(interval)
wasBootstrapped = true
}
if err := collector.scan(ctx, workers, isOffline, gen, schema, allowedOwners); err != nil {
if err := collector.scan(ctx, workers, isOffline, gen, schema, names, allowedOwners); err != nil {
slog.Error("Got an error when running checks", slog.Any("err", err))
}
checkIterationsTotal.Inc()
Expand Down Expand Up @@ -310,7 +312,7 @@ func newProblemCollector(cfg config.Config, f pathFinderFunc, minSeverity checks
}
}

func (c *problemCollector) scan(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, schema parser.Schema, allowedOwners []*regexp.Regexp) error {
func (c *problemCollector) scan(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, schema parser.Schema, names model.ValidationScheme, allowedOwners []*regexp.Regexp) error {
paths, err := c.finder(ctx)
if err != nil {
return fmt.Errorf("failed to get the list of paths to check: %w", err)
Expand All @@ -325,6 +327,7 @@ func (c *problemCollector) scan(ctx context.Context, workers int, isOffline bool
config.MustCompileRegexes(c.cfg.Parser.Relaxed...),
),
schema,
names,
allowedOwners,
).Find()
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.71.0

### Added

- Added `names` option to the `parser` block, which controls how does Prometheus validates
label names.

## v0.70.0

### Added
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Syntax:
```js
parser {
schema = "prometheus|thanos"
names = "legacy|utf-8"
include = [ "(.*)", ... ]
exclude = [ "(.*)", ... ]
relaxed = [ "(.*)", ... ]
Expand All @@ -81,6 +82,9 @@ parser {
in [Thanos Rule](https://thanos.io/tip/components/rule.md/) docs, which currently allows for setting
an extra key on the rule group object - `partial_response_strategy`.
Default value is `prometheus`.
- `names` - validation scheme for label names. This control if Prometheus libraries are
allowing UTF-8 in label **names** or not. See [utf-8 guide](https://prometheus.io/docs/guides/utf8/).
Default value is `utf-8`.
- `include` - list of regexp patterns to check when running checks. Only files
matching those regexp rules will be checked, other modified files will be ignored.
- `exclude` - list of regexp patterns to ignore when running checks.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/neilotoole/slogt v1.1.0
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.61.0
github.com/prometheus/common v0.62.0
github.com/prometheus/prometheus v0.301.0
github.com/prymitive/current v0.1.1
github.com/rogpeppe/go-internal v1.13.1
Expand Down Expand Up @@ -76,5 +76,5 @@ require (
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ=
github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s=
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/prometheus/prometheus v0.301.0 h1:0z8dgegmILivNomCd79RKvVkIols8vBGPKmcIBc7OyY=
Expand Down Expand Up @@ -215,8 +215,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -251,8 +251,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI=
google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func runTests(t *testing.T, testCases []checkTest) {
}

func parseContent(content string) (entries []discovery.Entry, err error) {
p := parser.NewParser(false, parser.PrometheusSchema)
p := parser.NewParser(false, parser.PrometheusSchema, model.UTF8Validation)
rules, err := p.Parse([]byte(content))
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion internal/checks/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package checks_test
import (
"testing"

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/cloudflare/pint/internal/checks"
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestTemplatedRegexpExpand(t *testing.T) {
}

func newMustRule(content string) parser.Rule {
p := parser.NewParser(false, parser.PrometheusSchema)
p := parser.NewParser(false, parser.PrometheusSchema, model.UTF8Validation)
rules, err := p.Parse([]byte(content))
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/gkampitakis/go-snaps/snaps"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/cloudflare/pint/internal/checks"
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestSetDisabledChecks(t *testing.T) {
}

func newRule(t *testing.T, content string) parser.Rule {
p := parser.NewParser(false, parser.PrometheusSchema)
p := parser.NewParser(false, parser.PrometheusSchema, model.UTF8Validation)
rules, err := p.Parse([]byte(content))
if err != nil {
t.Error(err)
Expand Down
18 changes: 18 additions & 0 deletions internal/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
const (
SchemaPrometheus = "prometheus"
SchemaThanos = "thanos"

NamesLegacy = "legacy"
NamesUTF8 = "utf-8"
)

type Parser struct {
Schema string `hcl:"schema,optional" json:"schema,omitempty"`
Names string `hcl:"names,optional" json:"names,omitempty"`
Relaxed []string `hcl:"relaxed,optional" json:"relaxed,omitempty"`
Include []string `hcl:"include,optional" json:"include,omitempty"`
Exclude []string `hcl:"exclude,optional" json:"exclude,omitempty"`
Expand All @@ -24,6 +28,13 @@ func (p Parser) getSchema() string {
return p.Schema
}

func (p Parser) getNames() string {
if p.Names == "" {
return NamesUTF8
}
return p.Names
}

func (p Parser) validate() error {
switch s := p.getSchema(); s {
case SchemaPrometheus:
Expand All @@ -32,6 +43,13 @@ func (p Parser) validate() error {
return fmt.Errorf("unsupported parser scheme: %s", s)
}

switch n := p.getNames(); n {
case NamesUTF8:
case NamesLegacy:
default:
return fmt.Errorf("unsupported parser names: %s", n)
}

for _, pattern := range p.Relaxed {
_, err := regexp.Compile(pattern)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Entry struct {
State ChangeType
}

func readRules(reportedPath, sourcePath string, r io.Reader, isStrict bool, schema parser.Schema, allowedOwners []*regexp.Regexp) (entries []Entry, err error) {
func readRules(reportedPath, sourcePath string, r io.Reader, p parser.Parser, allowedOwners []*regexp.Regexp) (entries []Entry, err error) {
content, err := parser.ReadContent(r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -159,7 +159,6 @@ func readRules(reportedPath, sourcePath string, r io.Reader, isStrict bool, sche
return entries, nil
}

p := parser.NewParser(isStrict, schema)
rules, err := p.Parse(content.Body)
if err != nil {
slog.Warn(
Expand Down
6 changes: 4 additions & 2 deletions internal/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"testing"

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/cloudflare/pint/internal/parser"
Expand All @@ -24,7 +25,7 @@ func (r failingReader) Read(_ []byte) (int, error) {

func TestReadRules(t *testing.T) {
mustParse := func(offset int, s string) parser.Rule {
p := parser.NewParser(false, parser.PrometheusSchema)
p := parser.NewParser(false, parser.PrometheusSchema, model.UTF8Validation)
r, err := p.Parse([]byte(strings.Repeat("\n", offset) + s))
if err != nil {
panic(fmt.Sprintf("failed to parse rule:\n---\n%s\n---\nerror: %s", s, err))
Expand Down Expand Up @@ -338,7 +339,8 @@ groups:
fmt.Sprintf("rPath=%s sPath=%s strict=%v title=%s", tc.reportedPath, tc.sourcePath, tc.isStrict, tc.title),
func(t *testing.T) {
r := tc.sourceFunc(t)
entries, err := readRules(tc.reportedPath, tc.sourcePath, r, tc.isStrict, parser.PrometheusSchema, nil)
p := parser.NewParser(tc.isStrict, parser.PrometheusSchema, model.UTF8Validation)
entries, err := readRules(tc.reportedPath, tc.sourcePath, r, p, nil)
if tc.err != "" {
require.EqualError(t, err, tc.err)
} else {
Expand Down
Loading
Loading