From f93589c8e16efec7c5c9dfa8ec98c68e9e101f62 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 14 Mar 2024 11:26:21 +0000 Subject: [PATCH 1/2] Add more tests --- .github/workflows/benchmark.yml | 1 + .github/workflows/ci.yml | 2 + .github/workflows/examples.yml | 1 + .github/workflows/go-mod-tidy.yml | 1 + .github/workflows/test.yml | 1 + internal/checks/promql_series_test.go | 66 ++++++++++++++++++++++++++- 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d0cc438c..8bb34117 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod + cache: false - name: Fetch test rules run: make -C cmd/pint/bench fetch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e054127a..01012e3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ permissions: jobs: ci: runs-on: ubuntu-latest + if: ${{ github.event.pull_request.head.repo.full_name == 'cloudflare/pint' }} steps: - name: Check out code uses: actions/checkout@v4 @@ -29,6 +30,7 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod + cache: false - name: Compile pint run: make build diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index cef977b1..72a3095f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod + cache: false - name: Build binary run: make diff --git a/.github/workflows/go-mod-tidy.yml b/.github/workflows/go-mod-tidy.yml index bd000409..a6187fde 100644 --- a/.github/workflows/go-mod-tidy.yml +++ b/.github/workflows/go-mod-tidy.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod + cache: false - name: Run go mod tidy run: go mod tidy diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e380f900..0d6702e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod + cache: false - name: Test run: make test diff --git a/internal/checks/promql_series_test.go b/internal/checks/promql_series_test.go index 96bda546..24e06bb0 100644 --- a/internal/checks/promql_series_test.go +++ b/internal/checks/promql_series_test.go @@ -3338,7 +3338,7 @@ func TestSeriesCheck(t *testing.T) { content: ` - alert: foo expr: | - (sum(sometimes{foo!=\"bar\"} or vector(0))) + (sum(sometimes{foo!="bar"} or vector(0))) or (bob > 10) or @@ -3353,7 +3353,7 @@ func TestSeriesCheck(t *testing.T) { content: ` - alert: foo expr: | - (sum(sometimes{foo!=\"bar\"} or vector(0))) + (sum(sometimes{foo!="bar"} or vector(0))) or ((bob > 10) or sum(foo) or vector(1)) `, @@ -3361,6 +3361,68 @@ func TestSeriesCheck(t *testing.T) { prometheus: newSimpleProm, problems: noProblems, }, + { + description: "metric with fallback / 4", + content: ` +- alert: foo + expr: | + ( + sum(sometimes{foo!="bar"}) + or + vector(1) + ) and ( + ((bob > 10) or sum(bar)) + or + notfound > 0 + ) +`, + checker: newSeriesCheck, + prometheus: newSimpleProm, + problems: func(uri string) []checks.Problem { + return []checks.Problem{ + { + Lines: parser.LineRange{ + First: 3, + Last: 12, + }, + Reporter: checks.SeriesCheckName, + Text: noMetricText("prom", uri, "bob", "1w"), + Details: checks.SeriesCheckCommonProblemDetails, + Severity: checks.Bug, + }, + { + Lines: parser.LineRange{ + First: 3, + Last: 12, + }, + Reporter: checks.SeriesCheckName, + Text: noMetricText("prom", uri, "bar", "1w"), + Details: checks.SeriesCheckCommonProblemDetails, + Severity: checks.Bug, + }, + { + Lines: parser.LineRange{ + First: 3, + Last: 12, + }, + Reporter: checks.SeriesCheckName, + Text: noMetricText("prom", uri, "notfound", "1w"), + Details: checks.SeriesCheckCommonProblemDetails, + Severity: checks.Bug, + }, + } + }, + mocks: []*prometheusMock{ + { + conds: []requestCondition{requireQueryPath}, + resp: respondWithEmptyVector(), + }, + { + conds: []requestCondition{requireRangeQueryPath}, + resp: respondWithEmptyMatrix(), + }, + }, + }, } runTests(t, testCases) } From 49a19b899ccfa864d98c2d5e1ada8236d1967db1 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 14 Mar 2024 11:32:40 +0000 Subject: [PATCH 2/2] Fix preview link --- internal/checks/alerts_count.go | 2 +- internal/checks/alerts_count_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/checks/alerts_count.go b/internal/checks/alerts_count.go index 925b5636..d566f0dd 100644 --- a/internal/checks/alerts_count.go +++ b/internal/checks/alerts_count.go @@ -118,7 +118,7 @@ func (c AlertsCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ [] Lines: rule.AlertingRule.Expr.Value.Lines, Reporter: c.Reporter(), Text: fmt.Sprintf("%s would trigger %d alert(s) in the last %s.", promText(c.prom.Name(), qr.URI), alerts, output.HumanizeDuration(delta)), - Details: fmt.Sprintf(`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=1&g0.range_input=%s).`, + Details: fmt.Sprintf(`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=0&g0.range_input=%s).`, qr.PublicURI, url.QueryEscape(rule.AlertingRule.Expr.Value.Value), output.HumanizeDuration(delta), ), Severity: c.severity, diff --git a/internal/checks/alerts_count_test.go b/internal/checks/alerts_count_test.go index dcae2dae..6342616f 100644 --- a/internal/checks/alerts_count_test.go +++ b/internal/checks/alerts_count_test.go @@ -23,7 +23,7 @@ func alertsText(name, uri string, count int, since string) string { func alertsDetails(uri, query, since string) string { return fmt.Sprintf( - `To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=1&g0.range_input=%s).`, + `To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=0&g0.range_input=%s).`, uri, url.QueryEscape(query), since, ) }