Skip to content

Commit

Permalink
Merge pull request #788 from cloudflare/discovery
Browse files Browse the repository at this point in the history
Swich to git branch discovery
  • Loading branch information
prymitive authored Nov 23, 2023
2 parents 1ec5860 + 9ec14cf commit ae4e045
Show file tree
Hide file tree
Showing 31 changed files with 413 additions and 931 deletions.
16 changes: 2 additions & 14 deletions cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

var (
baseBranchFlag = "base-branch"
devFlag = "dev"
failOnFlag = "fail-on"
teamCityFlag = "teamcity"
)
Expand All @@ -43,12 +42,6 @@ var ciCmd = &cli.Command{
Value: "",
Usage: "Set base branch to use for PR checks (main, master, ...)",
},
&cli.BoolFlag{
Name: devFlag,
Aliases: []string{"n"},
Value: false,
Usage: "Use experimental change detection",
},
&cli.StringFlag{
Name: failOnFlag,
Aliases: []string{"w"},
Expand Down Expand Up @@ -96,13 +89,8 @@ func actionCI(c *cli.Context) error {
}

var entries []discovery.Entry
if c.Bool(devFlag) {
finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
entries, err = finder.Find()
} else {
finder := discovery.NewGitBlameFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
entries, err = finder.Find()
}
finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
entries, err = finder.Find()
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/pint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func httpServer(ts *testscript.TestScript, _ bool, args []string) {
}
mock.handler(w, r)
done = true
break
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func scanWorker(ctx context.Context, jobs <-chan scanJob, results chan<- reporte
default:
switch {
case job.entry.State == discovery.Removed:
// FIXME
// FIXME check if it breaks any other rule?
case errors.Is(job.entry.PathError, discovery.ErrFileIsIgnored):
results <- reporter.Report{
ReportedPath: job.entry.ReportedPath,
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0027_ci_branch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 using git blame" base=main
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Problems found" Fatal=1
rules.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
2 | expr: sum(foo) bi(job)
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0028_ci_git_error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
level=INFO msg="Loading configuration file" path=.pint.hcl
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
level=DEBUG msg="Got branch information" base=notmain current=v2
level=INFO msg="Finding all rules to check on current git branch using git blame" base=notmain
level=INFO msg="Finding all rules to check on current git branch" base=notmain
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","notmain..HEAD"]
level=ERROR msg="Fatal error" err="failed to get the list of commits to scan: fatal: ambiguous argument 'notmain..HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
-- src/v1.yml --
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0029_ci_too_many_commits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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 using git blame" base=main
level=INFO msg="Finding all rules to check on current git branch" base=main
level=ERROR msg="Fatal error" err="number of commits to check (3) is higher than maxCommits (2), exiting"
-- src/v1.yml --
- record: rule1
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0060_ci_noop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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 using git blame" base=main
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Problems found" Fatal=1
b.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
2 | expr: sum(foo) bi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,30 @@ cp ../src/v2.yml rules.yml
exec git commit -am 'v2'

env BITBUCKET_AUTH_TOKEN="12345"
pint.ok --no-color ci
pint.error -l error --no-color ci
! stdout .
stderr 'level=INFO msg="Problems found" Information=1'
cmp stderr ../stderr.txt

-- stderr.txt --
rules.yml:2 Warning: Alert query doesn't have any condition, it will always fire if the metric exists. (alerts/comparison)
2 | expr: sum(foo{job=~"xxx"}) by(job)

rules.yml:2 Bug: Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead. (promql/regexp)
2 | expr: sum(foo{job=~"xxx"}) by(job)

rules.yml:3 Information: `0s` is the default value of `for`, consider removing this redundant line. (alerts/for)
3 | for: 0s

rules.yml:5 Warning: Alert query doesn't have any condition, it will always fire if the metric exists. (alerts/comparison)
5 | expr: sum(foo{job=~"xxx"}) by(job)

rules.yml:5 Bug: Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead. (promql/regexp)
5 | expr: sum(foo{job=~"xxx"}) by(job)

rules.yml:6 Information: `0s` is the default value of `for`, consider removing this redundant line. (alerts/for)
6 | for: 0s

level=ERROR msg="Fatal error" err="problems found"
-- src/v1.yml --
- alert: rule1a
expr: sum(foo{job=~"xxx"}) by(job)
Expand Down
53 changes: 0 additions & 53 deletions cmd/pint/tests/0117_ci_dir_move_blame.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exec git commit -am 'v2'

env GITHUB_AUTH_TOKEN=12345
env GITHUB_PULL_REQUEST_NUMBER=1
pint.ok -l debug --no-color ci --dev
pint.ok -l debug --no-color ci
! stdout .
stderr 'level=INFO msg="Pull request review created" status="200 OK"'
stderr 'msg="Skipping directory entry change"'
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0124_ci_base_branch_flag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 using git blame" base=main
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Problems found" Fatal=1
rules.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
2 | expr: sum(foo) bi(job)
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0134_ci_base_branch_flag_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
level=INFO msg="Loading configuration file" path=.pint.hcl
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
level=DEBUG msg="Got branch information" base=origin/main current=v2
level=INFO msg="Finding all rules to check on current git branch using git blame" base=origin/main
level=INFO msg="Finding all rules to check on current git branch" base=origin/main
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
level=ERROR msg="Fatal error" err="failed to get the list of commits to scan: fatal: ambiguous argument 'origin/main..HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
-- src/v1.yml --
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0135_ci_base_branch_config_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
level=INFO msg="Loading configuration file" path=.pint.hcl
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
level=DEBUG msg="Got branch information" base=origin/main current=v2
level=INFO msg="Finding all rules to check on current git branch using git blame" base=origin/main
level=INFO msg="Finding all rules to check on current git branch" base=origin/main
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
level=ERROR msg="Fatal error" err="failed to get the list of commits to scan: fatal: ambiguous argument 'origin/main..HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
-- src/v1.yml --
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0159_ci_teamcity.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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 using git blame" base=main
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Problems found" Fatal=1 Warning=1
##teamcity[testSuiteStarted name='promql/syntax']
##teamcity[testSuiteStarted name='Fatal']
Expand Down
108 changes: 108 additions & 0 deletions cmd/pint/tests/0160_ci_comment_edit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
http response prometheus /api/v1/metadata 200 {"status":"success","data":{}}
http response prometheus /api/v1/status/config 200 {"status":"success","data":{"yaml":"global:\n scrape_interval: 30s\n"}}
http response prometheus /api/v1/status/flags 200 {"status":"success","data":{"storage.tsdb.retention.time": "1d"}}
http response prometheus /api/v1/query_range 200 {"status":"success","data":{"resultType":"matrix","result":[]}}
http response prometheus /api/v1/query 200 {"status":"success","data":{"resultType":"vector","result":[]}}
http start prometheus 127.0.0.1:7160

mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v0.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 v1
cp ../src/v1.yml rules.yml
exec git commit -am 'v1'
pint.ok --no-color ci
cmp stderr ../stderrV1.txt

exec git checkout main
exec git merge v1

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'v2'
pint.error --no-color ci
! stdout .
cmp stderr ../stderrV2.txt

-- stderrV1.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tags=[] include=[] exclude=[]
-- stderrV2.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=INFO msg="Finding all rules to check on current git branch" base=main
level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tags=[] include=[] exclude=[]
level=WARN msg="No results for Prometheus uptime metric, you might have set uptime config option to a missing metric, please check your config" name=prom metric=up
level=WARN msg="Using dummy Prometheus uptime metric results with no gaps" name=prom metric=up
level=WARN msg="No results for Prometheus uptime metric, you might have set uptime config option to a missing metric, please check your config" name=prom metric=up
level=WARN msg="Using dummy Prometheus uptime metric results with no gaps" name=prom metric=up
level=INFO msg="Problems found" Bug=2
rules.yml:8 Bug: `prom` Prometheus server at http://127.0.0.1:7160 didn't have any series for `up` metric in the last 1w. (promql/series)
8 | expr: up == 0

rules.yml:16 Bug: `prom` Prometheus server at http://127.0.0.1:7160 didn't have any series for `up` metric in the last 1w. (promql/series)
16 | expr: up == 0

level=ERROR msg="Fatal error" err="problems found"
-- src/v0.yml --
groups:
- name: g1
rules: []
-- src/v1.yml --
groups:
- name: g1
rules:
- alert: DownAlert
# foo
# pint disable promql/series(up)
# bar
expr: up == 0
annotations:
summary: 'Service is down'
labels:
cluster: dev
- record: up:sum
# foo
# pint disable promql/series(up)
# bar
expr: up == 0
labels:
cluster: dev
-- src/v2.yml --
groups:
- name: g1
rules:
- alert: DownAlert
# foo
# pint disable promql/series(xxx)
# bar
expr: up == 0
annotations:
summary: 'Service is down'
labels:
cluster: dev
- record: up:sum
# foo
# bar
expr: up == 0
labels:
cluster: dev
-- src/.pint.hcl --
ci {
baseBranch = "main"
}
prometheus "prom" {
uri = "http://127.0.0.1:7160"
timeout = "5s"
required = true
}
Loading

0 comments on commit ae4e045

Please sign in to comment.