Skip to content

Commit ae4e045

Browse files
authored
Merge pull request #788 from cloudflare/discovery
Swich to git branch discovery
2 parents 1ec5860 + 9ec14cf commit ae4e045

31 files changed

+413
-931
lines changed

cmd/pint/ci.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
var (
2323
baseBranchFlag = "base-branch"
24-
devFlag = "dev"
2524
failOnFlag = "fail-on"
2625
teamCityFlag = "teamcity"
2726
)
@@ -43,12 +42,6 @@ var ciCmd = &cli.Command{
4342
Value: "",
4443
Usage: "Set base branch to use for PR checks (main, master, ...)",
4544
},
46-
&cli.BoolFlag{
47-
Name: devFlag,
48-
Aliases: []string{"n"},
49-
Value: false,
50-
Usage: "Use experimental change detection",
51-
},
5245
&cli.StringFlag{
5346
Name: failOnFlag,
5447
Aliases: []string{"w"},
@@ -96,13 +89,8 @@ func actionCI(c *cli.Context) error {
9689
}
9790

9891
var entries []discovery.Entry
99-
if c.Bool(devFlag) {
100-
finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
101-
entries, err = finder.Find()
102-
} else {
103-
finder := discovery.NewGitBlameFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
104-
entries, err = finder.Find()
105-
}
92+
finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, excludeRe, baseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
93+
entries, err = finder.Find()
10694
if err != nil {
10795
return err
10896
}

cmd/pint/main_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func httpServer(ts *testscript.TestScript, _ bool, args []string) {
190190
}
191191
mock.handler(w, r)
192192
done = true
193+
break
193194
}
194195
break
195196
}

