Skip to content

Commit

Permalink
Add support for file/disable comments
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Nov 11, 2022
1 parent 4d5cde2 commit 97107d4
Show file tree
Hide file tree
Showing 31 changed files with 563 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func checkRules(ctx context.Context, workers int, cfg config.Config, entries []d
Msg("Found alerting rule")
}

checkList := cfg.GetChecksForRule(ctx, entry.SourcePath, entry.Rule)
checkList := cfg.GetChecksForRule(ctx, entry.SourcePath, entry.Rule, entry.DisabledChecks)
for _, check := range checkList {
checkIterationChecks.Inc()
check := check
Expand Down
34 changes: 34 additions & 0 deletions cmd/pint/tests/0103_file_disable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pint.ok -l debug --no-color lint rules
! stdout .
cmp stderr stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=debug msg="File parsed" path=rules/0001.yml rules=1
level=debug msg="Starting query workers" name=prom uri=http://127.0.0.1:7103 workers=16
level=debug msg="Found recording rule" lines=9-10 path=rules/0001.yml record=colo:test1
level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)"] path=rules/0001.yml rule=colo:test1
level=debug msg="Stopping query workers" name=prom uri=http://127.0.0.1:7103
-- rules/0001.yml --
# This should skip all online checks
# pint file/disable promql/series
# pint file/disable promql/rate
#
# pint file/disable alerts/count
# pint file/disable promql/range_query
#

- record: "colo:test1"
expr: sum(foo) without(job)


-- .pint.hcl --
prometheus "prom" {
uri = "http://127.0.0.1:7103"
failover = []
timeout = "5s"
required = true
}
parser {
relaxed = [".*"]
}
35 changes: 35 additions & 0 deletions cmd/pint/tests/0104_file_ignore_prom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
http response prometheus / 502 Bad Gateway
http start prometheus 127.0.0.1:7104

pint.error --no-color lint rules
! stdout .
stderr 'level=error msg="Query returned an error" error="server error: 502" query=/api/v1/status/config uri=http://127.0.0.1:7104'
stderr 'level=error msg="Query returned an error" error="server error: 502" query=/api/v1/status/flags uri=http://127.0.0.1:7104'
stderr 'level=error msg="Query returned an error" error="server error: 502" query=count\(foo\) uri=http://127.0.0.1:7104'
stderr 'level=info msg="Problems found" Bug=3'
-- rules/0001.yml --
# This should skip all online checks
# pint file/disable promql/series
# pint file/disable promql/rate
#
# pint file/disable alerts/count
# pint file/disable promql/range_query
#

- record: "colo:test1"
expr: sum(foo) without(job)

-- rules/0002.yml --
- record: "colo:test2"
expr: sum(foo) without(job)

-- .pint.hcl --
prometheus "prom" {
uri = "http://127.0.0.1:7104"
failover = []
timeout = "5s"
required = true
}
parser {
relaxed = [".*"]
}
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Added `pint_prometheus_cache_evictions_total` metric tracking the number of times
cache results were evicted from query cache.
- Allow disabling individual checks for the entire file using
`# pint file/disable ...` comments.

### Changed

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/alerts/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable alerts/annotation`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable alerts/annotation`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/alerts/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable alerts/comparison`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable alerts/comparison`
7 changes: 6 additions & 1 deletion docs/checks/alerts/count.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable alerts/count`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable alerts/count`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/alerts/for.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable alerts/for`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable alerts/for`
7 changes: 6 additions & 1 deletion docs/checks/alerts/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable alerts/template`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable alerts/template`
2 changes: 1 addition & 1 deletion docs/checks/ignore/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ grand_parent: Documentation
# ignore/file

You will see this check reports for files that are excludes from pint using a
`file/ignore` comment.
`ignore/file` comment.
See this [page](../../ignoring.md) for details on how such comments work.

Those reports are informational to make it obvious that pint didn't run any
Expand Down
7 changes: 6 additions & 1 deletion docs/checks/promql/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/aggregate`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/aggregate`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/promql/fragile.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/fragile`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/fragile`
7 changes: 6 additions & 1 deletion docs/checks/promql/range_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/range_query`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/range_query`

Expand Down
8 changes: 7 additions & 1 deletion docs/checks/promql/rate.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:

You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/rate`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/rate`

Expand Down
8 changes: 7 additions & 1 deletion docs/checks/promql/regexp.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.

You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/regexp`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/regexp`
7 changes: 6 additions & 1 deletion docs/checks/promql/series.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/series`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/series`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/promql/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/syntax`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/syntax`
7 changes: 6 additions & 1 deletion docs/checks/promql/vector_matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable promql/vector_matching`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable promql/vector_matching`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/query/cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable query/cost`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable query/cost`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/rule/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it:
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable rule/label`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable rule/label`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/rule/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable rule/link`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable rule/link`

Expand Down
7 changes: 6 additions & 1 deletion docs/checks/rule/reject.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ checks {
}
```

Or you can disable it per rule by adding a comment to it.
You can also disable it for all rules inside given file by adding
a comment anywhere in that file. Example:

`# pint file/disable rule/reject`

Or you can disable it per rule by adding a comment to it. Example:

`# pint disable rule/reject`

Expand Down
7 changes: 7 additions & 0 deletions docs/ignoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ checks {
}
```

## Disabling invididual checks for specific files

To disable individual check for a specific rule use `# pint file/disable ...` comments
anywhere in the file. This will disable given check for all rules in that file.

See each individual [check](checks/index.md) documentation for details.

## Disabling individual checks for specific rules

To disable individual check for a specific rule use `# pint disable ...` comments.
Expand Down
Loading

0 comments on commit 97107d4

Please sign in to comment.