-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
366 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ SNI | |
symlink | ||
symlinked | ||
symlinks | ||
TeamCity | ||
templated | ||
Thanos | ||
TLS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
env NO_COLOR=1 | ||
pint.error --no-color lint --min-severity=info --teamcity rules | ||
! stdout . | ||
cmp stderr stderr.txt | ||
|
||
-- stderr.txt -- | ||
level=INFO msg="Finding all rules to check" paths=["rules"] | ||
##teamcity[testSuiteStarted name='alerts/comparison'] | ||
##teamcity[testSuiteStarted name='Warning'] | ||
##teamcity[testStarted name='rules/0001.yml:5'] | ||
##teamcity[testStdErr name='rules/0001.yml:5' out='alert query doesn|'t have any condition, it will always fire if the metric exists'] | ||
##teamcity[testFinished name='rules/0001.yml:5'] | ||
##teamcity[testSuiteFinished name='Warning'] | ||
##teamcity[testSuiteFinished name='alerts/comparison'] | ||
##teamcity[testSuiteStarted name='promql/syntax'] | ||
##teamcity[testSuiteStarted name='Fatal'] | ||
##teamcity[testStarted name='rules/0001.yml:7'] | ||
##teamcity[testFailed name='rules/0001.yml:7' message='' details='syntax error: unexpected identifier "with"'] | ||
##teamcity[testFinished name='rules/0001.yml:7'] | ||
##teamcity[testSuiteFinished name='Fatal'] | ||
##teamcity[testSuiteFinished name='promql/syntax'] | ||
level=INFO msg="Problems found" Fatal=1 Warning=1 | ||
level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" | ||
-- rules/0001.yml -- | ||
groups: | ||
- name: test | ||
rules: | ||
- alert: Example | ||
expr: up | ||
- alert: Example | ||
expr: sum(xxx) with() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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 v1 | ||
cp ../src/a.yml a.yml | ||
exec git add a.yml | ||
exec git commit -am 'v1' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/b.yml b.yml | ||
exec git add b.yml | ||
exec git commit -am 'v2' | ||
|
||
exec git checkout -b v3 | ||
exec git rm a.yml | ||
exec git commit -am 'v3' | ||
|
||
pint.error --no-color ci -t | ||
! 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 using git blame" base=main | ||
level=INFO msg="Problems found" Fatal=1 Warning=1 | ||
##teamcity[testSuiteStarted name='promql/syntax'] | ||
##teamcity[testSuiteStarted name='Fatal'] | ||
##teamcity[testStarted name='b.yml:2'] | ||
##teamcity[testFailed name='b.yml:2' message='' details='syntax error: unexpected identifier "bi"'] | ||
##teamcity[testFinished name='b.yml:2'] | ||
##teamcity[testSuiteFinished name='Fatal'] | ||
##teamcity[testSuiteFinished name='promql/syntax'] | ||
##teamcity[testSuiteStarted name='alerts/comparison'] | ||
##teamcity[testSuiteStarted name='Warning'] | ||
##teamcity[testStarted name='b.yml:4'] | ||
##teamcity[testStdErr name='b.yml:4' out='alert query doesn|'t have any condition, it will always fire if the metric exists'] | ||
##teamcity[testFinished name='b.yml:4'] | ||
##teamcity[testSuiteFinished name='Warning'] | ||
##teamcity[testSuiteFinished name='alerts/comparison'] | ||
level=ERROR msg="Fatal error" err="problems found" | ||
-- src/a.yml -- | ||
- record: rule1 | ||
expr: sum(foo) bi() | ||
-- src/b.yml -- | ||
- record: rule1 | ||
expr: sum(foo) bi() | ||
- alert: rule2 | ||
expr: sum(foo) | ||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package reporter | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cloudflare/pint/internal/checks" | ||
) | ||
|
||
func NewTeamCityReporter(output io.Writer) TeamCityReporter { | ||
return TeamCityReporter{ | ||
output: output, | ||
escaper: strings.NewReplacer( | ||
"'", "|'", | ||
"\n", "|n", | ||
"\r", "|r", | ||
"\\uNNNN", "|0xNNNN", | ||
"|", "||", | ||
"[", "|[", | ||
"]", "|]", | ||
), | ||
} | ||
} | ||
|
||
type TeamCityReporter struct { | ||
output io.Writer | ||
escaper *strings.Replacer | ||
} | ||
|
||
func (tc TeamCityReporter) name(report Report) string { | ||
return fmt.Sprintf("%s:%d", report.ReportedPath, report.Problem.Lines[0]) | ||
} | ||
|
||
func (tc TeamCityReporter) escape(s string) string { | ||
return tc.escaper.Replace(s) | ||
} | ||
|
||
func (tc TeamCityReporter) Submit(summary Summary) error { | ||
var buf strings.Builder | ||
for _, report := range summary.reports { | ||
buf.WriteString("##teamcity[testSuiteStarted name='") | ||
buf.WriteString(report.Problem.Reporter) | ||
buf.WriteString("']\n") | ||
|
||
buf.WriteString("##teamcity[testSuiteStarted name='") | ||
buf.WriteString(report.Problem.Severity.String()) | ||
buf.WriteString("']\n") | ||
|
||
buf.WriteString("##teamcity[testStarted name='") | ||
buf.WriteString(tc.name(report)) | ||
buf.WriteString("']\n") | ||
|
||
if report.Problem.Severity >= checks.Bug { | ||
buf.WriteString("##teamcity[testFailed name='") | ||
buf.WriteString(tc.name(report)) | ||
buf.WriteString("' message='' details='") | ||
buf.WriteString(tc.escape(report.Problem.Text)) | ||
buf.WriteString("']\n") | ||
} else { | ||
buf.WriteString("##teamcity[testStdErr name='") | ||
buf.WriteString(tc.name(report)) | ||
buf.WriteString("' out='") | ||
buf.WriteString(tc.escape(report.Problem.Text)) | ||
buf.WriteString("']\n") | ||
} | ||
|
||
buf.WriteString("##teamcity[testFinished name='") | ||
buf.WriteString(report.ReportedPath) | ||
buf.WriteRune(':') | ||
buf.WriteString(strconv.Itoa(report.Problem.Lines[0])) | ||
buf.WriteString("']\n") | ||
|
||
buf.WriteString("##teamcity[testSuiteFinished name='") | ||
buf.WriteString(report.Problem.Severity.String()) | ||
buf.WriteString("']\n") | ||
|
||
buf.WriteString("##teamcity[testSuiteFinished name='") | ||
buf.WriteString(report.Problem.Reporter) | ||
buf.WriteString("']\n") | ||
|
||
fmt.Fprint(tc.output, buf.String()) | ||
buf.Reset() | ||
} | ||
return nil | ||
} |
Oops, something went wrong.