Skip to content

Commit

Permalink
Merge pull request #898 from cloudflare/rule/duplicate
Browse files Browse the repository at this point in the history
Fix missing rule path check
  • Loading branch information
prymitive authored Mar 8, 2024
2 parents 3b0fa48 + ebb557b commit a27ad9b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
85 changes: 85 additions & 0 deletions cmd/pint/tests/0167_rule_duplicate_symlink.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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:7167

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

cp ../src/v0.yml rules.yml
exec ln -s rules.yml symlink.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

-- 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=prom1 uris=1 uptime=up tags=[] include=["^rules.yml$"] exclude=[]
level=INFO msg="Configured new Prometheus server" name=prom2 uris=1 uptime=up tags=[] include=["^symlink.yml$"] exclude=[]
-- stderrV2.txt --
-- src/v0.yml --
groups:
groups:
- name: g1
rules:
- alert: DownAlert
expr: up == 0
annotations:
summary: 'Service is down'
labels:
cluster: dev
- record: up:sum
expr: up == 0
labels:
cluster: dev
-- src/v1.yml --
groups:
- name: g1
rules:
- alert: DownAlert
expr: up == 0
annotations:
summary: 'Service is down'
labels:
cluster: dev
- record: new:sum
expr: up == 0
- record: up:sum
expr: up == 0
labels:
cluster: dev
-- src/.pint.hcl --
ci {
baseBranch = "main"
}
checks {
disabled = [
"promql/series",
]
}
prometheus "prom1" {
uri = "http://127.0.0.1:7167/1"
timeout = "5s"
required = true
include = ["rules.yml"]
}
prometheus "prom2" {
uri = "http://127.0.0.1:7167/2"
timeout = "5s"
required = true
include = ["symlink.yml"]
}
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
codecov:
token: fa0dae01-b3cf-46b7-b7d2-254e990ac824
require_ci_to_pass: false
notify:
wait_for_ci: false
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.55.0

### Fixed

- Fixed false positive reports from [rule/duplicate](checks/rule/duplicate.md) when
using symlinks.

## v0.54.0

### Added
Expand Down
3 changes: 3 additions & 0 deletions internal/checks/rule_duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (c RuleDuplicateCheck) Check(ctx context.Context, path string, rule parser.
if entry.SourcePath == path && entry.Rule.Lines.First == rule.Lines.First {
continue
}
if !c.prom.IsEnabledForPath(path) {
continue
}
if !c.prom.IsEnabledForPath(entry.SourcePath) {
continue
}
Expand Down

0 comments on commit a27ad9b

Please sign in to comment.