diff --git a/cmd/pint/tests/0188_ci_noop.txt b/cmd/pint/tests/0188_ci_noop.txt new file mode 100644 index 00000000..fd9f870d --- /dev/null +++ b/cmd/pint/tests/0188_ci_noop.txt @@ -0,0 +1,68 @@ +http response bitbucket /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint 200 OK +http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests 200 {} +http start bitbucket 127.0.0.1:6188 + +mkdir testrepo +cd testrepo +exec git init --initial-branch=main . + +cp ../src/rules.yml rules.yml +cp ../src/.pint.hcl . +env GIT_AUTHOR_NAME=pint +env GIT_AUTHOR_EMAIL=pint@example.com +env GIT_COMMITTER_NAME=pint +env GIT_COMMITTER_EMAIL=pint@example.com +exec git add . +exec git commit -am 'import rules and config' + +exec git checkout -b v2 +exec touch .keep +exec git add .keep +exec git commit -am 'v2' + +env BITBUCKET_AUTH_TOKEN="12345" +exec pint -l debug --no-color ci +! stdout . +stderr '{"value":2,"title":"Number of rules parsed","type":"NUMBER"}' +stderr '{"value":2,"title":"Number of rules checked","type":"NUMBER"}' +stderr '{"value":0,"title":"Number of problems found","type":"NUMBER"}' +stderr '{"value":0,"title":"Number of offline checks","type":"NUMBER"}' +stderr '{"value":0,"title":"Number of online checks","type":"NUMBER"}' + +-- src/rules.yml -- +- alert: alert1 + expr: up == 0 + for: 5m +- alert: alert2 + expr: up == 0 + for: 5m + +-- src/.pint.hcl -- +parser { + relaxed = [".*"] +} +ci { + baseBranch = "main" +} +repository { + bitbucket { + uri = "http://127.0.0.1:6188" + project = "prometheus" + repository = "rules" + } +} +prometheus "prom" { + uri = "http://127.0.0.1:2188" + timeout = "5s" + required = true +} +rule { + match { + kind = "alerting" + } + alerts { + range = "1d" + step = "1m" + resolve = "5m" + } +} diff --git a/cmd/pint/tests/0189_config_bad_loglevel.txt b/cmd/pint/tests/0189_config_bad_loglevel.txt new file mode 100644 index 00000000..5b5c8884 --- /dev/null +++ b/cmd/pint/tests/0189_config_bad_loglevel.txt @@ -0,0 +1,7 @@ +! exec pint -l invalid --no-color config +! stdout . +stderr 'ERROR Fatal error err="failed to set log level: ''invalid'' is not a valid log level"' + +! exec pint -l invalid --no-color parse 'foo' +! stdout . +stderr 'ERROR Fatal error err="failed to set log level: ''invalid'' is not a valid log level"' \ No newline at end of file diff --git a/cmd/pint/tests/0190_ci_dup_prom.txt b/cmd/pint/tests/0190_ci_dup_prom.txt new file mode 100644 index 00000000..8238903e --- /dev/null +++ b/cmd/pint/tests/0190_ci_dup_prom.txt @@ -0,0 +1,38 @@ +mkdir testrepo +cd testrepo +exec git init --initial-branch=main . + +cp ../src/.pint.hcl . +env GIT_AUTHOR_NAME=pint +env GIT_AUTHOR_EMAIL=pint@example.com +env GIT_COMMITTER_NAME=pint +env GIT_COMMITTER_EMAIL=pint@example.com +exec git add . +exec git commit -am 'import rules and config' + +exec git checkout -b v2 +exec touch .keep +exec git add .keep +exec git commit -am 'v2' + +! exec pint --no-color ci +! stdout . +cmp stderr ../stderr.txt + +-- stderr.txt -- +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": prometheus server name must be unique, found two or more config blocks using \"prom\" name" +-- src/.pint.hcl -- +ci { + baseBranch = "main" +} +prometheus "prom" { + uri = "http://127.0.0.1:2190" + timeout = "5s" + required = true +} +prometheus "prom" { + uri = "http://127.0.0.1:3190" + timeout = "5s" + required = true +} diff --git a/cmd/pint/tests/0191_lint_dup_prom.txt b/cmd/pint/tests/0191_lint_dup_prom.txt new file mode 100644 index 00000000..80e450f2 --- /dev/null +++ b/cmd/pint/tests/0191_lint_dup_prom.txt @@ -0,0 +1,19 @@ +! exec pint --no-color lint rules.yml +! stdout . +cmp stderr stderr.txt + +-- stderr.txt -- +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": prometheus server name must be unique, found two or more config blocks using \"prom\" name" +-- rules.yml -- +-- .pint.hcl -- +prometheus "prom" { + uri = "http://127.0.0.1:2191" + timeout = "5s" + required = true +} +prometheus "prom" { + uri = "http://127.0.0.1:3191" + timeout = "5s" + required = true +} diff --git a/cmd/pint/tests/0192_ci_broken_removed_rule.txt b/cmd/pint/tests/0192_ci_broken_removed_rule.txt new file mode 100644 index 00000000..67750588 --- /dev/null +++ b/cmd/pint/tests/0192_ci_broken_removed_rule.txt @@ -0,0 +1,40 @@ +mkdir testrepo +cd testrepo +exec git init --initial-branch=main . + +cp ../src/rules.yml rules.yml +cp ../src/.pint.hcl . +env GIT_AUTHOR_NAME=pint +env GIT_AUTHOR_EMAIL=pint@example.com +env GIT_COMMITTER_NAME=pint +env GIT_COMMITTER_EMAIL=pint@example.com +exec git add . +exec git commit -am 'import rules and config' + +exec git checkout -b v2 +exec git rm rules.yml +exec git commit -am 'v2' + +exec pint --no-color ci +! stdout . +cmp stderr ../stderr.txt + +-- stderr.txt -- +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Finding all rules to check on current git branch" base=main +-- src/rules.yml -- +groups: +- name: foo + rules: + - record: + expr: sum(foo) by(job) + - record: rule2 + expr: sum(foo + +-- src/.pint.hcl -- +ci { + baseBranch = "main" +} +parser { + include = ["rules.yml"] +} diff --git a/go.mod b/go.mod index 79aca733..8cd1c4e1 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,6 @@ require ( go.uber.org/atomic v1.11.0 go.uber.org/automaxprocs v1.5.3 go.uber.org/ratelimit v0.3.1 - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/oauth2 v0.22.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -72,6 +71,7 @@ require ( go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/metric v1.28.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect + golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect golang.org/x/mod v0.19.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.22.0 // indirect diff --git a/internal/checks/alerts_annotation.go b/internal/checks/alerts_annotation.go index c987a080..9461a098 100644 --- a/internal/checks/alerts_annotation.go +++ b/internal/checks/alerts_annotation.go @@ -3,13 +3,12 @@ package checks import ( "context" "fmt" + "slices" "strconv" "strings" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" - - "golang.org/x/exp/slices" ) const ( diff --git a/internal/checks/alerts_template.go b/internal/checks/alerts_template.go index 0b97f7aa..6de491c1 100644 --- a/internal/checks/alerts_template.go +++ b/internal/checks/alerts_template.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "slices" "strings" textTemplate "text/template" "text/template/parse" @@ -15,7 +16,6 @@ import ( "github.com/prometheus/prometheus/promql" promParser "github.com/prometheus/prometheus/promql/parser" promTemplate "github.com/prometheus/prometheus/template" - "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" diff --git a/internal/checks/promql_rate.go b/internal/checks/promql_rate.go index 188c8131..61467a46 100644 --- a/internal/checks/promql_rate.go +++ b/internal/checks/promql_rate.go @@ -3,10 +3,9 @@ package checks import ( "context" "fmt" + "slices" "time" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/output" "github.com/cloudflare/pint/internal/parser" diff --git a/internal/checks/promql_series.go b/internal/checks/promql_series.go index 7c76a50d..d7f6e17e 100644 --- a/internal/checks/promql_series.go +++ b/internal/checks/promql_series.go @@ -5,12 +5,11 @@ import ( "fmt" "log/slog" "regexp" + "slices" "strconv" "strings" "time" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/comments" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/output" diff --git a/internal/checks/promql_vector_matching.go b/internal/checks/promql_vector_matching.go index b1727431..6160aabe 100644 --- a/internal/checks/promql_vector_matching.go +++ b/internal/checks/promql_vector_matching.go @@ -3,13 +3,13 @@ package checks import ( "context" "fmt" + "slices" "sort" "strings" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" promParser "github.com/prometheus/prometheus/promql/parser" - "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" diff --git a/internal/checks/rule_link.go b/internal/checks/rule_link.go index c4add066..9aff968f 100644 --- a/internal/checks/rule_link.go +++ b/internal/checks/rule_link.go @@ -8,10 +8,9 @@ import ( "net/http" "net/url" "regexp" + "slices" "time" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" ) diff --git a/internal/config/config.go b/internal/config/config.go index dec29433..f1b91393 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,11 +6,10 @@ import ( "fmt" "log/slog" "os" + "slices" "strings" "time" - "golang.org/x/exp/slices" - "github.com/zclconf/go-cty/cty" "github.com/cloudflare/pint/internal/checks" diff --git a/internal/config/parsed_rule.go b/internal/config/parsed_rule.go index c69867a5..568d1f2b 100644 --- a/internal/config/parsed_rule.go +++ b/internal/config/parsed_rule.go @@ -2,10 +2,9 @@ package config import ( "context" + "slices" "time" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/checks" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/promapi" diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 152cefa3..77c359a6 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -6,10 +6,9 @@ import ( "fmt" "io" "log/slog" + "slices" "time" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/comments" "github.com/cloudflare/pint/internal/parser" ) diff --git a/internal/discovery/git_branch.go b/internal/discovery/git_branch.go index eba76368..7d24c235 100644 --- a/internal/discovery/git_branch.go +++ b/internal/discovery/git_branch.go @@ -4,11 +4,10 @@ import ( "bytes" "fmt" "log/slog" + "slices" "sort" "strings" - "golang.org/x/exp/slices" - "github.com/cloudflare/pint/internal/git" "github.com/cloudflare/pint/internal/output" "github.com/cloudflare/pint/internal/parser" diff --git a/internal/git/changes.go b/internal/git/changes.go index 7253106f..21b7ee00 100644 --- a/internal/git/changes.go +++ b/internal/git/changes.go @@ -7,9 +7,8 @@ import ( "log/slog" "os" "path" + "slices" "strings" - - "golang.org/x/exp/slices" ) type FileStatus rune diff --git a/internal/parser/models.go b/internal/parser/models.go index 123b9e04..0ecaab77 100644 --- a/internal/parser/models.go +++ b/internal/parser/models.go @@ -2,10 +2,10 @@ package parser import ( "fmt" + "slices" "strconv" "strings" - "golang.org/x/exp/slices" "gopkg.in/yaml.v3" "github.com/cloudflare/pint/internal/comments"