cmd/pint/scan.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func scanWorker(ctx context.Context, jobs <-chan scanJob, results chan<- reporte
175175
default:
176176
switch {
177177
case job.entry.State == discovery.Removed:
178-
// FIXME
178+
// FIXME check if it breaks any other rule?
179179
case errors.Is(job.entry.PathError, discovery.ErrFileIsIgnored):
180180
results <- reporter.Report{
181181
ReportedPath: job.entry.ReportedPath,

cmd/pint/tests/0027_ci_branch.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cmp stderr ../stderr.txt
2121

2222
-- stderr.txt --
2323
level=INFO msg="Loading configuration file" path=.pint.hcl
24-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=main
24+
level=INFO msg="Finding all rules to check on current git branch" base=main
2525
level=INFO msg="Problems found" Fatal=1
2626
rules.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
2727
2 | expr: sum(foo) bi(job)

cmd/pint/tests/0028_ci_git_error.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
2323
level=INFO msg="Loading configuration file" path=.pint.hcl
2424
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
2525
level=DEBUG msg="Got branch information" base=notmain current=v2
26-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=notmain
26+
level=INFO msg="Finding all rules to check on current git branch" base=notmain
2727
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","notmain..HEAD"]
2828
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"
2929
-- src/v1.yml --

cmd/pint/tests/0029_ci_too_many_commits.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cmp stderr ../stderr.txt
2828

2929
-- stderr.txt --
3030
level=INFO msg="Loading configuration file" path=.pint.hcl
31-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=main
31+
level=INFO msg="Finding all rules to check on current git branch" base=main
3232
level=ERROR msg="Fatal error" err="number of commits to check (3) is higher than maxCommits (2), exiting"
3333
-- src/v1.yml --
3434
- record: rule1

cmd/pint/tests/0060_ci_noop.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cmp stderr ../stderr.txt
3030

3131
-- stderr.txt --
3232
level=INFO msg="Loading configuration file" path=.pint.hcl
33-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=main
33+
level=INFO msg="Finding all rules to check on current git branch" base=main
3434
level=INFO msg="Problems found" Fatal=1
3535
b.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
3636
2 | expr: sum(foo) bi()

cmd/pint/tests/0069_bitbucket_skip_unmodified.txt cmd/pint/tests/0069_bitbucket_unmodified.txt

+22-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,30 @@ cp ../src/v2.yml rules.yml
2020
exec git commit -am 'v2'
2121

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

27+
-- stderr.txt --
28+
rules.yml:2 Warning: Alert query doesn't have any condition, it will always fire if the metric exists. (alerts/comparison)
29+
2 | expr: sum(foo{job=~"xxx"}) by(job)
30+
31+
rules.yml:2 Bug: Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead. (promql/regexp)
32+
2 | expr: sum(foo{job=~"xxx"}) by(job)
33+
34+
rules.yml:3 Information: `0s` is the default value of `for`, consider removing this redundant line. (alerts/for)
35+
3 | for: 0s
36+
37+
rules.yml:5 Warning: Alert query doesn't have any condition, it will always fire if the metric exists. (alerts/comparison)
38+
5 | expr: sum(foo{job=~"xxx"}) by(job)
39+
40+
rules.yml:5 Bug: Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead. (promql/regexp)
41+
5 | expr: sum(foo{job=~"xxx"}) by(job)
42+
43+
rules.yml:6 Information: `0s` is the default value of `for`, consider removing this redundant line. (alerts/for)
44+
6 | for: 0s
45+
46+
level=ERROR msg="Fatal error" err="problems found"
2747
-- src/v1.yml --
2848
- alert: rule1a
2949
expr: sum(foo{job=~"xxx"}) by(job)

cmd/pint/tests/0117_ci_dir_move_blame.txt

-53
This file was deleted.

cmd/pint/tests/0118_ci_dir_move_branch.txt cmd/pint/tests/0118_ci_dir_move.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exec git commit -am 'v2'
2525

2626
env GITHUB_AUTH_TOKEN=12345
2727
env GITHUB_PULL_REQUEST_NUMBER=1
28-
pint.ok -l debug --no-color ci --dev
28+
pint.ok -l debug --no-color ci
2929
! stdout .
3030
stderr 'level=INFO msg="Pull request review created" status="200 OK"'
3131
stderr 'msg="Skipping directory entry change"'

cmd/pint/tests/0124_ci_base_branch_flag.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cmp stderr ../stderr.txt
2121

2222
-- stderr.txt --
2323
level=INFO msg="Loading configuration file" path=.pint.hcl
24-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=main
24+
level=INFO msg="Finding all rules to check on current git branch" base=main
2525
level=INFO msg="Problems found" Fatal=1
2626
rules.yml:2 Fatal: Prometheus failed to parse the query with this PromQL error: unexpected identifier "bi". (promql/syntax)
2727
2 | expr: sum(foo) bi(job)

cmd/pint/tests/0134_ci_base_branch_flag_path.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
2323
level=INFO msg="Loading configuration file" path=.pint.hcl
2424
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
2525
level=DEBUG msg="Got branch information" base=origin/main current=v2
26-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=origin/main
26+
level=INFO msg="Finding all rules to check on current git branch" base=origin/main
2727
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
2828
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"
2929
-- src/v1.yml --

cmd/pint/tests/0135_ci_base_branch_config_path.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cmp stderr ../stderr.txt
2323
level=INFO msg="Loading configuration file" path=.pint.hcl
2424
level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
2525
level=DEBUG msg="Got branch information" base=origin/main current=v2
26-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=origin/main
26+
level=INFO msg="Finding all rules to check on current git branch" base=origin/main
2727
level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
2828
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"
2929
-- src/v1.yml --

cmd/pint/tests/0159_ci_teamcity.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cmp stderr ../stderr.txt
3030

3131
-- stderr.txt --
3232
level=INFO msg="Loading configuration file" path=.pint.hcl
33-
level=INFO msg="Finding all rules to check on current git branch using git blame" base=main
33+
level=INFO msg="Finding all rules to check on current git branch" base=main
3434
level=INFO msg="Problems found" Fatal=1 Warning=1
3535
##teamcity[testSuiteStarted name='promql/syntax']
3636
##teamcity[testSuiteStarted name='Fatal']
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
http response prometheus /api/v1/metadata 200 {"status":"success","data":{}}
2+
http response prometheus /api/v1/status/config 200 {"status":"success","data":{"yaml":"global:\n scrape_interval: 30s\n"}}
3+
http response prometheus /api/v1/status/flags 200 {"status":"success","data":{"storage.tsdb.retention.time": "1d"}}
4+
http response prometheus /api/v1/query_range 200 {"status":"success","data":{"resultType":"matrix","result":[]}}
5+
http response prometheus /api/v1/query 200 {"status":"success","data":{"resultType":"vector","result":[]}}
6+
http start prometheus 127.0.0.1:7160
7+
8+
mkdir testrepo
9+
cd testrepo
10+
exec git init --initial-branch=main .
11+
12+
cp ../src/v0.yml rules.yml
13+
cp ../src/.pint.hcl .
14+
env GIT_AUTHOR_NAME=pint
15+
16+
env GIT_COMMITTER_NAME=pint
17+
18+
exec git add .
19+
exec git commit -am 'import rules and config'
20+
21+
exec git checkout -b v1
22+
cp ../src/v1.yml rules.yml
23+
exec git commit -am 'v1'
24+
pint.ok --no-color ci
25+
cmp stderr ../stderrV1.txt
26+
27+
exec git checkout main
28+
exec git merge v1
29+
30+
exec git checkout -b v2
31+
cp ../src/v2.yml rules.yml
32+
exec git commit -am 'v2'
33+
pint.error --no-color ci
34+
! stdout .
35+
cmp stderr ../stderrV2.txt
36+
37+
-- stderrV1.txt --
38+
level=INFO msg="Loading configuration file" path=.pint.hcl
39+
level=INFO msg="Finding all rules to check on current git branch" base=main
40+
level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tags=[] include=[] exclude=[]
41+
-- stderrV2.txt --
42+
level=INFO msg="Loading configuration file" path=.pint.hcl
43+
level=INFO msg="Finding all rules to check on current git branch" base=main
44+
level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tags=[] include=[] exclude=[]
45+
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
46+
level=WARN msg="Using dummy Prometheus uptime metric results with no gaps" name=prom metric=up
47+
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
48+
level=WARN msg="Using dummy Prometheus uptime metric results with no gaps" name=prom metric=up
49+
level=INFO msg="Problems found" Bug=2
50+
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)
51+
8 | expr: up == 0
52+
53+
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)
54+
16 | expr: up == 0
55+
56+
level=ERROR msg="Fatal error" err="problems found"
57+
-- src/v0.yml --
58+
groups:
59+
- name: g1
60+
rules: []
61+
-- src/v1.yml --
62+
groups:
63+
- name: g1
64+
rules:
65+
- alert: DownAlert
66+
# foo
67+
# pint disable promql/series(up)
68+
# bar
69+
expr: up == 0
70+
annotations:
71+
summary: 'Service is down'
72+
labels:
73+
cluster: dev
74+
- record: up:sum
75+
# foo
76+
# pint disable promql/series(up)
77+
# bar
78+
expr: up == 0
79+
labels:
80+
cluster: dev
81+
-- src/v2.yml --
82+
groups:
83+
- name: g1
84+
rules:
85+
- alert: DownAlert
86+
# foo
87+
# pint disable promql/series(xxx)
88+
# bar
89+
expr: up == 0
90+
annotations:
91+
summary: 'Service is down'
92+
labels:
93+
cluster: dev
94+
- record: up:sum
95+
# foo
96+
# bar
97+
expr: up == 0
98+
labels:
99+
cluster: dev
100+
-- src/.pint.hcl --
101+
ci {
102+
baseBranch = "main"
103+
}
104+
prometheus "prom" {
105+
uri = "http://127.0.0.1:7160"
106+
timeout = "5s"
107+
required = true
108+
}

0 commit comments

Comments
 (0)