From a795ccca60782a38e73aa00964e92c4ddd88712f Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 12 Oct 2023 09:42:41 +0100 Subject: [PATCH] Use log/slog instead of zerolog --- cmd/pint/ci.go | 35 +- cmd/pint/lint.go | 11 +- cmd/pint/logger.go | 34 +- cmd/pint/main.go | 9 +- cmd/pint/main_test.go | 7 +- cmd/pint/scan.go | 30 +- cmd/pint/tests/0001_match_path.txt | 6 +- cmd/pint/tests/0002_nothing_to_lint.txt | 2 +- cmd/pint/tests/0003_lint_workdir.txt | 7 +- cmd/pint/tests/0004_fail_invalid_yaml.txt | 8 +- cmd/pint/tests/0005_false_positive.txt | 2 +- cmd/pint/tests/0006_rr_labels.txt | 6 +- cmd/pint/tests/0007_alerts.txt | 6 +- .../tests/0008_recording_rule_prometheus.txt | 6 +- .../tests/0009_alerting_rule_prometheus.txt | 6 +- cmd/pint/tests/0010_syntax_check.txt | 8 +- cmd/pint/tests/0011_ignore_rules.txt | 6 +- cmd/pint/tests/0012_issue_20.txt | 7 +- cmd/pint/tests/0013_issue49_1.txt | 4 +- cmd/pint/tests/0014_issue49_2.txt | 2 +- cmd/pint/tests/0017_issue69.txt | 2 +- cmd/pint/tests/0018_match_alerting.txt | 14 +- cmd/pint/tests/0019_match_recording.txt | 14 +- cmd/pint/tests/0020_ignore_kind.txt | 14 +- cmd/pint/tests/0021_ignore_all.txt | 4 +- cmd/pint/tests/0022_ignore_multi.txt | 4 +- cmd/pint/tests/0023_enabled_checks.txt | 8 +- cmd/pint/tests/0024_color_output.txt | 7 +- cmd/pint/tests/0025_config.txt | 2 +- cmd/pint/tests/0026_aggregate_empty_name.txt | 4 +- cmd/pint/tests/0027_ci_branch.txt | 6 +- cmd/pint/tests/0028_ci_git_error.txt | 13 +- cmd/pint/tests/0029_ci_too_many_commits.txt | 4 +- cmd/pint/tests/0031_ci_bitbucket.txt | 8 +- cmd/pint/tests/0032_ci_github.txt | 2 +- cmd/pint/tests/0033_ci_github_multi.txt | 2 +- cmd/pint/tests/0035_bad_loglevel.txt | 5 +- cmd/pint/tests/0036_ci_basebranch.txt | 4 +- cmd/pint/tests/0037_disable_checks.txt | 22 +- cmd/pint/tests/0038_disable_checks_regex.txt | 4 +- cmd/pint/tests/0039_prom_selected_path.txt | 22 +- cmd/pint/tests/0040_rule_match_label.txt | 22 +- cmd/pint/tests/0041_watch.txt | 22 +- cmd/pint/tests/0043_watch_cancel.txt | 6 +- cmd/pint/tests/0044_parse_error.txt | 2 +- cmd/pint/tests/0045_parse_no_query.txt | 2 +- .../tests/0051_watch_severity_invalid.txt | 2 +- cmd/pint/tests/0052_match_multiple.txt | 14 +- cmd/pint/tests/0053_ignore_multiple.txt | 12 +- cmd/pint/tests/0055_prometheus_failover.txt | 4 +- cmd/pint/tests/0056_prometheus_required.txt | 6 +- cmd/pint/tests/0058_templated_check.txt | 6 +- .../0059_templated_check_bad_template.txt | 4 +- cmd/pint/tests/0060_ci_noop.txt | 6 +- cmd/pint/tests/0061_lint_workers_zero.txt | 2 +- cmd/pint/tests/0062_lint_no_args.txt | 2 +- cmd/pint/tests/0063_lint_offline.txt | 2 +- cmd/pint/tests/0064_watch_no_path.txt | 2 +- cmd/pint/tests/0065_ci_include.txt | 14 +- cmd/pint/tests/0066_lint_owner.txt | 6 +- cmd/pint/tests/0067_relaxed.txt | 6 +- cmd/pint/tests/0068_skip_ci.txt | 10 +- .../tests/0069_bitbucket_skip_unmodified.txt | 2 +- cmd/pint/tests/0070_bitbucket_strict.txt | 12 +- cmd/pint/tests/0071_ci_owner.txt | 2 +- .../0072_bitbucket_move_bug_to_modified.txt | 14 +- cmd/pint/tests/0073_lint_k8s.txt | 6 +- cmd/pint/tests/0074_strict_error.txt | 4 +- cmd/pint/tests/0075_ci_strict.txt | 10 +- cmd/pint/tests/0076_ci_group_errors.txt | 2 +- cmd/pint/tests/0077_strict_error_owner.txt | 4 +- cmd/pint/tests/0078_repeated_group.txt | 4 +- .../0079_check_promql_series_invalid.txt | 4 +- cmd/pint/tests/0080_lint_online.txt | 8 +- cmd/pint/tests/0081_rulefmt.txt | 4 +- cmd/pint/tests/0082_ci_base_branch_flag.txt | 4 +- cmd/pint/tests/0083_github_action.txt | 12 +- .../tests/0084_github_action_override.txt | 6 +- cmd/pint/tests/0085_github_no_envs.txt | 2 +- .../tests/0086_rulefmt_ignored_errors.txt | 4 +- cmd/pint/tests/0087_dedup.txt | 4 +- cmd/pint/tests/0088_rule_link.txt | 4 +- cmd/pint/tests/0089_lint_min_severity_bug.txt | 4 +- .../tests/0090_lint_min_severity_info.txt | 2 +- .../tests/0091_lint_min_severity_invalid.txt | 2 +- cmd/pint/tests/0092_dir_symlink.txt | 6 +- .../tests/0093_ci_bitbucket_ignore_file.txt | 16 +- cmd/pint/tests/0094_rule_file_symlink_bb.txt | 12 +- cmd/pint/tests/0095_rulefmt_symlink.txt | 14 +- cmd/pint/tests/0096_bad_symlink.txt | 2 +- .../tests/0097_rule_file_symlink_error.txt | 2 +- cmd/pint/tests/0098_rule_file_symlink_gh.txt | 2 +- cmd/pint/tests/0099_symlink_outside_glob.txt | 8 +- cmd/pint/tests/0100_ci_alerts_count.txt | 4 +- cmd/pint/tests/0103_file_disable.txt | 12 +- cmd/pint/tests/0104_file_ignore_prom.txt | 8 +- cmd/pint/tests/0105_too_many_samples.txt | 4 +- cmd/pint/tests/0106_ci_git_branch_error.txt | 4 +- .../tests/0107_ci_git_invalid_log_level.txt | 5 +- cmd/pint/tests/0108_rule_duplicate.txt | 16 +- ..._rule_duplicate_multiple_proms_include.txt | 2 +- ..._rule_duplicate_multiple_proms_exclude.txt | 2 +- cmd/pint/tests/0111_snooze.txt | 10 +- cmd/pint/tests/0112_expired_snooze.txt | 12 +- cmd/pint/tests/0113_config_env_expand.txt | 2 +- .../tests/0114_config_env_expand_error.txt | 4 +- cmd/pint/tests/0115_file_disable_tag.txt | 12 +- cmd/pint/tests/0116_file_snooze.txt | 16 +- cmd/pint/tests/0117_ci_dir_move_blame.txt | 2 +- cmd/pint/tests/0118_ci_dir_move_branch.txt | 2 +- cmd/pint/tests/0119_ci_fail_on_warning.txt | 2 +- cmd/pint/tests/0120_ci_fail_on_invalid.txt | 2 +- cmd/pint/tests/0121_rule_for.txt | 6 +- cmd/pint/tests/0122_lint_owner_allowed.txt | 6 +- cmd/pint/tests/0123_ci_owner_allowed.txt | 2 +- cmd/pint/tests/0124_ci_base_branch_flag.txt | 6 +- cmd/pint/tests/0125_lint_fail_on_warning.txt | 4 +- cmd/pint/tests/0126_lint_fail_on_invalid.txt | 2 +- ...127_lint_fail_on_fatal_but_got_warning.txt | 4 +- .../tests/0128_lint_fail_on_warning_only.txt | 6 +- cmd/pint/tests/0133_tls_certs_bad.txt | 4 +- .../tests/0134_ci_base_branch_flag_path.txt | 13 +- .../tests/0135_ci_base_branch_config_path.txt | 13 +- cmd/pint/tests/0136_annotation_regex_key.txt | 4 +- .../tests/0137_annotation_regex_key_fail.txt | 6 +- .../0138_annoation_regex_key_required.txt | 6 +- cmd/pint/tests/0139_ci_exclude.txt | 14 +- cmd/pint/tests/0140_ci_include_exclude.txt | 14 +- cmd/pint/tests/0141_empty_keys.txt | 4 +- cmd/pint/tests/0142_keep_firing_for.txt | 4 +- cmd/pint/tests/0143_keep_firing_for.txt | 6 +- cmd/pint/watch.go | 30 +- go.mod | 1 - go.sum | 6 - internal/checks/alerts_count.go | 4 +- internal/checks/base_test.go | 21 +- internal/checks/promql_aggregation.go | 7 +- internal/checks/promql_series.go | 103 +- internal/checks/rule_link.go | 13 +- .../config/__snapshots__/config_test.snap | 1920 ++++++++--------- internal/config/config.go | 6 +- internal/config/rule.go | 24 +- internal/discovery/discovery.go | 29 +- internal/discovery/git_blame.go | 15 +- internal/discovery/git_branch.go | 75 +- internal/discovery/symlinks.go | 5 +- internal/git/changes.go | 18 +- internal/git/git.go | 9 +- internal/log/handler.go | 141 ++ internal/log/log.go | 31 + internal/parser/utils/absent.go | 5 +- internal/parser/utils/aggregation.go | 7 +- internal/parser/utils/rate.go | 5 +- internal/parser/utils/sum.go | 5 +- internal/promapi/config.go | 8 +- internal/promapi/errors.go | 4 +- internal/promapi/flags.go | 8 +- internal/promapi/metadata.go | 13 +- internal/promapi/prometheus.go | 27 +- internal/promapi/query.go | 15 +- internal/promapi/range.go | 25 +- internal/reporter/bitbucket.go | 24 +- internal/reporter/bitbucket_test.go | 5 +- internal/reporter/console.go | 16 +- internal/reporter/github.go | 16 +- internal/reporter/github_test.go | 5 +- 166 files changed, 1900 insertions(+), 1692 deletions(-) create mode 100644 internal/log/handler.go create mode 100644 internal/log/log.go diff --git a/cmd/pint/ci.go b/cmd/pint/ci.go index ef080a7b..487d8005 100644 --- a/cmd/pint/ci.go +++ b/cmd/pint/ci.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "log/slog" "os" "regexp" "strconv" @@ -15,7 +16,6 @@ import ( "github.com/cloudflare/pint/internal/git" "github.com/cloudflare/pint/internal/reporter" - "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" ) @@ -82,9 +82,9 @@ func actionCI(c *cli.Context) error { if err != nil { return fmt.Errorf("failed to get the name of current branch") } - log.Debug().Str("current", currentBranch).Str("base", baseBranch).Msg("Got branch information") + slog.Debug("Got branch information", slog.String("base", baseBranch), slog.String("current", currentBranch)) if currentBranch == strings.Split(baseBranch, "/")[len(strings.Split(baseBranch, "/"))-1] { - log.Info().Str("branch", currentBranch).Msg("Running from base branch, skipping checks") + slog.Info("Running from base branch, skipping checks", slog.String("branch", currentBranch)) return nil } @@ -176,15 +176,15 @@ func actionCI(c *cli.Context) error { } problemsFound := false - bySeverity := map[string]interface{}{} // interface{} is needed for log.Fields() - for s, c := range summary.CountBySeverity() { + bySeverity := summary.CountBySeverity() + for s := range bySeverity { if s >= minSeverity { problemsFound = true + break } - bySeverity[s.String()] = c } if len(bySeverity) > 0 { - log.Info().Fields(bySeverity).Msg("Problems found") + slog.Info("Problems found", logSeverityCounters(bySeverity)...) } if err := submitReports(reps, summary); err != nil { @@ -198,6 +198,15 @@ func actionCI(c *cli.Context) error { return nil } +func logSeverityCounters(src map[checks.Severity]int) (attrs []any) { + for _, s := range []checks.Severity{checks.Fatal, checks.Bug, checks.Warning, checks.Information} { + if c, ok := src[s]; ok { + attrs = append(attrs, slog.Attr{Key: s.String(), Value: slog.IntValue(c)}) + } + } + return attrs +} + func detectCI(cfg *config.CI) *config.CI { var isNil, isDirty bool @@ -209,7 +218,7 @@ func detectCI(cfg *config.CI) *config.CI { if bb := os.Getenv("GITHUB_BASE_REF"); bb != "" { isDirty = true cfg.BaseBranch = bb - log.Debug().Str("branch", bb).Msg("got base branch from GITHUB_BASE_REF env variable") + slog.Debug("got base branch from GITHUB_BASE_REF env variable", slog.String("branch", bb)) } if isNil && !isDirty { @@ -243,7 +252,7 @@ func detectGithubActions(gh *config.GitHub) *config.GitHub { os.Getenv("GITHUB_REF") != "" { parts := strings.Split(os.Getenv("GITHUB_REF"), "/") if len(parts) >= 4 { - log.Info().Str("pr", parts[2]).Msg("Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable") + slog.Info("Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable", slog.String("pr", parts[2])) os.Setenv("GITHUB_PULL_REQUEST_NUMBER", parts[2]) } } @@ -259,12 +268,12 @@ func detectGithubActions(gh *config.GitHub) *config.GitHub { parts := strings.SplitN(repo, "/", 2) if len(parts) == 2 { if gh.Owner == "" { - log.Info().Str("owner", parts[0]).Msg("Setting repository owner from GITHUB_REPOSITORY env variable") + slog.Info("Setting repository owner from GITHUB_REPOSITORY env variable", slog.String("owner", parts[0])) gh.Owner = parts[0] isDirty = true } if gh.Repo == "" { - log.Info().Str("repo", parts[1]).Msg("Setting repository name from GITHUB_REPOSITORY env variable") + slog.Info("Setting repository name from GITHUB_REPOSITORY env variable", slog.String("repo", parts[1])) gh.Repo = parts[1] isDirty = true } @@ -273,11 +282,11 @@ func detectGithubActions(gh *config.GitHub) *config.GitHub { if api := os.Getenv("GITHUB_API_URL"); api != "" { if gh.BaseURI == "" { - log.Info().Str("baseuri", api).Msg("Setting repository base URI from GITHUB_API_URL env variable") + slog.Info("Setting repository base URI from GITHUB_API_URL env variable", slog.String("baseuri", api)) gh.BaseURI = api } if gh.UploadURI == "" { - log.Info().Str("uploaduri", api).Msg("Setting repository upload URI from GITHUB_API_URL env variable") + slog.Info("Setting repository upload URI from GITHUB_API_URL env variable", slog.String("uploaduri", api)) gh.UploadURI = api } } diff --git a/cmd/pint/lint.go b/cmd/pint/lint.go index 85d524dd..f51aea0f 100644 --- a/cmd/pint/lint.go +++ b/cmd/pint/lint.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "log/slog" "os" "regexp" @@ -11,7 +12,6 @@ import ( "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/reporter" - "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" ) @@ -87,25 +87,24 @@ func actionLint(c *cli.Context) error { return err } - bySeverity := map[string]interface{}{} // interface{} is needed for log.Fields() + bySeverity := summary.CountBySeverity() var problems, hiddenProblems, failProblems int - for s, c := range summary.CountBySeverity() { + for s, c := range bySeverity { if s >= failOn { failProblems++ } if s < minSeverity { hiddenProblems++ } - bySeverity[s.String()] = c if s >= checks.Bug { problems += c } } if len(bySeverity) > 0 { - log.Info().Fields(bySeverity).Msg("Problems found") + slog.Info("Problems found", logSeverityCounters(bySeverity)...) } if hiddenProblems > 0 { - log.Info().Msgf("%d problem(s) not visible because of --%s=%s flag", hiddenProblems, minSeverityFlag, c.String(minSeverityFlag)) + slog.Info(fmt.Sprintf("%d problem(s) not visible because of --%s=%s flag", hiddenProblems, minSeverityFlag, c.String(minSeverityFlag))) } if failProblems > 0 { diff --git a/cmd/pint/logger.go b/cmd/pint/logger.go index 0184743a..33438301 100644 --- a/cmd/pint/logger.go +++ b/cmd/pint/logger.go @@ -4,37 +4,21 @@ import ( "fmt" "os" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" + "github.com/cloudflare/pint/internal/log" ) -func msgFormatter(msg interface{}) string { - return fmt.Sprintf("msg=%q", msg) -} - -func lvlFormatter(level interface{}) string { - if level == nil { - return "" - } - return fmt.Sprintf("level=%s", level) -} - func initLogger(level string, noColor bool) error { - log.Logger = log.Logger.Output(zerolog.ConsoleWriter{ - Out: os.Stderr, - NoColor: noColor, - FormatLevel: lvlFormatter, - FormatMessage: msgFormatter, - FormatTimestamp: func(interface{}) string { - return "" - }, - }) - - l, err := zerolog.ParseLevel(level) + l, err := log.ParseLevel(level) if err != nil { return fmt.Errorf("'%s' is not a valid log level", level) } - zerolog.SetGlobalLevel(l) + + nc := os.Getenv("NO_COLOR") + if nc != "" && nc != "0" { + noColor = true + } + + log.Setup(l, noColor) return nil } diff --git a/cmd/pint/main.go b/cmd/pint/main.go index eec0d237..8192bdb0 100644 --- a/cmd/pint/main.go +++ b/cmd/pint/main.go @@ -2,10 +2,9 @@ package main import ( "fmt" + "log/slog" "os" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" "go.uber.org/automaxprocs/maxprocs" @@ -45,7 +44,7 @@ func newApp() *cli.App { &cli.StringFlag{ Name: logLevelFlag, Aliases: []string{"l"}, - Value: zerolog.InfoLevel.String(), + Value: slog.LevelInfo.String(), Usage: "Log level", }, &cli.BoolFlag{ @@ -98,7 +97,7 @@ func actionSetup(c *cli.Context) (meta actionMeta, err error) { undo, err := maxprocs.Set() defer undo() if err != nil { - log.Error().Err(err).Msg("failed to set GOMAXPROCS") + slog.Error("failed to set GOMAXPROCS", slog.Any("err", err)) } meta.workers = c.Int(workersFlag) @@ -122,7 +121,7 @@ func main() { app := newApp() err := app.Run(os.Args) if err != nil { - log.Fatal().Err(err).Msg("Execution completed with error(s)") + slog.Error("Execution completed with error(s)", slog.Any("err", err)) os.Exit(1) } } diff --git a/cmd/pint/main_test.go b/cmd/pint/main_test.go index fcd403c9..90b2e865 100644 --- a/cmd/pint/main_test.go +++ b/cmd/pint/main_test.go @@ -9,6 +9,7 @@ import ( "encoding/pem" "errors" "fmt" + "log/slog" "math/big" "net" "net/http" @@ -20,8 +21,6 @@ import ( "time" "github.com/rogpeppe/go-internal/testscript" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" ) // mock command that fails tests if error is returned @@ -29,7 +28,7 @@ func mockMainShouldSucceed() int { app := newApp() err := app.Run(os.Args) if err != nil { - log.WithLevel(zerolog.FatalLevel).Err(err).Msg("Fatal error") + slog.Error("Fatal error", slog.Any("err", err)) return 1 } return 0 @@ -40,7 +39,7 @@ func mockMainShouldFail() int { app := newApp() err := app.Run(os.Args) if err != nil { - log.WithLevel(zerolog.FatalLevel).Err(err).Msg("Fatal error") + slog.Error("Fatal error", slog.Any("err", err)) return 0 } fmt.Fprintf(os.Stderr, "expected an error but none was returned\n") diff --git a/cmd/pint/scan.go b/cmd/pint/scan.go index ce9699bf..2c607c89 100644 --- a/cmd/pint/scan.go +++ b/cmd/pint/scan.go @@ -3,13 +3,13 @@ package main import ( "context" "errors" + "log/slog" "regexp" "strconv" "sync" "time" "github.com/prometheus/prometheus/model/rulefmt" - "github.com/rs/zerolog/log" "go.uber.org/atomic" "github.com/cloudflare/pint/internal/checks" @@ -93,19 +93,19 @@ func checkRules(ctx context.Context, workers int, cfg config.Config, entries []d case entry.PathError == nil && entry.Rule.Error.Err == nil: if entry.Rule.RecordingRule != nil { rulesParsedTotal.WithLabelValues(config.RecordingRuleType).Inc() - log.Debug(). - Str("path", entry.SourcePath). - Str("record", entry.Rule.RecordingRule.Record.Value.Value). - Str("lines", output.FormatLineRangeString(entry.Rule.Lines())). - Msg("Found recording rule") + slog.Debug("Found recording rule", + slog.String("path", entry.SourcePath), + slog.String("record", entry.Rule.RecordingRule.Record.Value.Value), + slog.String("lines", output.FormatLineRangeString(entry.Rule.Lines())), + ) } if entry.Rule.AlertingRule != nil { rulesParsedTotal.WithLabelValues(config.AlertingRuleType).Inc() - log.Debug(). - Str("path", entry.SourcePath). - Str("alert", entry.Rule.AlertingRule.Alert.Value.Value). - Str("lines", output.FormatLineRangeString(entry.Rule.Lines())). - Msg("Found alerting rule") + slog.Debug("Found alerting rule", + slog.String("path", entry.SourcePath), + slog.String("alert", entry.Rule.AlertingRule.Alert.Value.Value), + slog.String("lines", output.FormatLineRangeString(entry.Rule.Lines())), + ) } checkList := cfg.GetChecksForRule(ctx, entry.SourcePath, entry.Rule, entry.DisabledChecks) @@ -121,10 +121,10 @@ func checkRules(ctx context.Context, workers int, cfg config.Config, entries []d } default: if entry.Rule.Error.Err != nil { - log.Debug(). - Str("path", entry.SourcePath). - Str("lines", output.FormatLineRangeString(entry.Rule.Lines())). - Msg("Found invalid rule") + slog.Debug("Found invalid rule", + slog.String("path", entry.SourcePath), + slog.String("lines", output.FormatLineRangeString(entry.Rule.Lines())), + ) rulesParsedTotal.WithLabelValues(config.InvalidRuleType).Inc() } jobs <- scanJob{entry: entry, allEntries: entries, check: nil} diff --git a/cmd/pint/tests/0001_match_path.txt b/cmd/pint/tests/0001_match_path.txt index 64284bfa..a442aa5f 100644 --- a/cmd/pint/tests/0001_match_path.txt +++ b/cmd/pint/tests/0001_match_path.txt @@ -3,12 +3,12 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0002.yml:2 Bug: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 2 | expr: sum(foo) without(job) -level=info msg="Problems found" Bug=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - record: "colo:test1" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0002_nothing_to_lint.txt b/cmd/pint/tests/0002_nothing_to_lint.txt index 787e347d..da1f46e8 100644 --- a/cmd/pint/tests/0002_nothing_to_lint.txt +++ b/cmd/pint/tests/0002_nothing_to_lint.txt @@ -4,4 +4,4 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="no matching files" +level=ERROR msg="Fatal error" err="no matching files" diff --git a/cmd/pint/tests/0003_lint_workdir.txt b/cmd/pint/tests/0003_lint_workdir.txt index 82876791..4330843c 100644 --- a/cmd/pint/tests/0003_lint_workdir.txt +++ b/cmd/pint/tests/0003_lint_workdir.txt @@ -1,9 +1,10 @@ +env NO_COLOR=1 pint.error --no-color lint --min-severity=info rules ! stdout . cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:2 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 2 | expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name) @@ -60,8 +61,8 @@ rules/0003.yaml:58-61 Information: using the value of rate(errors[5m]) inside th .. 61 | summary: 'error rate: {{ $value }}' -level=info msg="Problems found" Bug=2 Fatal=1 Information=1 Warning=10 -level=fatal msg="Fatal error" error="found 2 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 Bug=2 Warning=10 Information=1 +level=ERROR msg="Fatal error" err="found 2 problem(s) with severity Bug or higher" -- rules/0001.yml -- - record: colo_job:fl_cf_html_bytes_in:rate10m expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name) diff --git a/cmd/pint/tests/0004_fail_invalid_yaml.txt b/cmd/pint/tests/0004_fail_invalid_yaml.txt index ece6f6c1..b885b17b 100644 --- a/cmd/pint/tests/0004_fail_invalid_yaml.txt +++ b/cmd/pint/tests/0004_fail_invalid_yaml.txt @@ -3,16 +3,16 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=error msg="Failed to parse file content" error="yaml: line 4: did not find expected key" lines=1-7 path=rules/bad.yaml +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Failed to parse file content" err="yaml: line 4: did not find expected key" path=rules/bad.yaml lines=1-7 rules/bad.yaml:4 Fatal: did not find expected key (yaml/parse) 4 | rules/ok.yml:5 Fatal: syntax error: unclosed left bracket (promql/syntax) 5 | expr: sum(foo[5m) -level=info msg="Problems found" Fatal=2 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=2 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/ok.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0005_false_positive.txt b/cmd/pint/tests/0005_false_positive.txt index 0cd1e881..a094bc74 100644 --- a/cmd/pint/tests/0005_false_positive.txt +++ b/cmd/pint/tests/0005_false_positive.txt @@ -3,7 +3,7 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yml -- - record: "colo:test1" expr: topk(6, sum(rate(edgeworker_subrequest_errorCount{cordon="free"}[5m])) BY (zoneId,job)) diff --git a/cmd/pint/tests/0006_rr_labels.txt b/cmd/pint/tests/0006_rr_labels.txt index 2379861c..4339b602 100644 --- a/cmd/pint/tests/0006_rr_labels.txt +++ b/cmd/pint/tests/0006_rr_labels.txt @@ -3,12 +3,12 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:8 Fatal: incomplete rule, no alert or record key (yaml/parse) 8 | - expr: sum(foo) -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0007_alerts.txt b/cmd/pint/tests/0007_alerts.txt index e46db458..5d12da6a 100644 --- a/cmd/pint/tests/0007_alerts.txt +++ b/cmd/pint/tests/0007_alerts.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:1-2 Bug: url annotation is required (alerts/annotation) 1 | - alert: Always 2 | expr: up @@ -47,8 +47,8 @@ rules/0002.yml:11 Bug: using $value in labels will generate a new alert on every rules/0002.yml:12 Bug: using .Value in labels will generate a new alert on every value change, move it to annotations (alerts/template) 12 | val: '{{ .Value|humanizeDuration }}' -level=info msg="Problems found" Bug=5 Fatal=4 Warning=4 -level=fatal msg="Fatal error" error="found 2 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=4 Bug=5 Warning=4 +level=ERROR msg="Fatal error" err="found 2 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: Always expr: up diff --git a/cmd/pint/tests/0008_recording_rule_prometheus.txt b/cmd/pint/tests/0008_recording_rule_prometheus.txt index df705ee0..2ba93e10 100644 --- a/cmd/pint/tests/0008_recording_rule_prometheus.txt +++ b/cmd/pint/tests/0008_recording_rule_prometheus.txt @@ -3,15 +3,15 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:5 Bug: instance label should be removed when aggregating "^colo(?:_.+)?:.+$" rules, remove instance from by() (promql/aggregate) 5 | expr: sum by (instance) (http_inprogress_requests) rules/0001.yml:5 Warning: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 5 | expr: sum by (instance) (http_inprogress_requests) -level=info msg="Problems found" Bug=1 Warning=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=1 Warning=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- groups: - name: example diff --git a/cmd/pint/tests/0009_alerting_rule_prometheus.txt b/cmd/pint/tests/0009_alerting_rule_prometheus.txt index 0630d4b2..5d676f16 100644 --- a/cmd/pint/tests/0009_alerting_rule_prometheus.txt +++ b/cmd/pint/tests/0009_alerting_rule_prometheus.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:11-13 Bug: link annotation is required (alerts/annotation) 11 | annotations: 12 | summary: "Instance {{ $labels.instance }} down" @@ -17,8 +17,8 @@ rules/0001.yml:19-21 Bug: link annotation is required (alerts/annotation) 20 | summary: "High request latency on {{ $labels.instance }}" 21 | description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)" -level=info msg="Problems found" Bug=2 Warning=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=2 Warning=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- groups: - name: example diff --git a/cmd/pint/tests/0010_syntax_check.txt b/cmd/pint/tests/0010_syntax_check.txt index 5dca09bf..c3e41ff4 100644 --- a/cmd/pint/tests/0010_syntax_check.txt +++ b/cmd/pint/tests/0010_syntax_check.txt @@ -3,13 +3,13 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=error msg="Failed to parse file content" error="yaml: line 6: did not find expected '-' indicator" lines=1-12 path=rules/1.yaml +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Failed to parse file content" err="yaml: line 6: did not find expected '-' indicator" path=rules/1.yaml lines=1-12 rules/1.yaml:6 Fatal: did not find expected '-' indicator (yaml/parse) 6 | -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/1.yaml -- - alert: Good expr: up == 0 diff --git a/cmd/pint/tests/0011_ignore_rules.txt b/cmd/pint/tests/0011_ignore_rules.txt index f83be1ab..4b3ca603 100644 --- a/cmd/pint/tests/0011_ignore_rules.txt +++ b/cmd/pint/tests/0011_ignore_rules.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yaml:5 Fatal: syntax error: unexpected right parenthesis ')' (promql/syntax) 5 | expr: sum(errors_total) by ) @@ -19,8 +19,8 @@ rules/1.yaml:33 Warning: alert query doesn't have any condition, it will always rules/1.yaml:33 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 33 | expr: sum(errors_total) without(job) -level=info msg="Problems found" Fatal=2 Warning=3 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=2 Warning=3 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/1.yaml -- - record: disabled expr: sum(errors_total) by ) # pint disable promql/syntax diff --git a/cmd/pint/tests/0012_issue_20.txt b/cmd/pint/tests/0012_issue_20.txt index ad001e59..ece024b6 100644 --- a/cmd/pint/tests/0012_issue_20.txt +++ b/cmd/pint/tests/0012_issue_20.txt @@ -3,14 +3,15 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=warn msg="Tried to read more lines than present in the source file, this is likely due to '\n' usage in some rules, see https://github.com/cloudflare/pint/issues/20 for details" path=rules/1.yaml +level=INFO msg="Loading configuration file" path=.pint.hcl +level=WARN msg="Tried to read more lines than present in the source file, this is likely due to ' +' usage in some rules, see https://github.com/cloudflare/pint/issues/20 for details" path=rules/1.yaml rules/1.yaml:9-13 Warning: runbook_url annotation is required (alerts/annotation) 9 | annotations: 10 | summary: "HAProxy server healthcheck failure (instance {{ $labels.instance }})" 11 | description: "Some server healthcheck are failing on {{ $labels.server }}\n VALUE = {{ $value }}\n LABELS: {{ $labels }}" -level=info msg="Problems found" Warning=1 +level=INFO msg="Problems found" Warning=1 -- rules/1.yaml -- groups: - name: "haproxy.api_server.rules" diff --git a/cmd/pint/tests/0013_issue49_1.txt b/cmd/pint/tests/0013_issue49_1.txt index dee573f2..a6f1ee40 100644 --- a/cmd/pint/tests/0013_issue49_1.txt +++ b/cmd/pint/tests/0013_issue49_1.txt @@ -3,5 +3,5 @@ pint.error --no-color --config not_existed_config.hcl lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=not_existed_config.hcl -level=fatal msg="Fatal error" error="failed to load config file \"not_existed_config.hcl\": : Configuration file not found; The configuration file not_existed_config.hcl does not exist." +level=INFO msg="Loading configuration file" path=not_existed_config.hcl +level=ERROR msg="Fatal error" err="failed to load config file \"not_existed_config.hcl\": : Configuration file not found; The configuration file not_existed_config.hcl does not exist." diff --git a/cmd/pint/tests/0014_issue49_2.txt b/cmd/pint/tests/0014_issue49_2.txt index 947b4708..aff0d574 100644 --- a/cmd/pint/tests/0014_issue49_2.txt +++ b/cmd/pint/tests/0014_issue49_2.txt @@ -3,7 +3,7 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yaml -- - record: down expr: up == 0 diff --git a/cmd/pint/tests/0017_issue69.txt b/cmd/pint/tests/0017_issue69.txt index f1309811..f564bfec 100644 --- a/cmd/pint/tests/0017_issue69.txt +++ b/cmd/pint/tests/0017_issue69.txt @@ -4230,7 +4230,7 @@ rules/template.yml:4-5 Bug: severity label is required (rule/label) 4 | - alert: Test Alert 2 5 | expr: up == 0 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- copy.sh -- for I in `seq 1 263` ; do cp rules/template.yml rules/$I.yml ; done diff --git a/cmd/pint/tests/0018_match_alerting.txt b/cmd/pint/tests/0018_match_alerting.txt index a0f38646..0dd2ead9 100644 --- a/cmd/pint/tests/0018_match_alerting.txt +++ b/cmd/pint/tests/0018_match_alerting.txt @@ -3,19 +3,19 @@ pint.ok --no-color -l debug lint rules 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=2 -level=debug msg="Found recording rule" lines=1-2 path=rules/0001.yml record=colo:recording -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:recording -level=debug msg="Found alerting rule" alert=colo:alerting lines=4-5 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:recording +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting rules/0001.yml:5 Warning: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison) 5 | expr: sum(bar) without(job) rules/0001.yml:5 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 5 | expr: sum(bar) without(job) -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0019_match_recording.txt b/cmd/pint/tests/0019_match_recording.txt index 48eebab2..7d40abdd 100644 --- a/cmd/pint/tests/0019_match_recording.txt +++ b/cmd/pint/tests/0019_match_recording.txt @@ -3,16 +3,16 @@ pint.ok --no-color -l debug lint rules 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=2 -level=debug msg="Found recording rule" lines=1-2 path=rules/0001.yml record=colo:recording -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording -level=debug msg="Found alerting rule" alert=colo:alerting lines=4-5 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting rules/0001.yml:2 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 2 | expr: sum(foo) without(job) -level=info msg="Problems found" Warning=1 +level=INFO msg="Problems found" Warning=1 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0020_ignore_kind.txt b/cmd/pint/tests/0020_ignore_kind.txt index 111afb92..bda02d11 100644 --- a/cmd/pint/tests/0020_ignore_kind.txt +++ b/cmd/pint/tests/0020_ignore_kind.txt @@ -3,19 +3,19 @@ pint.ok --no-color -l debug lint rules 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=2 -level=debug msg="Found recording rule" lines=4-5 path=rules/0001.yml record=colo:recording -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording -level=debug msg="Found alerting rule" alert=colo:alerting lines=7-8 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting rules/0001.yml:5 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 5 | expr: sum(foo) without(job) rules/0001.yml:8 Warning: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison) 8 | expr: sum(bar) without(job) -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0021_ignore_all.txt b/cmd/pint/tests/0021_ignore_all.txt index 261fd3a7..f766797a 100644 --- a/cmd/pint/tests/0021_ignore_all.txt +++ b/cmd/pint/tests/0021_ignore_all.txt @@ -3,8 +3,8 @@ pint.error --no-color -l debug lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": ignore block must have at least one condition" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": ignore block must have at least one condition" -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0022_ignore_multi.txt b/cmd/pint/tests/0022_ignore_multi.txt index ced5cc4d..a3ae5dc7 100644 --- a/cmd/pint/tests/0022_ignore_multi.txt +++ b/cmd/pint/tests/0022_ignore_multi.txt @@ -3,14 +3,14 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yaml:2 Warning: dropped label should be removed when aggregating "^.+$" rules, remove dropped from by() (promql/aggregate) 2 | expr: sum(errors_total) by(keep,dropped) rules/1.yaml:5 Warning: keep label is required and should be preserved when aggregating "^.+$" rules, remove keep from without() (promql/aggregate) 5 | expr: sum(errors_total) without(keep,dropped) -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/1.yaml -- - record: disabled expr: sum(errors_total) by(keep,dropped) diff --git a/cmd/pint/tests/0023_enabled_checks.txt b/cmd/pint/tests/0023_enabled_checks.txt index d4a23c49..5d18212a 100644 --- a/cmd/pint/tests/0023_enabled_checks.txt +++ b/cmd/pint/tests/0023_enabled_checks.txt @@ -1,9 +1,9 @@ pint.error -l debug --no-color lint rules ! stdout . -stderr 'level=debug msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/1.yaml rule=one' -stderr 'level=debug msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/1.yaml rule=two' -stderr 'level=debug msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/2.yaml rule=one' -stderr 'level=debug msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/2.yaml rule=two' +stderr 'level=DEBUG msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/1.yaml rule=one' +stderr 'level=DEBUG msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/1.yaml rule=two' +stderr 'level=DEBUG msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/2.yaml rule=one' +stderr 'level=DEBUG msg="Configured checks for rule" enabled=\["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/rate\(prom\)","promql/series\(prom\)","promql/vector_matching\(prom\)"\,"promql/range_query\(prom\)","rule/duplicate\(prom\)","labels/conflict\(prom\)"] path=rules/2.yaml rule=two' -- rules/1.yaml -- - record: one diff --git a/cmd/pint/tests/0024_color_output.txt b/cmd/pint/tests/0024_color_output.txt index bdc82d93..7a1802b9 100644 --- a/cmd/pint/tests/0024_color_output.txt +++ b/cmd/pint/tests/0024_color_output.txt @@ -1,9 +1,10 @@ +env NO_COLOR=0 pint.error lint rules ! stdout . cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:2 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 2 | expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name) @@ -49,8 +50,8 @@ rules/0003.yaml:40 Warning: instance label should be removed when aggregating "^ rules/0003.yaml:40 Warning: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 40 | expr: sum(byinstance) by(instance) -level=info msg="Problems found" Fatal=1 Warning=10 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 Warning=10 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - record: colo_job:fl_cf_html_bytes_in:rate10m expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name) diff --git a/cmd/pint/tests/0025_config.txt b/cmd/pint/tests/0025_config.txt index 38e96207..11bec78b 100644 --- a/cmd/pint/tests/0025_config.txt +++ b/cmd/pint/tests/0025_config.txt @@ -5,7 +5,7 @@ pint.ok --no-color config cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl { "ci": { "maxCommits": 20, diff --git a/cmd/pint/tests/0026_aggregate_empty_name.txt b/cmd/pint/tests/0026_aggregate_empty_name.txt index 0f736c36..340a3f11 100644 --- a/cmd/pint/tests/0026_aggregate_empty_name.txt +++ b/cmd/pint/tests/0026_aggregate_empty_name.txt @@ -3,8 +3,8 @@ pint.error --no-color config cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": empty name regex" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": empty name regex" -- .pint.hcl -- rule { match { diff --git a/cmd/pint/tests/0027_ci_branch.txt b/cmd/pint/tests/0027_ci_branch.txt index bee3a91c..72493099 100644 --- a/cmd/pint/tests/0027_ci_branch.txt +++ b/cmd/pint/tests/0027_ci_branch.txt @@ -20,12 +20,12 @@ pint.error --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=info msg="Problems found" Fatal=1 +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Problems found" Fatal=1 rules.yml:2 Fatal: syntax error: unexpected identifier "bi" (promql/syntax) 2 | expr: sum(foo) bi(job) -level=fatal msg="Fatal error" error="problems found" +level=ERROR msg="Fatal error" err="problems found" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0028_ci_git_error.txt b/cmd/pint/tests/0028_ci_git_error.txt index 84b729ed..1d95709a 100644 --- a/cmd/pint/tests/0028_ci_git_error.txt +++ b/cmd/pint/tests/0028_ci_git_error.txt @@ -20,11 +20,14 @@ pint.error -l debug --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] -level=debug msg="Got branch information" base=notmain current=v2 -level=debug msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","notmain..HEAD"] -level=fatal msg="Fatal error" error="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 [...] -- [...]'\n" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] +level=DEBUG msg="Got branch information" base=notmain current=v2 +level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","notmain..HEAD"] +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. +Use '--' to separate paths from revisions, like this: +'git [...] -- [...]' +" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0029_ci_too_many_commits.txt b/cmd/pint/tests/0029_ci_too_many_commits.txt index b2b04dc0..7e96954b 100644 --- a/cmd/pint/tests/0029_ci_too_many_commits.txt +++ b/cmd/pint/tests/0029_ci_too_many_commits.txt @@ -27,8 +27,8 @@ pint.error --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="number of commits to check (3) is higher than maxCommits (2), exiting" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="number of commits to check (3) is higher than maxCommits (2), exiting" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0031_ci_bitbucket.txt b/cmd/pint/tests/0031_ci_bitbucket.txt index e96c32e8..a8ceee52 100644 --- a/cmd/pint/tests/0031_ci_bitbucket.txt +++ b/cmd/pint/tests/0031_ci_bitbucket.txt @@ -21,10 +21,10 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.ok -l debug --no-color ci ! stdout . -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0032_ci_github.txt b/cmd/pint/tests/0032_ci_github.txt index 0bd090dd..0852380f 100644 --- a/cmd/pint/tests/0032_ci_github.txt +++ b/cmd/pint/tests/0032_ci_github.txt @@ -25,7 +25,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.ok -l debug --offline --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0033_ci_github_multi.txt b/cmd/pint/tests/0033_ci_github_multi.txt index 33d6f07c..92d0313d 100644 --- a/cmd/pint/tests/0033_ci_github_multi.txt +++ b/cmd/pint/tests/0033_ci_github_multi.txt @@ -25,7 +25,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.error -l debug --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0035_bad_loglevel.txt b/cmd/pint/tests/0035_bad_loglevel.txt index fe3228f7..00463515 100644 --- a/cmd/pint/tests/0035_bad_loglevel.txt +++ b/cmd/pint/tests/0035_bad_loglevel.txt @@ -1,6 +1,3 @@ pint.error -l invalid --no-color lint rules ! stdout . -cmp stderr stderr.txt - --- stderr.txt -- -level=fatal msg="Fatal error" error="failed to set log level: 'invalid' is not a valid log level" +stderr 'ERROR Fatal error err="failed to set log level: ''invalid'' is not a valid log level"' diff --git a/cmd/pint/tests/0036_ci_basebranch.txt b/cmd/pint/tests/0036_ci_basebranch.txt index 889e4a6d..1262d2b4 100644 --- a/cmd/pint/tests/0036_ci_basebranch.txt +++ b/cmd/pint/tests/0036_ci_basebranch.txt @@ -16,8 +16,8 @@ pint.ok --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=info msg="Running from base branch, skipping checks" branch=main +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Running from base branch, skipping checks" branch=main -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0037_disable_checks.txt b/cmd/pint/tests/0037_disable_checks.txt index bd7674fc..05608b3a 100644 --- a/cmd/pint/tests/0037_disable_checks.txt +++ b/cmd/pint/tests/0037_disable_checks.txt @@ -3,20 +3,20 @@ pint.ok -l debug --no-color -d alerts/for -d alerts/comparison -d promql/rate(pr 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=3 -level=debug msg="Starting query workers" name=prom uri=http://127.0.0.1 workers=16 -level=debug msg="Found alerting rule" alert=default-for lines=1-3 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)"] path=rules/0001.yml rule=default-for -level=debug msg="Found recording rule" lines=5-6 path=rules/0001.yml record=sum-job -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum-job -level=debug msg="Found alerting rule" alert=no-comparison lines=8-9 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)"] path=rules/0001.yml rule=no-comparison +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=3 +level=DEBUG msg="Starting query workers" name=prom uri=http://127.0.0.1 workers=16 +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=default-for lines=1-3 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)"] path=rules/0001.yml rule=default-for +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum-job lines=5-6 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum-job +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=no-comparison lines=8-9 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)"] path=rules/0001.yml rule=no-comparison rules/0001.yml:6 Warning: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 6 | expr: sum(foo) -level=info msg="Problems found" Warning=1 -level=debug msg="Stopping query workers" name=prom uri=http://127.0.0.1 +level=INFO msg="Problems found" Warning=1 +level=DEBUG msg="Stopping query workers" name=prom uri=http://127.0.0.1 -- rules/0001.yml -- - alert: default-for expr: foo > 1 diff --git a/cmd/pint/tests/0038_disable_checks_regex.txt b/cmd/pint/tests/0038_disable_checks_regex.txt index a76f3057..8431eca8 100644 --- a/cmd/pint/tests/0038_disable_checks_regex.txt +++ b/cmd/pint/tests/0038_disable_checks_regex.txt @@ -3,11 +3,11 @@ pint.ok --no-color -d 'alerts/.*' -d 'promql/c.+' lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:6 Warning: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 6 | expr: sum(foo) -level=info msg="Problems found" Warning=1 +level=INFO msg="Problems found" Warning=1 -- rules/0001.yml -- - alert: default-for expr: foo > 1 diff --git a/cmd/pint/tests/0039_prom_selected_path.txt b/cmd/pint/tests/0039_prom_selected_path.txt index 24720de5..ead00d7a 100644 --- a/cmd/pint/tests/0039_prom_selected_path.txt +++ b/cmd/pint/tests/0039_prom_selected_path.txt @@ -3,20 +3,20 @@ pint.ok -l debug --no-color lint rules 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=3 -level=debug msg="Starting query workers" name=disabled uri=http://127.0.0.1:123 workers=16 -level=debug msg="Found alerting rule" alert=first lines=1-3 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=first -level=debug msg="Found recording rule" lines=5-6 path=rules/0001.yml record=second -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=second -level=debug msg="Found alerting rule" alert=third lines=8-9 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=third +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=3 +level=DEBUG msg="Starting query workers" name=disabled uri=http://127.0.0.1:123 workers=16 +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=first lines=1-3 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=first +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=second lines=5-6 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=second +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=third lines=8-9 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=third rules/0001.yml:6 Warning: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 6 | expr: sum(bar) -level=info msg="Problems found" Warning=1 -level=debug msg="Stopping query workers" name=disabled uri=http://127.0.0.1:123 +level=INFO msg="Problems found" Warning=1 +level=DEBUG msg="Stopping query workers" name=disabled uri=http://127.0.0.1:123 -- rules/0001.yml -- - alert: first expr: foo > 1 diff --git a/cmd/pint/tests/0040_rule_match_label.txt b/cmd/pint/tests/0040_rule_match_label.txt index 95cb7c4a..06f09d73 100644 --- a/cmd/pint/tests/0040_rule_match_label.txt +++ b/cmd/pint/tests/0040_rule_match_label.txt @@ -3,23 +3,23 @@ pint.ok --no-color -l debug lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="File parsed" path=rules/rules.yml rules=4 -level=debug msg="Found recording rule" lines=1-2 path=rules/rules.yml record=ignore -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore -level=debug msg="Found recording rule" lines=4-7 path=rules/rules.yml record=match -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match -level=debug msg="Found alerting rule" alert=ignore lines=9-10 path=rules/rules.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore -level=debug msg="Found alerting rule" alert=match lines=12-15 path=rules/rules.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/rules.yml rules=4 +level=DEBUG msg="Found recording rule" path=rules/rules.yml record=ignore lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore +level=DEBUG msg="Found recording rule" path=rules/rules.yml record=match lines=4-7 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match +level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=ignore lines=9-10 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore +level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=match lines=12-15 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match rules/rules.yml:5 Warning: job label is required and should be preserved when aggregating "^.*$" rules, use by(job, ...) (promql/aggregate) 5 | expr: sum(foo) rules/rules.yml:13 Warning: job label is required and should be preserved when aggregating "^.*$" rules, use by(job, ...) (promql/aggregate) 13 | expr: sum(foo) > 0 -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/rules.yml -- - record: ignore expr: sum(foo) diff --git a/cmd/pint/tests/0041_watch.txt b/cmd/pint/tests/0041_watch.txt index b7fb5dfd..cc14448c 100644 --- a/cmd/pint/tests/0041_watch.txt +++ b/cmd/pint/tests/0041_watch.txt @@ -3,17 +3,17 @@ exec bash -x ./test.sh & pint.ok --no-color -l debug watch --interval=5s --listen=127.0.0.1:6041 --pidfile=pint.pid rules ! stdout . -stderr 'level=info msg="Pidfile created" path=pint.pid' -stderr 'level=info msg="Started HTTP server" address=127.0.0.1:6041' -stderr 'level=info msg="Will continuously run checks until terminated" interval=5s' -stderr 'level=debug msg="Running checks"' -stderr 'level=error msg="Got an error when running checks" error="no matching files"' -stderr 'level=debug msg="Running checks"' -stderr 'level=error msg="Got an error when running checks" error="no matching files"' -stderr 'level=info msg="Shutting down"' -stderr 'level=info msg="Waiting for all background tasks to finish"' -stderr 'level=info msg="Background worker finished"' -stderr 'level=info msg="Pidfile removed" path=pint.pid' +stderr 'level=INFO msg="Pidfile created" path=pint.pid' +stderr 'level=INFO msg="Started HTTP server" address=127.0.0.1:6041' +stderr 'level=INFO msg="Will continuously run checks until terminated" interval=5s' +stderr 'level=DEBUG msg="Running checks"' +stderr 'level=ERROR msg="Got an error when running checks" err="no matching files"' +stderr 'level=DEBUG msg="Running checks"' +stderr 'level=ERROR msg="Got an error when running checks" err="no matching files"' +stderr 'level=INFO msg="Shutting down"' +stderr 'level=INFO msg="Waiting for all background tasks to finish"' +stderr 'level=INFO msg="Background worker finished"' +stderr 'level=INFO msg="Pidfile removed" path=pint.pid' grep '^pint_check_iterations_total 2$' curl.txt diff --git a/cmd/pint/tests/0043_watch_cancel.txt b/cmd/pint/tests/0043_watch_cancel.txt index b816191c..de5d85c0 100644 --- a/cmd/pint/tests/0043_watch_cancel.txt +++ b/cmd/pint/tests/0043_watch_cancel.txt @@ -5,9 +5,9 @@ exec bash -x ./test.sh & pint.ok --no-color watch --interval=1h --listen=127.0.0.1:6043 --pidfile=pint.pid rules ! stdout . -stderr 'level=info msg="Shutting down"' -stderr 'level=info msg="Waiting for all background tasks to finish"' -stderr 'level=info msg="Background worker finished"' +stderr 'level=INFO msg="Shutting down"' +stderr 'level=INFO msg="Waiting for all background tasks to finish"' +stderr 'level=INFO msg="Background worker finished"' -- test.sh -- sleep 3 diff --git a/cmd/pint/tests/0044_parse_error.txt b/cmd/pint/tests/0044_parse_error.txt index ce11c156..893a9f2d 100644 --- a/cmd/pint/tests/0044_parse_error.txt +++ b/cmd/pint/tests/0044_parse_error.txt @@ -3,4 +3,4 @@ pint.error parse 'sum(foo) by(' cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="1:13: parse error: unclosed left parenthesis" +level=ERROR msg="Fatal error" err="1:13: parse error: unclosed left parenthesis" diff --git a/cmd/pint/tests/0045_parse_no_query.txt b/cmd/pint/tests/0045_parse_no_query.txt index 2292f08d..ed944d9f 100644 --- a/cmd/pint/tests/0045_parse_no_query.txt +++ b/cmd/pint/tests/0045_parse_no_query.txt @@ -3,4 +3,4 @@ pint.error --no-color parse cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="a query string is required" +level=ERROR msg="Fatal error" err="a query string is required" diff --git a/cmd/pint/tests/0051_watch_severity_invalid.txt b/cmd/pint/tests/0051_watch_severity_invalid.txt index 68259e73..9720e375 100644 --- a/cmd/pint/tests/0051_watch_severity_invalid.txt +++ b/cmd/pint/tests/0051_watch_severity_invalid.txt @@ -3,4 +3,4 @@ pint.error --no-color watch --min-severity=foo bar cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="invalid --min-severity value: unknown severity: foo" +level=ERROR msg="Fatal error" err="invalid --min-severity value: unknown severity: foo" diff --git a/cmd/pint/tests/0052_match_multiple.txt b/cmd/pint/tests/0052_match_multiple.txt index 0ba1e485..25236c33 100644 --- a/cmd/pint/tests/0052_match_multiple.txt +++ b/cmd/pint/tests/0052_match_multiple.txt @@ -3,19 +3,19 @@ pint.ok --no-color -l debug lint rules 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=2 -level=debug msg="Found recording rule" lines=4-5 path=rules/0001.yml record=colo:recording -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording -level=debug msg="Found alerting rule" alert=colo:alerting lines=7-8 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting rules/0001.yml:5 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 5 | expr: sum(foo) without(job) rules/0001.yml:8 Warning: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) 8 | expr: sum(bar) without(job) > 0 -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0053_ignore_multiple.txt b/cmd/pint/tests/0053_ignore_multiple.txt index 4bec2ec8..d2896516 100644 --- a/cmd/pint/tests/0053_ignore_multiple.txt +++ b/cmd/pint/tests/0053_ignore_multiple.txt @@ -3,12 +3,12 @@ pint.ok --no-color -l debug lint rules 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=2 -level=debug msg="Found recording rule" lines=4-5 path=rules/0001.yml record=colo:recording -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:recording -level=debug msg="Found alerting rule" alert=colo:alerting lines=7-8 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:recording +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0055_prometheus_failover.txt b/cmd/pint/tests/0055_prometheus_failover.txt index dae18e08..106a225e 100644 --- a/cmd/pint/tests/0055_prometheus_failover.txt +++ b/cmd/pint/tests/0055_prometheus_failover.txt @@ -5,8 +5,8 @@ http start prometheus 127.0.0.1:7055 pint.error --no-color lint rules ! stdout . -stderr 'level=error msg="Query returned an error" error="Post \\"http://127.0.0.1:1055/api/v1/query\\": dial tcp 127.0.0.1:1055: connect: connection refused" query=count\(foo\) uri=http://127.0.0.1:1055' -stderr 'level=error msg="Query returned an error" error="failed to query Prometheus config: Get \\"http://127.0.0.1:1055/api/v1/status/config\\": dial tcp 127.0.0.1:1055: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:1055' +stderr 'level=ERROR msg="Query returned an error" err="Post \\"http://127.0.0.1:1055/api/v1/query\\": dial tcp 127.0.0.1:1055: connect: connection refused" uri=http://127.0.0.1:1055 query=count\(foo\)' +stderr 'level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \\"http://127.0.0.1:1055/api/v1/status/config\\": dial tcp 127.0.0.1:1055: connect: connection refused" uri=http://127.0.0.1:1055 query=/api/v1/status/config' ! stderr 'query="count\(foo offset ' stderr 'rules/1.yml:2 Bug: prometheus "prom" at http://127.0.0.1:7055 didn''t have any series for "foo" metric in the last 1w \(promql/series\)' diff --git a/cmd/pint/tests/0056_prometheus_required.txt b/cmd/pint/tests/0056_prometheus_required.txt index 9d5eae55..89059ec2 100644 --- a/cmd/pint/tests/0056_prometheus_required.txt +++ b/cmd/pint/tests/0056_prometheus_required.txt @@ -3,9 +3,9 @@ http start prometheus 127.0.0.1:7056 pint.ok -l debug --no-color lint rules ! stdout . -stderr 'level=error msg="Query returned an error" error="server error: 500" query=count\(up\) uri=http://127.0.0.1:7056' -stderr 'level=error msg="Query returned an error" error="server error: 500" query=/api/v1/status/config uri=http://127.0.0.1:7056' -stderr 'level=info msg="Problems found" Warning=[0-9]+' +stderr 'level=ERROR msg="Query returned an error" err="server error: 500" uri=http://127.0.0.1:7056 query=count\(up\)' +stderr 'level=ERROR msg="Query returned an error" err="server error: 500" uri=http://127.0.0.1:7056 query=/api/v1/status/config' +stderr 'level=INFO msg="Problems found" Warning=[0-9]+' -- rules/1.yaml -- - record: one diff --git a/cmd/pint/tests/0058_templated_check.txt b/cmd/pint/tests/0058_templated_check.txt index b7f1348e..a293ab76 100644 --- a/cmd/pint/tests/0058_templated_check.txt +++ b/cmd/pint/tests/0058_templated_check.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:4-6 Bug: alert_for annotation is required (alerts/annotation) 4 | - alert: Instance Is Down 2 5 | expr: up == 0 @@ -12,8 +12,8 @@ rules/0001.yml:4-6 Bug: alert_for annotation is required (alerts/annotation) rules/0001.yml:12 Bug: alert_for annotation value must match "^{{ $for }}$" (alerts/annotation) 12 | alert_for: 4m -level=info msg="Problems found" Bug=2 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=2 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 diff --git a/cmd/pint/tests/0059_templated_check_bad_template.txt b/cmd/pint/tests/0059_templated_check_bad_template.txt index 7bab1178..47dd32bb 100644 --- a/cmd/pint/tests/0059_templated_check_bad_template.txt +++ b/cmd/pint/tests/0059_templated_check_bad_template.txt @@ -3,8 +3,8 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": template: regexp:1:126: executing \"regexp\" at : nil is not a command" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": template: regexp:1:126: executing \"regexp\" at : nil is not a command" -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 diff --git a/cmd/pint/tests/0060_ci_noop.txt b/cmd/pint/tests/0060_ci_noop.txt index dd28a23a..d234a274 100644 --- a/cmd/pint/tests/0060_ci_noop.txt +++ b/cmd/pint/tests/0060_ci_noop.txt @@ -29,12 +29,12 @@ pint.error --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=info msg="Problems found" Fatal=1 +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Problems found" Fatal=1 b.yml:2 Fatal: syntax error: unexpected identifier "bi" (promql/syntax) 2 | expr: sum(foo) bi() -level=fatal msg="Fatal error" error="problems found" +level=ERROR msg="Fatal error" err="problems found" -- src/a.yml -- - record: rule1 expr: sum(foo) bi() diff --git a/cmd/pint/tests/0061_lint_workers_zero.txt b/cmd/pint/tests/0061_lint_workers_zero.txt index 6774b582..20bff3c8 100644 --- a/cmd/pint/tests/0061_lint_workers_zero.txt +++ b/cmd/pint/tests/0061_lint_workers_zero.txt @@ -3,4 +3,4 @@ pint.error --workers=0 --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="--workers flag must be > 0" +level=ERROR msg="Fatal error" err="--workers flag must be > 0" diff --git a/cmd/pint/tests/0062_lint_no_args.txt b/cmd/pint/tests/0062_lint_no_args.txt index 8a9c6941..5c465b9d 100644 --- a/cmd/pint/tests/0062_lint_no_args.txt +++ b/cmd/pint/tests/0062_lint_no_args.txt @@ -3,4 +3,4 @@ pint.error --workers=1 --no-color lint cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="at least one file or directory required" +level=ERROR msg="Fatal error" err="at least one file or directory required" diff --git a/cmd/pint/tests/0063_lint_offline.txt b/cmd/pint/tests/0063_lint_offline.txt index 3b9feb1e..ac0b4467 100644 --- a/cmd/pint/tests/0063_lint_offline.txt +++ b/cmd/pint/tests/0063_lint_offline.txt @@ -3,7 +3,7 @@ pint.ok --offline --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/ok.yml -- - record: sum:foo expr: sum(foo) diff --git a/cmd/pint/tests/0064_watch_no_path.txt b/cmd/pint/tests/0064_watch_no_path.txt index 43521dd8..07e2decb 100644 --- a/cmd/pint/tests/0064_watch_no_path.txt +++ b/cmd/pint/tests/0064_watch_no_path.txt @@ -3,4 +3,4 @@ pint.error --no-color watch --listen=127.0.0.1:6064 cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="at least one file or directory required" +level=ERROR msg="Fatal error" err="at least one file or directory required" diff --git a/cmd/pint/tests/0065_ci_include.txt b/cmd/pint/tests/0065_ci_include.txt index 97289818..00ee8f02 100644 --- a/cmd/pint/tests/0065_ci_include.txt +++ b/cmd/pint/tests/0065_ci_include.txt @@ -22,13 +22,13 @@ exec git commit -am 'v2' pint.ok -l debug --no-color ci ! stdout . -stderr 'level=debug msg="Got branch information" base=main current=v2' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Git file change" change=A commit=.* path=a.yml' -stderr 'level=debug msg="Git file change" change=A commit=.* path=b.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=a.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=b.yml' +stderr 'level=DEBUG msg="Got branch information" base=main current=v2' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=a.yml commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=b.yml commit=.*' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=a.yml' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=b.yml' -- src/a.yml -- - record: rule1 diff --git a/cmd/pint/tests/0066_lint_owner.txt b/cmd/pint/tests/0066_lint_owner.txt index 80a6e99b..196988be 100644 --- a/cmd/pint/tests/0066_lint_owner.txt +++ b/cmd/pint/tests/0066_lint_owner.txt @@ -3,7 +3,7 @@ pint.error --no-color lint --require-owner rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yml:4-5 Bug: rule/owner comments are required in all files, please add a "# pint file/owner $owner" somewhere in this file and/or "# pint rule/owner $owner" on top of each rule (rule/owner) 4 | - alert: No Owner 5 | expr: up > 0 @@ -16,8 +16,8 @@ rules/3.yml:1-2 Bug: rule/owner comments are required in all files, please add a 1 | - alert: No Owner 2 | expr: up{job="foo"} == 0 -level=info msg="Problems found" Bug=3 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=3 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/1.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0067_relaxed.txt b/cmd/pint/tests/0067_relaxed.txt index 68e3c3f3..d19311cb 100644 --- a/cmd/pint/tests/0067_relaxed.txt +++ b/cmd/pint/tests/0067_relaxed.txt @@ -3,12 +3,12 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/strict.yml:2 Fatal: cannot unmarshal !!seq into rulefmt.RuleGroups (yaml/parse) 2 | - alert: No Owner -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- {%- raw %} # pint ignore/line - alert: No Owner diff --git a/cmd/pint/tests/0068_skip_ci.txt b/cmd/pint/tests/0068_skip_ci.txt index b6945447..9c9b705c 100644 --- a/cmd/pint/tests/0068_skip_ci.txt +++ b/cmd/pint/tests/0068_skip_ci.txt @@ -21,11 +21,11 @@ exec git commit -am '[skip ci] v2' env BITBUCKET_AUTH_TOKEN="12345" pint.ok -l debug --no-color ci ! stdout . -stderr 'level=info msg="Found a commit with ''\[skip ci\]'', skipping all checks" commit=.*' -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' +stderr 'level=INFO msg="Found a commit with ''\[skip ci\]'', skipping all checks" commit=.*' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0069_bitbucket_skip_unmodified.txt b/cmd/pint/tests/0069_bitbucket_skip_unmodified.txt index 1fa49203..ee3aeac6 100644 --- a/cmd/pint/tests/0069_bitbucket_skip_unmodified.txt +++ b/cmd/pint/tests/0069_bitbucket_skip_unmodified.txt @@ -21,7 +21,7 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.ok --no-color ci ! stdout . -stderr 'level=info msg="Problems found" Information=1' +stderr 'level=INFO msg="Problems found" Information=1' -- src/v1.yml -- - alert: rule1a diff --git a/cmd/pint/tests/0070_bitbucket_strict.txt b/cmd/pint/tests/0070_bitbucket_strict.txt index d2b34a3a..51745297 100644 --- a/cmd/pint/tests/0070_bitbucket_strict.txt +++ b/cmd/pint/tests/0070_bitbucket_strict.txt @@ -21,12 +21,12 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.error -l debug --no-color ci ! stdout . -stderr 'result\\":\\"FAIL\\"' -stderr ',\\"line\\":3,' -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' +stderr 'result":"FAIL"' +stderr ',"line":3,' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0071_ci_owner.txt b/cmd/pint/tests/0071_ci_owner.txt index e0a1fd0c..61338844 100644 --- a/cmd/pint/tests/0071_ci_owner.txt +++ b/cmd/pint/tests/0071_ci_owner.txt @@ -36,7 +36,7 @@ rules.yml:6-7 Bug: rule/owner comments are required in all files, please add a " 6 | - alert: rule2 7 | expr: sum(foo) by(job) > 0 -level=fatal msg="Fatal error" error="problems found" +level=ERROR msg="Fatal error" err="problems found" -- src/v1.yml -- - alert: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0072_bitbucket_move_bug_to_modified.txt b/cmd/pint/tests/0072_bitbucket_move_bug_to_modified.txt index e1d3fb68..d9b7a9f4 100644 --- a/cmd/pint/tests/0072_bitbucket_move_bug_to_modified.txt +++ b/cmd/pint/tests/0072_bitbucket_move_bug_to_modified.txt @@ -21,13 +21,13 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.error --no-color -l debug ci ! stdout . -stderr 'level=info msg="Problems found" Fatal=1' -stderr 'result\\":\\"FAIL\\"' -stderr ',\\"line\\":3,' -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' +stderr 'level=INFO msg="Problems found" Fatal=1' +stderr 'result":"FAIL"' +stderr ',"line":3,' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0073_lint_k8s.txt b/cmd/pint/tests/0073_lint_k8s.txt index 2bb1cc3d..b56980c8 100644 --- a/cmd/pint/tests/0073_lint_k8s.txt +++ b/cmd/pint/tests/0073_lint_k8s.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yml:22-23 Bug: summary annotation is required (alerts/annotation) 22 | - alert: Example_High_Restart_Rate 23 | expr: sum(rate(kube_pod_container_status_restarts_total{namespace="example-app"}[5m])) > ( 3/60 ) @@ -26,8 +26,8 @@ rules/1.yml:25 Fatal: syntax error: no arguments for aggregate expression provid rules/1.yml:28 Fatal: duplicated expr key (yaml/parse) 28 | expr: sum(rate(kube_pod_container_status_restarts_total{namespace="example-app"}[5m])) > ( 3/60 ) -level=info msg="Problems found" Bug=4 Fatal=2 -level=fatal msg="Fatal error" error="found 2 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=2 Bug=4 +level=ERROR msg="Fatal error" err="found 2 problem(s) with severity Bug or higher" -- rules/1.yml -- --- kind: ConfigMap diff --git a/cmd/pint/tests/0074_strict_error.txt b/cmd/pint/tests/0074_strict_error.txt index e16be7c3..8cc334a0 100644 --- a/cmd/pint/tests/0074_strict_error.txt +++ b/cmd/pint/tests/0074_strict_error.txt @@ -6,8 +6,8 @@ cmp stderr stderr.txt rules/strict.yml:2 Fatal: field alert not found in type rulefmt.RuleGroup (yaml/parse) 2 | - alert: Conntrack_Table_Almost_Full -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- groups: - alert: Conntrack_Table_Almost_Full diff --git a/cmd/pint/tests/0075_ci_strict.txt b/cmd/pint/tests/0075_ci_strict.txt index 4a6400e1..0309b6fa 100644 --- a/cmd/pint/tests/0075_ci_strict.txt +++ b/cmd/pint/tests/0075_ci_strict.txt @@ -21,11 +21,11 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.error -l debug --no-color ci --require-owner ! stdout . -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=info msg="Problems found" Bug=1 Fatal=1' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=INFO msg="Problems found" Fatal=1 Bug=1' ! stderr 'parse error: unclosed left parenthesis' -- src/v1.yml -- diff --git a/cmd/pint/tests/0076_ci_group_errors.txt b/cmd/pint/tests/0076_ci_group_errors.txt index 24968194..eefc1eef 100644 --- a/cmd/pint/tests/0076_ci_group_errors.txt +++ b/cmd/pint/tests/0076_ci_group_errors.txt @@ -334,4 +334,4 @@ rules.yml:39 Warning: alert query doesn't have any condition, it will always fir rules.yml:39 Warning: aggregation using without() can be fragile when used inside binary expression because both sides must have identical sets of labels to produce any results, adding or removing labels to metrics used here can easily break the query, consider aggregating using by() to ensure consistent labels (promql/fragile) 39 | expr: errors / sum(requests) without(rack) -level=fatal msg="Fatal error" error="submitting reports: fatal error(s) reported" +level=ERROR msg="Fatal error" err="submitting reports: fatal error(s) reported" diff --git a/cmd/pint/tests/0077_strict_error_owner.txt b/cmd/pint/tests/0077_strict_error_owner.txt index 4397b84b..e06afcdd 100644 --- a/cmd/pint/tests/0077_strict_error_owner.txt +++ b/cmd/pint/tests/0077_strict_error_owner.txt @@ -9,8 +9,8 @@ rules/strict.yml:4 Fatal: "foo bar": invalid field 'annotations' in recording ru rules/strict.yml:4 Fatal: "foo bar": invalid recording rule name: foo bar (yaml/parse) 4 | - record: foo bar -level=info msg="Problems found" Fatal=2 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=2 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0078_repeated_group.txt b/cmd/pint/tests/0078_repeated_group.txt index 368e333b..7d3f583c 100644 --- a/cmd/pint/tests/0078_repeated_group.txt +++ b/cmd/pint/tests/0078_repeated_group.txt @@ -6,8 +6,8 @@ cmp stderr stderr.txt rules/strict.yml:4 Fatal: groupname: "foo" is repeated in the same file (yaml/parse) 4 | - name: foo -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0079_check_promql_series_invalid.txt b/cmd/pint/tests/0079_check_promql_series_invalid.txt index 80a15d4d..6e06b66d 100644 --- a/cmd/pint/tests/0079_check_promql_series_invalid.txt +++ b/cmd/pint/tests/0079_check_promql_series_invalid.txt @@ -3,8 +3,8 @@ pint.error --no-color config cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": .pint.hcl:7,3-6: Unsupported argument; An argument named \"bob\" is not expected here." +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": .pint.hcl:7,3-6: Unsupported argument; An argument named \"bob\" is not expected here." -- .pint.hcl -- prometheus "prom" { uri = "http://127.0.0.1" diff --git a/cmd/pint/tests/0080_lint_online.txt b/cmd/pint/tests/0080_lint_online.txt index 321a7d78..fe34557e 100644 --- a/cmd/pint/tests/0080_lint_online.txt +++ b/cmd/pint/tests/0080_lint_online.txt @@ -10,16 +10,16 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=warn msg="No results for Prometheus uptime metric, you might have set uptime config option to a missing metric, please check your config" metric=prometheus_ready name=prom1 -level=warn msg="Using dummy Prometheus uptime metric results with no gaps" metric=prometheus_ready name=prom1 +level=INFO msg="Loading configuration file" path=.pint.hcl +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=prom1 metric=prometheus_ready +level=WARN msg="Using dummy Prometheus uptime metric results with no gaps" name=prom1 metric=prometheus_ready rules/1.yml:2 Warning: http_errors_total[2d] selector is trying to query Prometheus for 2d worth of metrics, but prometheus "prom1" at http://127.0.0.1:7080 is configured to only keep 1d of metrics history (promql/range_query) 2 | expr: rate(http_errors_total[2d]) > 0 rules/1.yml:2 Warning: prometheus "prom1" at http://127.0.0.1:7080 didn't have any series for "http_errors_total" metric in the last 1w. Metric name "http_errors_total" matches "promql/series" check ignore regexp "^.+_errors_.+$" (promql/series) 2 | expr: rate(http_errors_total[2d]) > 0 -level=info msg="Problems found" Warning=2 +level=INFO msg="Problems found" Warning=2 -- rules/1.yml -- - alert: http errors expr: rate(http_errors_total[2d]) > 0 diff --git a/cmd/pint/tests/0081_rulefmt.txt b/cmd/pint/tests/0081_rulefmt.txt index e2481467..1843d557 100644 --- a/cmd/pint/tests/0081_rulefmt.txt +++ b/cmd/pint/tests/0081_rulefmt.txt @@ -6,8 +6,8 @@ cmp stderr stderr.txt rules/strict.yml:4 Fatal: missing expr key (yaml/parse) 4 | - record: foo -level=info msg="Problems found" Fatal=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0082_ci_base_branch_flag.txt b/cmd/pint/tests/0082_ci_base_branch_flag.txt index e1ba4a75..ab209a93 100644 --- a/cmd/pint/tests/0082_ci_base_branch_flag.txt +++ b/cmd/pint/tests/0082_ci_base_branch_flag.txt @@ -16,8 +16,8 @@ pint.ok --no-color ci --base-branch=main cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=info msg="Running from base branch, skipping checks" branch=main +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Running from base branch, skipping checks" branch=main -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0083_github_action.txt b/cmd/pint/tests/0083_github_action.txt index 3d36db33..3b7be0c3 100644 --- a/cmd/pint/tests/0083_github_action.txt +++ b/cmd/pint/tests/0083_github_action.txt @@ -30,12 +30,12 @@ env GITHUB_REPOSITORY=foo/bar env GITHUB_API_URL=http://127.0.0.1:6083 pint.ok -l debug --offline --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' -stderr 'level=info msg="Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable" pr=123' -stderr 'level=info msg="Setting repository owner from GITHUB_REPOSITORY env variable" owner=foo' -stderr 'level=info msg="Setting repository name from GITHUB_REPOSITORY env variable" repo=bar' -stderr 'level=info msg="Setting repository base URI from GITHUB_API_URL env variable" baseuri=http://127.0.0.1:6083' -stderr 'level=info msg="Setting repository upload URI from GITHUB_API_URL env variable" uploaduri=http://127.0.0.1:6083' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable" pr=123' +stderr 'level=INFO msg="Setting repository owner from GITHUB_REPOSITORY env variable" owner=foo' +stderr 'level=INFO msg="Setting repository name from GITHUB_REPOSITORY env variable" repo=bar' +stderr 'level=INFO msg="Setting repository base URI from GITHUB_API_URL env variable" baseuri=http://127.0.0.1:6083' +stderr 'level=INFO msg="Setting repository upload URI from GITHUB_API_URL env variable" uploaduri=http://127.0.0.1:6083' -- src/v1.yml -- groups: diff --git a/cmd/pint/tests/0084_github_action_override.txt b/cmd/pint/tests/0084_github_action_override.txt index e96fccb2..cb815ecc 100644 --- a/cmd/pint/tests/0084_github_action_override.txt +++ b/cmd/pint/tests/0084_github_action_override.txt @@ -30,9 +30,9 @@ env GITHUB_REPOSITORY=foo/bar env GITHUB_API_URL=http://127.0.0.1:6084 pint.ok -l debug --offline --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' -stderr 'level=info msg="Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable" pr=123' -stderr 'level=info msg="Setting repository base URI from GITHUB_API_URL env variable" baseuri=http://127.0.0.1:6084' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Setting GITHUB_PULL_REQUEST_NUMBER from GITHUB_REF env variable" pr=123' +stderr 'level=INFO msg="Setting repository base URI from GITHUB_API_URL env variable" baseuri=http://127.0.0.1:6084' -- src/v1.yml -- groups: diff --git a/cmd/pint/tests/0085_github_no_envs.txt b/cmd/pint/tests/0085_github_no_envs.txt index 3118f5fa..cb08aa4a 100644 --- a/cmd/pint/tests/0085_github_no_envs.txt +++ b/cmd/pint/tests/0085_github_no_envs.txt @@ -26,7 +26,7 @@ env GITHUB_ACTION=YES env GITHUB_PULL_REQUEST_NUMBER=123 pint.ok -l debug --offline --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' -- src/v1.yml -- groups: diff --git a/cmd/pint/tests/0086_rulefmt_ignored_errors.txt b/cmd/pint/tests/0086_rulefmt_ignored_errors.txt index 88c9fd13..b3d33fed 100644 --- a/cmd/pint/tests/0086_rulefmt_ignored_errors.txt +++ b/cmd/pint/tests/0086_rulefmt_ignored_errors.txt @@ -18,8 +18,8 @@ rules/strict.yml:15 Fatal: template parse error: function "bogus" not defined (a rules/strict.yml:20 Fatal: template parse error: function "bogus" not defined (alerts/template) 20 | dashboard: '{{ bogus }}' -level=info msg="Problems found" Fatal=5 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=5 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/strict.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0087_dedup.txt b/cmd/pint/tests/0087_dedup.txt index 199b44e8..d124d0dc 100644 --- a/cmd/pint/tests/0087_dedup.txt +++ b/cmd/pint/tests/0087_dedup.txt @@ -21,8 +21,8 @@ rules/01.yml:5-12 Bug: template is using "instance" label but the query removes .. 12 | summary: "Server {{ $labels.instance }} in cluster {{ $labels.cluster }} has gone down" -level=info msg="Problems found" Bug=3 Warning=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=3 Warning=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/01.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0088_rule_link.txt b/cmd/pint/tests/0088_rule_link.txt index db99647d..3345c3d4 100644 --- a/cmd/pint/tests/0088_rule_link.txt +++ b/cmd/pint/tests/0088_rule_link.txt @@ -10,7 +10,7 @@ pint.ok --no-color lint --min-severity=info rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yml:10 Information: GET request for http://127.0.0.1:7088/404 returned invalid status code: 404 Not Found (rule/link) 10 | r404: http://127.0.0.1:7088/404 @@ -20,7 +20,7 @@ rules/1.yml:11 Information: GET request for http://127.0.0.1:7088/500 returned i rules/1.yml:13 Warning: GET request for http://127.0.0.1:7088/redirect/404 returned invalid status code: 404 Not Found (rule/link) 13 | rewrite: https://xxxx.example.com/redirect/404 -level=info msg="Problems found" Information=2 Warning=1 +level=INFO msg="Problems found" Warning=1 Information=2 -- rules/1.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0089_lint_min_severity_bug.txt b/cmd/pint/tests/0089_lint_min_severity_bug.txt index c4df7e9b..0799a403 100644 --- a/cmd/pint/tests/0089_lint_min_severity_bug.txt +++ b/cmd/pint/tests/0089_lint_min_severity_bug.txt @@ -3,8 +3,8 @@ pint.ok --no-color lint --min-severity=bug rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Problems found" Information=1 -level=info msg="1 problem(s) not visible because of --min-severity=bug flag" +level=INFO msg="Problems found" Information=1 +level=INFO msg="1 problem(s) not visible because of --min-severity=bug flag" -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0090_lint_min_severity_info.txt b/cmd/pint/tests/0090_lint_min_severity_info.txt index 4dfdffaf..2340066e 100644 --- a/cmd/pint/tests/0090_lint_min_severity_info.txt +++ b/cmd/pint/tests/0090_lint_min_severity_info.txt @@ -8,7 +8,7 @@ rules/0001.yml:5-7 Information: using the value of rate(errors[2m]) inside this . 7 | summary: 'error rate: {{ $value }}' -level=info msg="Problems found" Information=1 +level=INFO msg="Problems found" Information=1 -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0091_lint_min_severity_invalid.txt b/cmd/pint/tests/0091_lint_min_severity_invalid.txt index c0e3cb6c..693f27cf 100644 --- a/cmd/pint/tests/0091_lint_min_severity_invalid.txt +++ b/cmd/pint/tests/0091_lint_min_severity_invalid.txt @@ -3,7 +3,7 @@ pint.error --no-color lint --min-severity=xxx rules cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="invalid --min-severity value: unknown severity: xxx" +level=ERROR msg="Fatal error" err="invalid --min-severity value: unknown severity: xxx" -- rules/0001.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0092_dir_symlink.txt b/cmd/pint/tests/0092_dir_symlink.txt index e09e712b..fab7aa8d 100644 --- a/cmd/pint/tests/0092_dir_symlink.txt +++ b/cmd/pint/tests/0092_dir_symlink.txt @@ -8,9 +8,9 @@ pint.ok -l debug --no-color lint rules linked rules/src/rule.yaml cmp stderr stderr.txt -- stderr.txt -- -level=debug msg="File parsed" path=rules/src/rule.yaml rules=1 -level=debug msg="Found recording rule" lines=4-5 path=rules/src/rule.yaml record=down -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/src/rule.yaml rule=down +level=DEBUG msg="File parsed" path=rules/src/rule.yaml rules=1 +level=DEBUG msg="Found recording rule" path=rules/src/rule.yaml record=down lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/src/rule.yaml rule=down -- rules/src/rule.yaml -- groups: - name: foo diff --git a/cmd/pint/tests/0093_ci_bitbucket_ignore_file.txt b/cmd/pint/tests/0093_ci_bitbucket_ignore_file.txt index 23a7e203..1c2bd68f 100644 --- a/cmd/pint/tests/0093_ci_bitbucket_ignore_file.txt +++ b/cmd/pint/tests/0093_ci_bitbucket_ignore_file.txt @@ -21,14 +21,14 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.ok --no-color -l debug ci ! stdout . -stderr 'level=info msg="Problems found" Information=1' -stderr 'result\\":\\"PASS\\"' -stderr ',\\"line\\":7,' -stderr '"message\\":\\"ignore/file:' -stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' -stderr 'level=debug msg="BitBucket request completed" status=200' -stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' -stderr 'level=debug msg="BitBucket request completed" status=200' +stderr 'level=INFO msg="Problems found" Information=1' +stderr 'result":"PASS"' +stderr ',"line":7,' +stderr '"message":"ignore/file:' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=PUT' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' +stderr 'level=DEBUG msg="Sending a request to BitBucket" method=DELETE' +stderr 'level=DEBUG msg="BitBucket request completed" status=200' -- src/v1.yml -- # pint ignore/file diff --git a/cmd/pint/tests/0094_rule_file_symlink_bb.txt b/cmd/pint/tests/0094_rule_file_symlink_bb.txt index 836b9763..71161658 100644 --- a/cmd/pint/tests/0094_rule_file_symlink_bb.txt +++ b/cmd/pint/tests/0094_rule_file_symlink_bb.txt @@ -47,8 +47,8 @@ stderr 'path=double.yml rule=rule1' stderr 'path=double.yml rule=rule2' ! stderr 'path=ignored.yml' -stderr 'level=info msg="Problems found" Bug=4' -stderr 'result\\":\\"FAIL\\"' +stderr 'level=INFO msg="Problems found" Bug=4' +stderr 'result":"FAIL"' ! stderr '^rules.yml:5 Bug: duration for rate' ! stderr '^rules.yml:7 Bug: duration for rate' @@ -57,10 +57,10 @@ stderr 'symlink.yml ~> rules.yml:7 Bug: duration for rate' stderr 'double.yml ~> rules.yml:5 Bug: duration for rate' stderr 'double.yml ~> rules.yml:7 Bug: duration for rate' -stderr '{\\"path\\":\\"rules.yml\\",\\"line\\":5,' -stderr '{\\"path\\":\\"rules.yml\\",\\"line\\":7,' -! stderr '{\\"path\\":\\"symlink.yml\\"' -! stderr '{\\"path\\":\\"double.yml\\"' +stderr '{"path":"rules.yml","line":5,' +stderr '{"path":"rules.yml","line":7,' +! stderr '{"path":"symlink.yml"' +! stderr '{"path":"double.yml"' stderr 'Problem detected on symlinked file symlink.yml:' stderr 'Problem detected on symlinked file double.yml:' diff --git a/cmd/pint/tests/0095_rulefmt_symlink.txt b/cmd/pint/tests/0095_rulefmt_symlink.txt index 85a37521..5db38c0f 100644 --- a/cmd/pint/tests/0095_rulefmt_symlink.txt +++ b/cmd/pint/tests/0095_rulefmt_symlink.txt @@ -6,13 +6,13 @@ pint.ok -l debug --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="File parsed" path=rules/relaxed/1.yml rules=1 -level=debug msg="File parsed" path=rules/strict/symlink.yml rules=1 -level=debug msg="Found recording rule" lines=1-2 path=rules/relaxed/1.yml record=foo -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/relaxed/1.yml rule=foo -level=debug msg="Found recording rule" lines=1-2 path=rules/strict/symlink.yml record=foo -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/strict/symlink.yml rule=foo +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/relaxed/1.yml rules=1 +level=DEBUG msg="File parsed" path=rules/strict/symlink.yml rules=1 +level=DEBUG msg="Found recording rule" path=rules/relaxed/1.yml record=foo lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/relaxed/1.yml rule=foo +level=DEBUG msg="Found recording rule" path=rules/strict/symlink.yml record=foo lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/strict/symlink.yml rule=foo -- rules/relaxed/1.yml -- - record: foo expr: up == 0 diff --git a/cmd/pint/tests/0096_bad_symlink.txt b/cmd/pint/tests/0096_bad_symlink.txt index 85332461..d8e4261b 100644 --- a/cmd/pint/tests/0096_bad_symlink.txt +++ b/cmd/pint/tests/0096_bad_symlink.txt @@ -6,4 +6,4 @@ pint.error -l debug --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=fatal msg="Fatal error" error="lstat rules/../bad.yml: no such file or directory" +level=ERROR msg="Fatal error" err="lstat rules/../bad.yml: no such file or directory" diff --git a/cmd/pint/tests/0097_rule_file_symlink_error.txt b/cmd/pint/tests/0097_rule_file_symlink_error.txt index 7785d636..9a8d96a5 100644 --- a/cmd/pint/tests/0097_rule_file_symlink_error.txt +++ b/cmd/pint/tests/0097_rule_file_symlink_error.txt @@ -18,7 +18,7 @@ exec git commit -am 'v2' pint.error -l debug -d promql/series --no-color ci ! stdout . -stderr 'level=fatal msg="Fatal error" error="symlink.yml is a symlink but target file cannot be evaluated: lstat xxx.yml: no such file or directory"' +stderr 'level=ERROR msg="Fatal error" err="symlink.yml is a symlink but target file cannot be evaluated: lstat xxx.yml: no such file or directory"' -- src/v1.yml -- groups: diff --git a/cmd/pint/tests/0098_rule_file_symlink_gh.txt b/cmd/pint/tests/0098_rule_file_symlink_gh.txt index 44d19baa..3677d003 100644 --- a/cmd/pint/tests/0098_rule_file_symlink_gh.txt +++ b/cmd/pint/tests/0098_rule_file_symlink_gh.txt @@ -26,7 +26,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.ok -l debug -d promql/series --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' -- src/v1.yml -- groups: diff --git a/cmd/pint/tests/0099_symlink_outside_glob.txt b/cmd/pint/tests/0099_symlink_outside_glob.txt index c8aff251..126f885d 100644 --- a/cmd/pint/tests/0099_symlink_outside_glob.txt +++ b/cmd/pint/tests/0099_symlink_outside_glob.txt @@ -6,10 +6,10 @@ pint.ok -l debug --no-color lint rules/relaxed cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="File parsed" path=rules/relaxed/1.yml rules=1 -level=debug msg="Found recording rule" lines=1-2 path=rules/relaxed/1.yml record=foo -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/relaxed/1.yml rule=foo +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/relaxed/1.yml rules=1 +level=DEBUG msg="Found recording rule" path=rules/relaxed/1.yml record=foo lines=1-2 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/relaxed/1.yml rule=foo -- rules/relaxed/1.yml -- - record: foo expr: up == 0 diff --git a/cmd/pint/tests/0100_ci_alerts_count.txt b/cmd/pint/tests/0100_ci_alerts_count.txt index e6cf6bc8..2c9a137e 100644 --- a/cmd/pint/tests/0100_ci_alerts_count.txt +++ b/cmd/pint/tests/0100_ci_alerts_count.txt @@ -28,8 +28,8 @@ exec git commit -am 'v2' env BITBUCKET_AUTH_TOKEN="12345" pint.ok -l debug --no-color ci ! stdout . -stderr '{\\"path\\":\\"rules.yml\\",\\"line\\":3,\\"message\\":\\"alerts/count: ' -stderr '{\\"path\\":\\"rules.yml\\",\\"line\\":8,\\"message\\":\\"alerts/count: ' +stderr '{"path":"rules.yml","line":3,"message":"alerts/count: ' +stderr '{"path":"rules.yml","line":8,"message":"alerts/count: ' -- src/v1.yml -- - alert: alert1 diff --git a/cmd/pint/tests/0103_file_disable.txt b/cmd/pint/tests/0103_file_disable.txt index 5024a520..ec90f72b 100644 --- a/cmd/pint/tests/0103_file_disable.txt +++ b/cmd/pint/tests/0103_file_disable.txt @@ -3,12 +3,12 @@ pint.ok -l debug --no-color lint rules 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)","labels/conflict(prom)"] path=rules/0001.yml rule=colo:test1 -level=debug msg="Stopping query workers" name=prom uri=http://127.0.0.1:7103 +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" path=rules/0001.yml record=colo:test1 lines=9-10 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","labels/conflict(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 diff --git a/cmd/pint/tests/0104_file_ignore_prom.txt b/cmd/pint/tests/0104_file_ignore_prom.txt index 60f0c283..0fdaf606 100644 --- a/cmd/pint/tests/0104_file_ignore_prom.txt +++ b/cmd/pint/tests/0104_file_ignore_prom.txt @@ -3,10 +3,10 @@ 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' +stderr 'level=ERROR msg="Query returned an error" err="server error: 502" uri=http://127.0.0.1:7104 query=/api/v1/status/config' +stderr 'level=ERROR msg="Query returned an error" err="server error: 502" uri=http://127.0.0.1:7104 query=/api/v1/status/flags' +stderr 'level=ERROR msg="Query returned an error" err="server error: 502" uri=http://127.0.0.1:7104 query=count\(foo\)' +stderr 'level=INFO msg="Problems found" Bug=3' -- rules/0001.yml -- # This should skip all online checks # pint file/disable promql/series diff --git a/cmd/pint/tests/0105_too_many_samples.txt b/cmd/pint/tests/0105_too_many_samples.txt index 65c5599a..583723d8 100644 --- a/cmd/pint/tests/0105_too_many_samples.txt +++ b/cmd/pint/tests/0105_too_many_samples.txt @@ -7,8 +7,8 @@ http start prometheus 127.0.0.1:7105 pint.error --no-color lint rules ! stdout . -stderr 'level=error msg="Query returned an error" error="query processing would load too many samples into memory in query execution" query=count\(up\) uri=http://127.0.0.1:7105' -stderr 'level=warn msg="Cannot detect Prometheus uptime gaps" error="execution: query processing would load too many samples into memory in query execution" name=prom' +stderr 'level=ERROR msg="Query returned an error" err="query processing would load too many samples into memory in query execution" uri=http://127.0.0.1:7105 query=count\(up\)' +stderr 'level=WARN msg="Cannot detect Prometheus uptime gaps" err="execution: query processing would load too many samples into memory in query execution" name=prom' -- rules/1.yaml -- - record: one diff --git a/cmd/pint/tests/0106_ci_git_branch_error.txt b/cmd/pint/tests/0106_ci_git_branch_error.txt index 458c6b0d..aad0798b 100644 --- a/cmd/pint/tests/0106_ci_git_branch_error.txt +++ b/cmd/pint/tests/0106_ci_git_branch_error.txt @@ -3,5 +3,5 @@ pint.error -l debug --no-color ci cmp stderr stderr.txt -- stderr.txt -- -level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] -level=fatal msg="Fatal error" error="failed to get the name of current branch" +level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] +level=ERROR msg="Fatal error" err="failed to get the name of current branch" diff --git a/cmd/pint/tests/0107_ci_git_invalid_log_level.txt b/cmd/pint/tests/0107_ci_git_invalid_log_level.txt index 3a7ae7cb..c3fd751a 100644 --- a/cmd/pint/tests/0107_ci_git_invalid_log_level.txt +++ b/cmd/pint/tests/0107_ci_git_invalid_log_level.txt @@ -1,6 +1,3 @@ pint.error -l xxx --no-color ci ! stdout . -cmp stderr stderr.txt - --- stderr.txt -- -level=fatal msg="Fatal error" error="failed to set log level: 'xxx' is not a valid log level" +stderr 'ERROR Fatal error err="failed to set log level: ''xxx'' is not a valid log level"' diff --git a/cmd/pint/tests/0108_rule_duplicate.txt b/cmd/pint/tests/0108_rule_duplicate.txt index 078f3635..9a365ec8 100644 --- a/cmd/pint/tests/0108_rule_duplicate.txt +++ b/cmd/pint/tests/0108_rule_duplicate.txt @@ -3,12 +3,12 @@ pint.error --no-color -d 'promql/.*' -d alerts/count lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=error msg="Query returned an error" error="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:7108 -level=error msg="Query returned an error" error="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:7108 -level=error msg="Query returned an error" error="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:7108 -level=error msg="Query returned an error" error="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:7108 -level=error msg="Query returned an error" error="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" query=/api/v1/status/config uri=http://127.0.0.1:7108 +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" uri=http://127.0.0.1:7108 query=/api/v1/status/config +level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" uri=http://127.0.0.1:7108 query=/api/v1/status/config +level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" uri=http://127.0.0.1:7108 query=/api/v1/status/config +level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" uri=http://127.0.0.1:7108 query=/api/v1/status/config +level=ERROR msg="Query returned an error" err="failed to query Prometheus config: Get \"http://127.0.0.1:7108/api/v1/status/config\": dial tcp 127.0.0.1:7108: connect: connection refused" uri=http://127.0.0.1:7108 query=/api/v1/status/config rules/0001.yml:1-2 Bug: duplicated rule, identical rule found at rules/0002.yml:1 (rule/duplicate) 1 | - record: "colo:duplicate" 2 | expr: sum(foo) without(job) @@ -39,8 +39,8 @@ rules/0002.yml:13-14 Bug: couldn't run "labels/conflict" checks due to prometheu 13 | labels: 14 | same: yes -level=info msg="Problems found" Bug=7 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=7 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - record: "colo:duplicate" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0109_rule_duplicate_multiple_proms_include.txt b/cmd/pint/tests/0109_rule_duplicate_multiple_proms_include.txt index bf024cc4..e6fa66c4 100644 --- a/cmd/pint/tests/0109_rule_duplicate_multiple_proms_include.txt +++ b/cmd/pint/tests/0109_rule_duplicate_multiple_proms_include.txt @@ -3,7 +3,7 @@ pint.ok --no-color -d 'promql/.*' -d alerts/count -d labels/conflict lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yml -- - record: "colo:duplicate" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0110_rule_duplicate_multiple_proms_exclude.txt b/cmd/pint/tests/0110_rule_duplicate_multiple_proms_exclude.txt index bed88294..31f3bc52 100644 --- a/cmd/pint/tests/0110_rule_duplicate_multiple_proms_exclude.txt +++ b/cmd/pint/tests/0110_rule_duplicate_multiple_proms_exclude.txt @@ -3,7 +3,7 @@ pint.ok --no-color -d 'promql/.*' -d alerts/count lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yml -- - record: "colo:duplicate" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0111_snooze.txt b/cmd/pint/tests/0111_snooze.txt index bab24443..910935f2 100644 --- a/cmd/pint/tests/0111_snooze.txt +++ b/cmd/pint/tests/0111_snooze.txt @@ -3,11 +3,11 @@ pint.ok -l debug --no-color lint rules 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="Found recording rule" lines=2-3 path=rules/0001.yml record=sum-job -level=debug msg="Check snoozed by comment" check=promql/aggregate(job:true) comment="snooze 2099-11-28T10:24:18Z promql/aggregate" snooze=promql/aggregate until=2099-11-28T10:24:18Z -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=sum-job +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=1 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum-job lines=2-3 +level=DEBUG msg="Check snoozed by comment" check=promql/aggregate(job:true) comment="snooze 2099-11-28T10:24:18Z promql/aggregate" until="2099-11-28T10:24:18Z" snooze=promql/aggregate +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=sum-job -- rules/0001.yml -- # pint snooze 2099-11-28T10:24:18Z promql/aggregate - record: sum-job diff --git a/cmd/pint/tests/0112_expired_snooze.txt b/cmd/pint/tests/0112_expired_snooze.txt index 2e5da81c..601858f2 100644 --- a/cmd/pint/tests/0112_expired_snooze.txt +++ b/cmd/pint/tests/0112_expired_snooze.txt @@ -3,15 +3,15 @@ pint.error -l debug --no-color lint rules 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="Found recording rule" lines=2-3 path=rules/0001.yml record=sum-job -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum-job +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="File parsed" path=rules/0001.yml rules=1 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum-job lines=2-3 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum-job rules/0001.yml:3 Bug: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) 3 | expr: sum(foo) -level=info msg="Problems found" Bug=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- # pint snooze 2000-11-28T10:24:18Z promql/aggregate - record: sum-job diff --git a/cmd/pint/tests/0113_config_env_expand.txt b/cmd/pint/tests/0113_config_env_expand.txt index 7425e7c1..ef5960f5 100644 --- a/cmd/pint/tests/0113_config_env_expand.txt +++ b/cmd/pint/tests/0113_config_env_expand.txt @@ -6,7 +6,7 @@ pint.ok --no-color config cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl { "ci": { "maxCommits": 20, diff --git a/cmd/pint/tests/0114_config_env_expand_error.txt b/cmd/pint/tests/0114_config_env_expand_error.txt index 5ba5a75e..7752091d 100644 --- a/cmd/pint/tests/0114_config_env_expand_error.txt +++ b/cmd/pint/tests/0114_config_env_expand_error.txt @@ -4,8 +4,8 @@ pint.error --no-color config cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": .pint.hcl:7,17-29: Unknown variable; There is no variable named \"ENV_AUTH_KEY\"., and 1 other diagnostic(s)" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": .pint.hcl:7,17-29: Unknown variable; There is no variable named \"ENV_AUTH_KEY\"., and 1 other diagnostic(s)" -- .pint.hcl -- parser { relaxed = [".*"] diff --git a/cmd/pint/tests/0115_file_disable_tag.txt b/cmd/pint/tests/0115_file_disable_tag.txt index b98f077c..233ab245 100644 --- a/cmd/pint/tests/0115_file_disable_tag.txt +++ b/cmd/pint/tests/0115_file_disable_tag.txt @@ -3,12 +3,12 @@ pint.ok -l debug --no-color lint rules 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="6 8" 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"] path=rules/0001.yml rule=colo:test1 -level=debug msg="Stopping query workers" name=prom uri=http://127.0.0.1:7103 +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" path=rules/0001.yml record=colo:test1 lines="6 8" +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] 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 -- # pint file/disable promql/series(+bar) # pint file/disable promql/rate(+bar) diff --git a/cmd/pint/tests/0116_file_snooze.txt b/cmd/pint/tests/0116_file_snooze.txt index 2e1effb4..6f0a5af3 100644 --- a/cmd/pint/tests/0116_file_snooze.txt +++ b/cmd/pint/tests/0116_file_snooze.txt @@ -3,14 +3,14 @@ pint.ok -l debug --no-color lint --min-severity=info rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="Check snoozed by comment" check=promql/aggregate(job:true) comment="file/snooze 2099-11-28T10:24:18Z promql/aggregate(job:true)" snooze=promql/aggregate(job:true) until=2099-11-28T10:24:18Z -level=debug msg="Check snoozed by comment" check=alerts/for comment="file/snooze 2099-11-28T10:24:18Z alerts/for" snooze=alerts/for until=2099-11-28T10:24:18Z -level=debug msg="File parsed" path=rules/0001.yml rules=2 -level=debug msg="Found recording rule" lines=4-5 path=rules/0001.yml record=sum-job -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=sum-job -level=debug msg="Found alerting rule" alert=Down lines=7-9 path=rules/0001.yml -level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=Down +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="Check snoozed by comment" check=promql/aggregate(job:true) comment="file/snooze 2099-11-28T10:24:18Z promql/aggregate(job:true)" until="2099-11-28T10:24:18Z" snooze=promql/aggregate(job:true) +level=DEBUG msg="Check snoozed by comment" check=alerts/for comment="file/snooze 2099-11-28T10:24:18Z alerts/for" until="2099-11-28T10:24:18Z" snooze=alerts/for +level=DEBUG msg="File parsed" path=rules/0001.yml rules=2 +level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum-job lines=4-5 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=sum-job +level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=Down lines=7-9 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=Down -- rules/0001.yml -- # pint file/snooze 2099-11-28T10:24:18Z promql/aggregate(job:true) # pint file/snooze 2099-11-28T10:24:18Z alerts/for diff --git a/cmd/pint/tests/0117_ci_dir_move_blame.txt b/cmd/pint/tests/0117_ci_dir_move_blame.txt index bc15be00..b5d7afd8 100644 --- a/cmd/pint/tests/0117_ci_dir_move_blame.txt +++ b/cmd/pint/tests/0117_ci_dir_move_blame.txt @@ -27,7 +27,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.ok -l debug --no-color ci ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' stderr 'msg="Skipping directory entry change"' -- src/rules.yml -- diff --git a/cmd/pint/tests/0118_ci_dir_move_branch.txt b/cmd/pint/tests/0118_ci_dir_move_branch.txt index 87983fac..d9719706 100644 --- a/cmd/pint/tests/0118_ci_dir_move_branch.txt +++ b/cmd/pint/tests/0118_ci_dir_move_branch.txt @@ -27,7 +27,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.ok -l debug --no-color ci --dev ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' stderr 'msg="Skipping directory entry change"' -- src/rules.yml -- diff --git a/cmd/pint/tests/0119_ci_fail_on_warning.txt b/cmd/pint/tests/0119_ci_fail_on_warning.txt index bd5532f2..e029c8d6 100644 --- a/cmd/pint/tests/0119_ci_fail_on_warning.txt +++ b/cmd/pint/tests/0119_ci_fail_on_warning.txt @@ -25,7 +25,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.error -l debug --offline --no-color ci --fail-on=warning ! stdout . -stderr 'level=info msg="Pull request review created" status="200 OK"' +stderr 'level=INFO msg="Pull request review created" status="200 OK"' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0120_ci_fail_on_invalid.txt b/cmd/pint/tests/0120_ci_fail_on_invalid.txt index cec10b2e..25dade91 100644 --- a/cmd/pint/tests/0120_ci_fail_on_invalid.txt +++ b/cmd/pint/tests/0120_ci_fail_on_invalid.txt @@ -19,7 +19,7 @@ env GITHUB_AUTH_TOKEN=12345 env GITHUB_PULL_REQUEST_NUMBER=1 pint.error -l debug --offline --no-color ci --fail-on=bogus ! stdout . -stderr 'level=fatal msg="Fatal error" error="invalid --fail-on value: unknown severity: bogus"' +stderr 'level=ERROR msg="Fatal error" err="invalid --fail-on value: unknown severity: bogus"' -- src/v1.yml -- - alert: rule1 diff --git a/cmd/pint/tests/0121_rule_for.txt b/cmd/pint/tests/0121_rule_for.txt index e2950b70..9172cdde 100644 --- a/cmd/pint/tests/0121_rule_for.txt +++ b/cmd/pint/tests/0121_rule_for.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:6 Bug: this alert rule must have a 'for' field with a minimum duration of 5m (rule/for) 6 | for: 3m @@ -13,8 +13,8 @@ rules/0001.yml:9 Bug: this alert rule must have a 'for' field with a maximum dur rules/0001.yml:10 Bug: this alert rule must have a 'for' field with a minimum duration of 5m (rule/for) 10 | - alert: none -level=info msg="Problems found" Bug=3 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=3 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: ok expr: up == 0 diff --git a/cmd/pint/tests/0122_lint_owner_allowed.txt b/cmd/pint/tests/0122_lint_owner_allowed.txt index 5e44f76b..9c02619d 100644 --- a/cmd/pint/tests/0122_lint_owner_allowed.txt +++ b/cmd/pint/tests/0122_lint_owner_allowed.txt @@ -3,7 +3,7 @@ pint.error --no-color lint --require-owner rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/1.yml:4-5 Bug: rule/owner comments are required in all files, please add a "# pint file/owner $owner" somewhere in this file and/or "# pint rule/owner $owner" on top of each rule (rule/owner) 4 | - alert: No Owner 5 | expr: up > 0 @@ -12,8 +12,8 @@ rules/1.yml:7-8 Bug: this rule is set as owned by "bob" but "bob" doesn't match 7 | - alert: Invalid 8 | expr: up == 0 -level=info msg="Problems found" Bug=2 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=2 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/1.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0123_ci_owner_allowed.txt b/cmd/pint/tests/0123_ci_owner_allowed.txt index a92c392d..da4e03f9 100644 --- a/cmd/pint/tests/0123_ci_owner_allowed.txt +++ b/cmd/pint/tests/0123_ci_owner_allowed.txt @@ -33,7 +33,7 @@ rules.yml:7-8 Bug: this rule is set as owned by "bob" but "bob" doesn't match an 7 | - alert: Invalid 8 | expr: up == 0 -level=fatal msg="Fatal error" error="problems found" +level=ERROR msg="Fatal error" err="problems found" -- src/v1.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0124_ci_base_branch_flag.txt b/cmd/pint/tests/0124_ci_base_branch_flag.txt index 6a8abd34..a0dae325 100644 --- a/cmd/pint/tests/0124_ci_base_branch_flag.txt +++ b/cmd/pint/tests/0124_ci_base_branch_flag.txt @@ -20,12 +20,12 @@ pint.error --no-color ci --base-branch=main cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=info msg="Problems found" Fatal=1 +level=INFO msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Problems found" Fatal=1 rules.yml:2 Fatal: syntax error: unexpected identifier "bi" (promql/syntax) 2 | expr: sum(foo) bi(job) -level=fatal msg="Fatal error" error="problems found" +level=ERROR msg="Fatal error" err="problems found" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0125_lint_fail_on_warning.txt b/cmd/pint/tests/0125_lint_fail_on_warning.txt index 951afd17..8fdbc6fe 100644 --- a/cmd/pint/tests/0125_lint_fail_on_warning.txt +++ b/cmd/pint/tests/0125_lint_fail_on_warning.txt @@ -16,5 +16,5 @@ rules/0001.yml:5 Warning: alert query doesn't have any condition, it will always rules/0001.yml:5 Bug: unnecessary regexp match on static string job=~"xxx", use job="xxx" instead (promql/regexp) 5 | expr: up{job=~"xxx"} -level=info msg="Problems found" Bug=1 Warning=1 -level=fatal msg="Fatal error" error="found 2 problem(s) with severity Warning or higher" +level=INFO msg="Problems found" Bug=1 Warning=1 +level=ERROR msg="Fatal error" err="found 2 problem(s) with severity Warning or higher" diff --git a/cmd/pint/tests/0126_lint_fail_on_invalid.txt b/cmd/pint/tests/0126_lint_fail_on_invalid.txt index 7ebf14a5..6716e1e8 100644 --- a/cmd/pint/tests/0126_lint_fail_on_invalid.txt +++ b/cmd/pint/tests/0126_lint_fail_on_invalid.txt @@ -6,4 +6,4 @@ cmp stderr stderr.txt # empty -- stderr.txt -- -level=fatal msg="Fatal error" error="invalid --fail-on value: unknown severity: xxx" +level=ERROR msg="Fatal error" err="invalid --fail-on value: unknown severity: xxx" diff --git a/cmd/pint/tests/0127_lint_fail_on_fatal_but_got_warning.txt b/cmd/pint/tests/0127_lint_fail_on_fatal_but_got_warning.txt index da32c4ef..d4ace045 100644 --- a/cmd/pint/tests/0127_lint_fail_on_fatal_but_got_warning.txt +++ b/cmd/pint/tests/0127_lint_fail_on_fatal_but_got_warning.txt @@ -10,5 +10,5 @@ groups: expr: up{job="xxx"} -- stderr.txt -- -level=info msg="Problems found" Warning=1 -level=info msg="1 problem(s) not visible because of --min-severity=bug flag" +level=INFO msg="Problems found" Warning=1 +level=INFO msg="1 problem(s) not visible because of --min-severity=bug flag" diff --git a/cmd/pint/tests/0128_lint_fail_on_warning_only.txt b/cmd/pint/tests/0128_lint_fail_on_warning_only.txt index d3860450..faa5f74c 100644 --- a/cmd/pint/tests/0128_lint_fail_on_warning_only.txt +++ b/cmd/pint/tests/0128_lint_fail_on_warning_only.txt @@ -10,6 +10,6 @@ groups: expr: up{job="xxx"} -- stderr.txt -- -level=info msg="Problems found" Warning=1 -level=info msg="1 problem(s) not visible because of --min-severity=bug flag" -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Warning or higher" +level=INFO msg="Problems found" Warning=1 +level=INFO msg="1 problem(s) not visible because of --min-severity=bug flag" +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Warning or higher" diff --git a/cmd/pint/tests/0133_tls_certs_bad.txt b/cmd/pint/tests/0133_tls_certs_bad.txt index 24d83caf..c2168d66 100644 --- a/cmd/pint/tests/0133_tls_certs_bad.txt +++ b/cmd/pint/tests/0133_tls_certs_bad.txt @@ -3,8 +3,8 @@ pint.error -l debug --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": invalid prometheus TLS configuration: open prom-ca.pem: no such file or directory" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": invalid prometheus TLS configuration: open prom-ca.pem: no such file or directory" -- rules/1.yml -- groups: - name: foo diff --git a/cmd/pint/tests/0134_ci_base_branch_flag_path.txt b/cmd/pint/tests/0134_ci_base_branch_flag_path.txt index 6a14e927..d06ed840 100644 --- a/cmd/pint/tests/0134_ci_base_branch_flag_path.txt +++ b/cmd/pint/tests/0134_ci_base_branch_flag_path.txt @@ -20,11 +20,14 @@ pint.error -l debug --no-color ci --base-branch=origin/main cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] -level=debug msg="Got branch information" base=origin/main current=v2 -level=debug msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"] -level=fatal msg="Fatal error" error="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 [...] -- [...]'\n" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] +level=DEBUG msg="Got branch information" base=origin/main current=v2 +level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"] +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. +Use '--' to separate paths from revisions, like this: +'git [...] -- [...]' +" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0135_ci_base_branch_config_path.txt b/cmd/pint/tests/0135_ci_base_branch_config_path.txt index c96166b1..9ca6bf27 100644 --- a/cmd/pint/tests/0135_ci_base_branch_config_path.txt +++ b/cmd/pint/tests/0135_ci_base_branch_config_path.txt @@ -20,11 +20,14 @@ pint.error -l debug --no-color ci cmp stderr ../stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl -level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] -level=debug msg="Got branch information" base=origin/main current=v2 -level=debug msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"] -level=fatal msg="Fatal error" error="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 [...] -- [...]'\n" +level=INFO msg="Loading configuration file" path=.pint.hcl +level=DEBUG msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"] +level=DEBUG msg="Got branch information" base=origin/main current=v2 +level=DEBUG msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"] +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. +Use '--' to separate paths from revisions, like this: +'git [...] -- [...]' +" -- src/v1.yml -- - record: rule1 expr: sum(foo) by(job) diff --git a/cmd/pint/tests/0136_annotation_regex_key.txt b/cmd/pint/tests/0136_annotation_regex_key.txt index 9f7b2ba7..d02c71e8 100644 --- a/cmd/pint/tests/0136_annotation_regex_key.txt +++ b/cmd/pint/tests/0136_annotation_regex_key.txt @@ -3,7 +3,7 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 @@ -21,4 +21,4 @@ rule { value = "bar" severity = "bug" } -} \ No newline at end of file +} diff --git a/cmd/pint/tests/0137_annotation_regex_key_fail.txt b/cmd/pint/tests/0137_annotation_regex_key_fail.txt index a6a2bd15..42ef2c45 100644 --- a/cmd/pint/tests/0137_annotation_regex_key_fail.txt +++ b/cmd/pint/tests/0137_annotation_regex_key_fail.txt @@ -3,12 +3,12 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:4 Bug: annotation_.* annotation value must match "^bar$" (alerts/annotation) 4 | annotation_foo: foo -level=info msg="Problems found" Bug=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 diff --git a/cmd/pint/tests/0138_annoation_regex_key_required.txt b/cmd/pint/tests/0138_annoation_regex_key_required.txt index 883e5a1d..69f89251 100644 --- a/cmd/pint/tests/0138_annoation_regex_key_required.txt +++ b/cmd/pint/tests/0138_annoation_regex_key_required.txt @@ -3,13 +3,13 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:1-2 Bug: annotation_.* annotation is required (alerts/annotation) 1 | - alert: Instance Is Down 1 2 | expr: up == 0 -level=info msg="Problems found" Bug=1 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=1 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 diff --git a/cmd/pint/tests/0139_ci_exclude.txt b/cmd/pint/tests/0139_ci_exclude.txt index e10fe6ce..1089bdec 100644 --- a/cmd/pint/tests/0139_ci_exclude.txt +++ b/cmd/pint/tests/0139_ci_exclude.txt @@ -22,13 +22,13 @@ exec git commit -am 'v2' pint.ok -l debug --no-color ci ! stdout . -stderr 'level=debug msg="Got branch information" base=main current=v2' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Git file change" change=A commit=.* path=a.yml' -stderr 'level=debug msg="Git file change" change=A commit=.* path=b.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=a.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=b.yml' +stderr 'level=DEBUG msg="Got branch information" base=main current=v2' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=a.yml commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=b.yml commit=.*' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=a.yml' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=b.yml' -- src/a.yml -- - record: rule1 diff --git a/cmd/pint/tests/0140_ci_include_exclude.txt b/cmd/pint/tests/0140_ci_include_exclude.txt index aa3a5993..ee96236c 100644 --- a/cmd/pint/tests/0140_ci_include_exclude.txt +++ b/cmd/pint/tests/0140_ci_include_exclude.txt @@ -22,13 +22,13 @@ exec git commit -am 'v2' pint.ok -l debug --no-color ci ! stdout . -stderr 'level=debug msg="Got branch information" base=main current=v2' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Found commit to scan" commit=.*' -stderr 'level=debug msg="Git file change" change=A commit=.* path=a.yml' -stderr 'level=debug msg="Git file change" change=A commit=.* path=b.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=a.yml' -stderr 'level=debug msg="Skipping file due to include/exclude rules" path=b.yml' +stderr 'level=DEBUG msg="Got branch information" base=main current=v2' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Found commit to scan" commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=a.yml commit=.*' +stderr 'level=DEBUG msg="Git file change" change=A path=b.yml commit=.*' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=a.yml' +stderr 'level=DEBUG msg="Skipping file due to include/exclude rules" path=b.yml' -- src/a.yml -- - record: rule1 diff --git a/cmd/pint/tests/0141_empty_keys.txt b/cmd/pint/tests/0141_empty_keys.txt index f8d7cafa..20d096c1 100644 --- a/cmd/pint/tests/0141_empty_keys.txt +++ b/cmd/pint/tests/0141_empty_keys.txt @@ -21,8 +21,8 @@ rules.yml:12 Fatal: alert value cannot be empty (yaml/parse) rules.yml:15 Fatal: expr value cannot be empty (yaml/parse) 15 | expr: -level=info msg="Problems found" Fatal=6 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Fatal=6 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules.yml -- groups: - name: rules diff --git a/cmd/pint/tests/0142_keep_firing_for.txt b/cmd/pint/tests/0142_keep_firing_for.txt index d8151d61..c1592223 100644 --- a/cmd/pint/tests/0142_keep_firing_for.txt +++ b/cmd/pint/tests/0142_keep_firing_for.txt @@ -3,7 +3,7 @@ pint.ok --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl -- rules/0001.yml -- - alert: Instance Is Down 1 expr: up == 0 @@ -12,4 +12,4 @@ level=info msg="Loading configuration file" path=.pint.hcl -- .pint.hcl -- parser { relaxed = [".*"] -} \ No newline at end of file +} diff --git a/cmd/pint/tests/0143_keep_firing_for.txt b/cmd/pint/tests/0143_keep_firing_for.txt index dca27356..6f6c487c 100644 --- a/cmd/pint/tests/0143_keep_firing_for.txt +++ b/cmd/pint/tests/0143_keep_firing_for.txt @@ -3,7 +3,7 @@ pint.error --no-color lint rules cmp stderr stderr.txt -- stderr.txt -- -level=info msg="Loading configuration file" path=.pint.hcl +level=INFO msg="Loading configuration file" path=.pint.hcl rules/0001.yml:6 Bug: this alert rule must have a 'keep_firing_for' field with a minimum duration of 5m (rule/for) 6 | keep_firing_for: 3m @@ -13,8 +13,8 @@ rules/0001.yml:9 Bug: this alert rule must have a 'keep_firing_for' field with a rules/0001.yml:10 Bug: this alert rule must have a 'keep_firing_for' field with a minimum duration of 5m (rule/for) 10 | - alert: none -level=info msg="Problems found" Bug=3 -level=fatal msg="Fatal error" error="found 1 problem(s) with severity Bug or higher" +level=INFO msg="Problems found" Bug=3 +level=ERROR msg="Fatal error" err="found 1 problem(s) with severity Bug or higher" -- rules/0001.yml -- - alert: ok expr: up == 0 diff --git a/cmd/pint/watch.go b/cmd/pint/watch.go index 38435746..3d8f64ab 100644 --- a/cmd/pint/watch.go +++ b/cmd/pint/watch.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log/slog" "net/http" _ "net/http/pprof" "os" @@ -23,7 +24,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" dto "github.com/prometheus/client_model/go" - "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" ) @@ -95,13 +95,13 @@ func actionWatch(c *cli.Context) error { if err != nil { return err } - log.Info().Str("path", pidfile).Msg("Pidfile created") + slog.Info("Pidfile created", slog.String("path", pidfile)) defer func() { pidErr := os.RemoveAll(pidfile) if pidErr != nil { - log.Error().Err(pidErr).Str("path", pidfile).Msg("Failed to remove pidfile") + slog.Error("Failed to remove pidfile", slog.Any("err", pidErr), slog.String("path", pidfile)) } - log.Info().Str("path", pidfile).Msg("Pidfile removed") + slog.Info("Pidfile removed", slog.String("path", pidfile)) }() } @@ -134,10 +134,10 @@ func actionWatch(c *cli.Context) error { } go func() { if httpErr := server.ListenAndServe(); !errors.Is(httpErr, http.ErrServerClosed) { - log.Error().Err(httpErr).Str("listen", listen).Msg("HTTP server returned an error") + slog.Error("HTTP server returned an error", slog.Any("err", httpErr), slog.String("listen", listen)) } }() - log.Info().Str("address", listen).Msg("Started HTTP server") + slog.Info("Started HTTP server", slog.String("address", listen)) interval := c.Duration(intervalFlag) @@ -154,11 +154,11 @@ func actionWatch(c *cli.Context) error { signal.Notify(quit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) <-quit - log.Info().Msg("Shutting down") + slog.Info("Shutting down") mainCancel() stop <- true - log.Info().Msg("Waiting for all background tasks to finish") + slog.Info("Waiting for all background tasks to finish") <-ack for _, prom := range meta.cfg.PrometheusServers { @@ -168,7 +168,7 @@ func actionWatch(c *cli.Context) error { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() if err = server.Shutdown(ctx); err != nil { - log.Error().Err(err).Msg("HTTP server returned an error while shutting down") + slog.Error("HTTP server returned an error while shutting down", slog.Any("err", err)) } return nil @@ -183,24 +183,24 @@ func startTimer(ctx context.Context, _ config.Config, workers int, interval time for { select { case <-ticker.C: - log.Debug().Msg("Running checks") + slog.Debug("Running checks") if !wasBootstrapped { ticker.Reset(interval) wasBootstrapped = true } if err := collector.scan(ctx, workers); err != nil { - log.Error().Err(err).Msg("Got an error when running checks") + slog.Error("Got an error when running checks", slog.Any("err", err)) } checkIterationsTotal.Inc() case <-stop: ticker.Stop() - log.Info().Msg("Background worker finished") + slog.Info("Background worker finished") ack <- true return } } }() - log.Info().Stringer("interval", interval).Msg("Will continuously run checks until terminated") + slog.Info("Will continuously run checks until terminated", slog.String("interval", interval.String())) return stop } @@ -293,7 +293,7 @@ func (c *problemCollector) Collect(ch chan<- prometheus.Metric) { for _, report := range c.summary.Reports() { if report.Problem.Severity < c.minSeverity { - log.Debug().Stringer("severity", report.Problem.Severity).Msg("Skipping report") + slog.Debug("Skipping report", slog.String("severity", report.Problem.Severity.String())) continue } @@ -323,7 +323,7 @@ func (c *problemCollector) Collect(ch chan<- prometheus.Metric) { var out dto.Metric err := metric.Write(&out) if err != nil { - log.Error().Err(err).Msg("Failed to write metric to a buffer") + slog.Error("Failed to write metric to a buffer", slog.Any("err", err)) continue } diff --git a/go.mod b/go.mod index 7691a2f7..b75ce657 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/prometheus/prometheus v0.47.2 github.com/prymitive/current v0.1.0 github.com/rogpeppe/go-internal v1.11.0 - github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 github.com/zclconf/go-cty v1.14.1 diff --git a/go.sum b/go.sum index d7d1bef8..f115d6cf 100644 --- a/go.sum +++ b/go.sum @@ -59,7 +59,6 @@ github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEM github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -127,7 +126,6 @@ github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg= github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -322,9 +320,6 @@ github.com/prymitive/current v0.1.0/go.mod h1:ZKbTBHjDMGAM3YPcnkA2I4L5U/vYfbXyVT github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= -github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.20 h1:a9hSJdJcd16e0HoMsnFvaHvxB3pxSD+SC7+CISp7xY0= @@ -448,7 +443,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/internal/checks/alerts_count.go b/internal/checks/alerts_count.go index 7e2f2deb..dc884ac2 100644 --- a/internal/checks/alerts_count.go +++ b/internal/checks/alerts_count.go @@ -3,11 +3,11 @@ package checks import ( "context" "fmt" + "log/slog" "sort" "time" "github.com/prometheus/common/model" - "github.com/rs/zerolog/log" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/output" @@ -78,7 +78,7 @@ func (c AlertsCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ [] if len(qr.Series.Ranges) > 0 { promUptime, err := c.prom.RangeQuery(ctx, "count(up)", params) if err != nil { - log.Warn().Err(err).Str("name", c.prom.Name()).Msg("Cannot detect Prometheus uptime gaps") + slog.Warn("Cannot detect Prometheus uptime gaps", slog.Any("err", err), slog.String("name", c.prom.Name())) } else { // FIXME: gaps are not used qr.Series.FindGaps(promUptime.Series, qr.Series.From, qr.Series.Until) diff --git a/internal/checks/base_test.go b/internal/checks/base_test.go index c1f40955..c7e5dba3 100644 --- a/internal/checks/base_test.go +++ b/internal/checks/base_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "net/http/httptest" "strconv" @@ -15,12 +16,11 @@ import ( v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "github.com/stretchr/testify/require" "github.com/cloudflare/pint/internal/checks" "github.com/cloudflare/pint/internal/discovery" + "github.com/cloudflare/pint/internal/log" "github.com/cloudflare/pint/internal/output" "github.com/cloudflare/pint/internal/parser" "github.com/cloudflare/pint/internal/promapi" @@ -104,7 +104,7 @@ type checkTest struct { } func runTests(t *testing.T, testCases []checkTest) { - zerolog.SetGlobalLevel(zerolog.FatalLevel) + log.Level.Set(slog.LevelError) for _, tc := range testCases { // original test t.Run(tc.description, func(t *testing.T) { @@ -547,13 +547,14 @@ func generateSampleStream(labels map[string]string, from, until time.Time, step }) from = from.Add(step) } - log.Debug(). - Stringer("labels", metric). - Str("from", from.UTC().Format(time.RFC3339Nano)). - Str("until", until.UTC().Format(time.RFC3339Nano)). - Str("step", output.HumanizeDuration(step)). - Int("samples", len(s.Values)). - Msg("Generating sample stream for tests") + slog.Debug( + "Generating sample stream for tests", + slog.String("labels", metric.String()), + slog.String("from", from.UTC().Format(time.RFC3339Nano)), + slog.String("until", until.UTC().Format(time.RFC3339Nano)), + slog.String("step", output.HumanizeDuration(step)), + slog.Int("samples", len(s.Values)), + ) return s } diff --git a/internal/checks/promql_aggregation.go b/internal/checks/promql_aggregation.go index 9ed249a6..bca216b0 100644 --- a/internal/checks/promql_aggregation.go +++ b/internal/checks/promql_aggregation.go @@ -3,8 +3,7 @@ package checks import ( "context" "fmt" - - "github.com/rs/zerolog/log" + "log/slog" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" @@ -97,7 +96,7 @@ func (c AggregationCheck) checkNode(node *parser.PromQLNode) (problems []exprPro goto NEXT case promParser.QUANTILE: default: - log.Warn().Str("op", n.Op.String()).Msg("Unsupported aggregation operation") + slog.Warn("Unsupported aggregation operation", slog.String("op", n.Op.String())) } if !n.Without && !c.keep && len(n.Grouping) == 0 { @@ -169,7 +168,7 @@ NEXT: problems = append(problems, c.checkNode(node.Children[1])...) return problems default: - log.Warn().Str("matching", n.VectorMatching.Card.String()).Msg("Unsupported VectorMatching operation") + slog.Warn("Unsupported VectorMatching operation", slog.String("matching", n.VectorMatching.Card.String())) } } diff --git a/internal/checks/promql_series.go b/internal/checks/promql_series.go index e8423287..f2ad3c6a 100644 --- a/internal/checks/promql_series.go +++ b/internal/checks/promql_series.go @@ -3,11 +3,11 @@ package checks import ( "context" "fmt" + "log/slog" "regexp" "strings" "time" - "github.com/rs/zerolog/log" "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/discovery" @@ -144,7 +144,11 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr } } if arEntry != nil { - log.Debug().Stringer("selector", &selector).Str("path", arEntry.SourcePath).Msg("Metric is provided by alerting rule") + slog.Debug( + "Metric is provided by alerting rule", + slog.String("selector", (&selector).String()), + slog.String("path", arEntry.SourcePath), + ) } else { problems = append(problems, Problem{ Fragment: selector.String(), @@ -174,32 +178,34 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr } // 1. If foo{bar, baz} is there -> GOOD - log.Debug().Str("check", c.Reporter()).Stringer("selector", &selector).Msg("Checking if selector returns anything") + slog.Debug("Checking if selector returns anything", slog.String("check", c.Reporter()), slog.String("selector", (&selector).String())) count, _, err := c.instantSeriesCount(ctx, fmt.Sprintf("count(%s)", selector.String())) if err != nil { problems = append(problems, c.queryProblem(err, selector.String(), expr)) continue } if count > 0 { - log.Debug().Str("check", c.Reporter()).Stringer("selector", &selector).Msg("Found series, skipping further checks") + slog.Debug("Found series, skipping further checks", slog.String("check", c.Reporter()), slog.String("selector", (&selector).String())) continue } promUptime, err := c.prom.RangeQuery(ctx, fmt.Sprintf("count(%s)", c.prom.UptimeMetric()), params) if err != nil { - log.Warn().Err(err).Str("name", c.prom.Name()).Msg("Cannot detect Prometheus uptime gaps") + slog.Warn("Cannot detect Prometheus uptime gaps", slog.Any("err", err), slog.String("name", c.prom.Name())) } if promUptime != nil && promUptime.Series.Ranges.Len() == 0 { - log.Warn(). - Str("name", c.prom.Name()). - Str("metric", c.prom.UptimeMetric()). - Msg("No results for Prometheus uptime metric, you might have set uptime config option to a missing metric, please check your config") + slog.Warn( + "No results for Prometheus uptime metric, you might have set uptime config option to a missing metric, please check your config", + slog.String("name", c.prom.Name()), + slog.String("metric", c.prom.UptimeMetric()), + ) } if promUptime == nil || promUptime.Series.Ranges.Len() == 0 { - log.Warn(). - Str("name", c.prom.Name()). - Str("metric", c.prom.UptimeMetric()). - Msg("Using dummy Prometheus uptime metric results with no gaps") + slog.Warn( + "Using dummy Prometheus uptime metric results with no gaps", + slog.String("name", c.prom.Name()), + slog.String("metric", c.prom.UptimeMetric()), + ) promUptime = &promapi.RangeQueryResult{ Series: promapi.SeriesTimeRanges{ From: params.Start(), @@ -220,7 +226,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr bareSelector := stripLabels(selector) // 2. If foo was NEVER there -> BUG - log.Debug().Str("check", c.Reporter()).Stringer("selector", &bareSelector).Msg("Checking if base metric has historical series") + slog.Debug("Checking if base metric has historical series", slog.String("check", c.Reporter()), slog.String("selector", (&bareSelector).String())) trs, err := c.prom.RangeQuery(ctx, fmt.Sprintf("count(%s)", bareSelector.String()), params) if err != nil { problems = append(problems, c.queryProblem(err, bareSelector.String(), expr)) @@ -241,7 +247,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr } if rrEntry != nil { // Validate recording rule instead - log.Debug().Stringer("selector", &bareSelector).Str("path", rrEntry.SourcePath).Msg("Metric is provided by recording rule") + slog.Debug("Metric is provided by recording rule", slog.String("selector", (&bareSelector).String()), slog.String("path", rrEntry.SourcePath)) problems = append(problems, Problem{ Fragment: bareSelector.String(), Lines: expr.Lines(), @@ -267,7 +273,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr Text: text, Severity: severity, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &bareSelector).Msg("No historical series for base metric") + slog.Debug("No historical series for base metric", slog.String("check", c.Reporter()), slog.String("selector", (&bareSelector).String())) continue } @@ -275,7 +281,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr for _, name := range labelNames { l := stripLabels(selector) l.LabelMatchers = append(l.LabelMatchers, labels.MustNewMatcher(labels.MatchRegexp, name, ".+")) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &l).Str("label", name).Msg("Checking if base metric has historical series with required label") + slog.Debug("Checking if base metric has historical series with required label", slog.String("check", c.Reporter()), slog.String("selector", (&l).String()), slog.String("label", name)) trsLabelCount, err := c.prom.RangeQuery(ctx, fmt.Sprintf("absent(%s)", l.String()), params) if err != nil { problems = append(problems, c.queryProblem(err, selector.String(), expr)) @@ -305,7 +311,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr promText(c.prom.Name(), trsLabelCount.URI), bareSelector.String(), name, sinceDesc(trsLabelCount.Series.From)), Severity: Bug, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &l).Str("label", name).Msg("No historical series with label used for the query") + slog.Debug("No historical series with label used for the query", slog.String("check", c.Reporter()), slog.String("selector", (&l).String()), slog.String("label", name)) } } if len(problems) > 0 { @@ -323,12 +329,13 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr } if !newest(trs.Series.Ranges).Before(trs.Series.Until.Add(minAge * -1)) { - log.Debug(). - Str("check", c.Reporter()). - Stringer("selector", &selector). - Str("min-age", output.HumanizeDuration(minAge)). - Str("last-seen", sinceDesc(newest(trs.Series.Ranges))). - Msg("Series disappeared from prometheus but for less then configured min-age") + slog.Debug( + "Series disappeared from prometheus but for less then configured min-age", + slog.String("check", c.Reporter()), + slog.String("selector", (&selector).String()), + slog.String("min-age", output.HumanizeDuration(minAge)), + slog.String("last-seen", sinceDesc(newest(trs.Series.Ranges))), + ) continue } @@ -347,7 +354,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr Text: text, Severity: severity, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &bareSelector).Msg("Series disappeared from prometheus") + slog.Debug("Series disappeared from prometheus", slog.String("check", c.Reporter()), slog.String("selector", (&bareSelector).String())) continue } @@ -359,7 +366,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr continue } if c.isLabelValueIgnored(rule, selector, lm.Name) { - log.Debug().Stringer("selector", &selector).Str("label", lm.Name).Msg("Label check disabled by comment") + slog.Debug("Label check disabled by comment", slog.String("selector", (&selector).String()), slog.String("label", lm.Name)) continue } labelSelector := promParser.VectorSelector{ @@ -367,7 +374,7 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr LabelMatchers: []*labels.Matcher{lm}, } addNameSelectorIfNeeded(&labelSelector, selector.LabelMatchers) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &labelSelector).Stringer("matcher", lm).Msg("Checking if there are historical series matching filter") + slog.Debug("Checking if there are historical series matching filter", slog.String("check", c.Reporter()), slog.String("selector", (&labelSelector).String()), slog.String("matcher", lm.String())) trsLabel, err := c.prom.RangeQuery(ctx, fmt.Sprintf("count(%s)", labelSelector.String()), params) if err != nil { @@ -393,7 +400,8 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr Text: text, Severity: severity, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &selector).Stringer("matcher", lm).Msg("No historical series matching filter used in the query") + slog.Debug("No historical series matching filter used in the query", + slog.String("check", c.Reporter()), slog.String("selector", (&selector).String()), slog.String("matcher", lm.String())) continue } @@ -428,12 +436,13 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr } if !newest(trsLabel.Series.Ranges).Before(trsLabel.Series.Until.Add(minAge * -1)) { - log.Debug(). - Str("check", c.Reporter()). - Stringer("selector", &selector). - Str("min-age", output.HumanizeDuration(minAge)). - Str("last-seen", sinceDesc(newest(trsLabel.Series.Ranges))). - Msg("Series disappeared from prometheus but for less then configured min-age") + slog.Debug( + "Series disappeared from prometheus but for less then configured min-age", + slog.String("check", c.Reporter()), + slog.String("selector", (&selector).String()), + slog.String("min-age", output.HumanizeDuration(minAge)), + slog.String("last-seen", sinceDesc(newest(trsLabel.Series.Ranges))), + ) continue } @@ -452,7 +461,12 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr Text: text, Severity: severity, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &selector).Stringer("matcher", lm).Msg("Series matching filter disappeared from prometheus ") + slog.Debug( + "Series matching filter disappeared from prometheus", + slog.String("check", c.Reporter()), + slog.String("selector", (&selector).String()), + slog.String("matcher", lm.String()), + ) continue } @@ -468,7 +482,12 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr output.HumanizeDuration(avgLife(trsLabel.Series.Ranges))), Severity: Warning, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &selector).Stringer("matcher", lm).Msg("Series matching filter are only sometimes present") + slog.Debug( + "Series matching filter are only sometimes present", + slog.String("check", c.Reporter()), + slog.String("selector", (&selector).String()), + slog.String("matcher", lm.String()), + ) } } if len(problems) > 0 { @@ -486,7 +505,11 @@ func (c SeriesCheck) Check(ctx context.Context, _ string, rule parser.Rule, entr bareSelector.String(), promText(c.prom.Name(), trs.URI), output.HumanizeDuration(avgLife(trs.Series.Ranges)), sinceDesc(trs.Series.From)), Severity: Warning, }) - log.Debug().Str("check", c.Reporter()).Stringer("selector", &bareSelector).Msg("Metric only sometimes present") + slog.Debug( + "Metric only sometimes present", + slog.String("check", c.Reporter()), + slog.String("selector", (&bareSelector).String()), + ) } } @@ -563,7 +586,11 @@ func (c SeriesCheck) isLabelValueIgnored(rule parser.Rule, selector promParser.V func (c SeriesCheck) textAndSeverity(settings *PromqlSeriesSettings, name, text string, s Severity) (string, Severity) { for _, re := range settings.ignoreMetricsRe { if name != "" && re.MatchString(name) { - log.Debug().Str("check", c.Reporter()).Str("metric", name).Stringer("regexp", re).Msg("Metric matches check ignore rules") + slog.Debug( + "Metric matches check ignore rules", + slog.String("check", c.Reporter()), + slog.String("metric", name), + slog.String("regexp", re.String())) return fmt.Sprintf("%s. Metric name %q matches %q check ignore regexp %q", text, name, c.Reporter(), re), Warning } } diff --git a/internal/checks/rule_link.go b/internal/checks/rule_link.go index 954bfd57..0034757c 100644 --- a/internal/checks/rule_link.go +++ b/internal/checks/rule_link.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "log/slog" "net/http" "net/url" "regexp" @@ -11,8 +12,6 @@ import ( "golang.org/x/exp/slices" - "github.com/rs/zerolog/log" - "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" ) @@ -78,14 +77,14 @@ func (c RuleLinkCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ } uri = u.String() - log.Debug().Str("link", uri).Msg("Found link to check") + slog.Debug("Found link to check", slog.String("link", uri)) if c.uriRewrite != "" { var result []byte for _, submatches := range re.FindAllStringSubmatchIndex(uri, -1) { result = re.ExpandString(result, c.uriRewrite, uri, submatches) } uri = string(result) - log.Debug().Stringer("link", u).Str("uri", uri).Msg("Link URI rewritten by rule") + slog.Debug("Link URI rewritten by rule", slog.String("link", u.String()), slog.String("uri", uri)) } rctx, cancel := context.WithTimeout(ctx, c.timeout) @@ -106,7 +105,7 @@ func (c RuleLinkCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ Text: fmt.Sprintf("GET request for %s returned an error: %s", uri, err), Severity: c.severity, }) - log.Debug().Str("uri", uri).Err(err).Msg("Link request returned an error") + slog.Debug("Link request returned an error", slog.String("uri", uri), slog.Any("err", err)) continue } _, _ = io.Copy(io.Discard, resp.Body) @@ -120,10 +119,10 @@ func (c RuleLinkCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ Text: fmt.Sprintf("GET request for %s returned invalid status code: %s", uri, resp.Status), Severity: c.severity, }) - log.Debug().Str("uri", uri).Str("status", resp.Status).Msg("Link request returned invalid status code") + slog.Debug("Link request returned invalid status code", slog.String("uri", uri), slog.String("status", resp.Status)) continue } - log.Debug().Str("uri", uri).Str("status", resp.Status).Msg("Link request returned a valid status code") + slog.Debug("Link request returned a valid status code", slog.String("uri", uri), slog.String("status", resp.Status)) } return problems diff --git a/internal/config/__snapshots__/config_test.snap b/internal/config/__snapshots__/config_test.snap index b9d8ef68..935e2425 100755 --- a/internal/config/__snapshots__/config_test.snap +++ b/internal/config/__snapshots__/config_test.snap @@ -2214,6 +2214,156 @@ } --- +[TestGetChecksForRule/for_match_/_passing#01 - 1] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "match": [ + { + "keep_firing_for": "\u003e 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/for_match_/_passing#02 - 1] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "match": [ + { + "keep_firing_for": "\u003e 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/for_match_/_passing#03 - 1] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "match": [ + { + "keep_firing_for": "\u003e 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + [TestGetChecksForRule/defaults - 2] { "ci": { @@ -3859,7 +4009,7 @@ } --- -[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 2] +[TestGetChecksForRule/for_match_/_passing#01 - 2] { "ci": { "maxCommits": 20, @@ -3894,7 +4044,7 @@ { "match": [ { - "for": "!= 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -3909,7 +4059,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_passing - 2] +[TestGetChecksForRule/for_match_/_passing#02 - 2] { "ci": { "maxCommits": 20, @@ -3942,9 +4092,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -3959,7 +4109,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_not_passing - 2] +[TestGetChecksForRule/for_match_/_passing#03 - 2] { "ci": { "maxCommits": 20, @@ -3992,9 +4142,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -4009,7 +4159,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 2] +[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 2] { "ci": { "maxCommits": 20, @@ -4042,9 +4192,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003e 0" + "for": "!= 15m" } ], "annotation": [ @@ -4059,7 +4209,7 @@ } --- -[TestGetChecksForRule/link - 2] +[TestGetChecksForRule/for_ignore_/_passing - 2] { "ci": { "maxCommits": 20, @@ -4092,15 +4242,15 @@ }, "rules": [ { - "link": [ + "ignore": [ { - "key": "https?://(.+)", - "uri": "http://localhost/$1", - "timeout": "10s", - "headers": { - "X-Auth": "xxx" - }, - "severity": "bug" + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true } ] } @@ -4109,33 +4259,13 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 2] +[TestGetChecksForRule/for_ignore_/_not_passing - 2] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], "checks": { "enabled": [ "alerts/annotation", @@ -4158,42 +4288,34 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template" ] }, + "rules": [ + { + "ignore": [ + { + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], "owners": {} } --- -[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 2] +[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 2] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], "checks": { "enabled": [ "alerts/annotation", @@ -4216,10 +4338,188 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template", - "promql/regexp" + ] + }, + "rules": [ + { + "ignore": [ + { + "for": "\u003e 0" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/link - 2] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "link": [ + { + "key": "https?://(.+)", + "uri": "http://localhost/$1", + "timeout": "10s", + "headers": { + "X-Auth": "xxx" + }, + "severity": "bug" + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 2] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ], + "disabled": [ + "alerts/template" + ] + }, + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 2] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ], + "disabled": [ + "alerts/template", + "promql/regexp" ] }, "owners": {} @@ -6074,7 +6374,7 @@ } --- -[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 3] +[TestGetChecksForRule/for_match_/_passing#01 - 3] { "ci": { "maxCommits": 20, @@ -6109,7 +6409,7 @@ { "match": [ { - "for": "!= 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -6124,7 +6424,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_passing - 3] +[TestGetChecksForRule/for_match_/_passing#02 - 3] { "ci": { "maxCommits": 20, @@ -6157,9 +6457,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -6174,7 +6474,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_not_passing - 3] +[TestGetChecksForRule/for_match_/_passing#03 - 3] { "ci": { "maxCommits": 20, @@ -6207,9 +6507,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -6224,7 +6524,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 3] +[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 3] { "ci": { "maxCommits": 20, @@ -6257,9 +6557,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003e 0" + "for": "!= 15m" } ], "annotation": [ @@ -6274,7 +6574,7 @@ } --- -[TestGetChecksForRule/link - 3] +[TestGetChecksForRule/for_ignore_/_passing - 3] { "ci": { "maxCommits": 20, @@ -6307,15 +6607,15 @@ }, "rules": [ { - "link": [ + "ignore": [ { - "key": "https?://(.+)", - "uri": "http://localhost/$1", - "timeout": "10s", - "headers": { - "X-Auth": "xxx" - }, - "severity": "bug" + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true } ] } @@ -6324,33 +6624,13 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 3] +[TestGetChecksForRule/for_ignore_/_not_passing - 3] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], "checks": { "enabled": [ "alerts/annotation", @@ -6373,20 +6653,190 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template" ] }, - "owners": {} -} ---- - -[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 3] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" + "rules": [ + { + "ignore": [ + { + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 3] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "ignore": [ + { + "for": "\u003e 0" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/link - 3] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "link": [ + { + "key": "https?://(.+)", + "uri": "http://localhost/$1", + "timeout": "10s", + "headers": { + "X-Auth": "xxx" + }, + "severity": "bug" + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 3] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ], + "disabled": [ + "alerts/template" + ] + }, + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 3] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" }, "parser": {}, "prometheus": [ @@ -8289,7 +8739,7 @@ } --- -[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 4] +[TestGetChecksForRule/for_match_/_passing#01 - 4] { "ci": { "maxCommits": 20, @@ -8324,7 +8774,7 @@ { "match": [ { - "for": "!= 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -8339,7 +8789,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_passing - 4] +[TestGetChecksForRule/for_match_/_passing#02 - 4] { "ci": { "maxCommits": 20, @@ -8372,9 +8822,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -8389,7 +8839,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_not_passing - 4] +[TestGetChecksForRule/for_match_/_passing#03 - 4] { "ci": { "maxCommits": 20, @@ -8422,9 +8872,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -8439,7 +8889,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 4] +[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 4] { "ci": { "maxCommits": 20, @@ -8472,9 +8922,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003e 0" + "for": "!= 15m" } ], "annotation": [ @@ -8489,7 +8939,7 @@ } --- -[TestGetChecksForRule/link - 4] +[TestGetChecksForRule/for_ignore_/_passing - 4] { "ci": { "maxCommits": 20, @@ -8522,15 +8972,15 @@ }, "rules": [ { - "link": [ + "ignore": [ { - "key": "https?://(.+)", - "uri": "http://localhost/$1", - "timeout": "10s", - "headers": { - "X-Auth": "xxx" - }, - "severity": "bug" + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true } ] } @@ -8539,33 +8989,13 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 4] +[TestGetChecksForRule/for_ignore_/_not_passing - 4] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], "checks": { "enabled": [ "alerts/annotation", @@ -8588,20 +9018,190 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template" ] }, - "owners": {} -} ---- - -[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 4] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" + "rules": [ + { + "ignore": [ + { + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 4] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "ignore": [ + { + "for": "\u003e 0" + } + ], + "annotation": [ + { + "key": "summary", + "required": true + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/link - 4] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ] + }, + "rules": [ + { + "link": [ + { + "key": "https?://(.+)", + "uri": "http://localhost/$1", + "timeout": "10s", + "headers": { + "X-Auth": "xxx" + }, + "severity": "bug" + } + ] + } + ], + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 4] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" + }, + "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], + "checks": { + "enabled": [ + "alerts/annotation", + "alerts/count", + "alerts/for", + "alerts/template", + "labels/conflict", + "promql/aggregate", + "alerts/comparison", + "promql/fragile", + "promql/range_query", + "promql/rate", + "promql/regexp", + "promql/syntax", + "promql/vector_matching", + "query/cost", + "promql/series", + "rule/duplicate", + "rule/for", + "rule/label", + "rule/link", + "rule/reject" + ], + "disabled": [ + "alerts/template" + ] + }, + "owners": {} +} +--- + +[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 4] +{ + "ci": { + "maxCommits": 20, + "baseBranch": "master" }, "parser": {}, "prometheus": [ @@ -10504,7 +11104,7 @@ } --- -[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 5] +[TestGetChecksForRule/for_match_/_passing#01 - 5] { "ci": { "maxCommits": 20, @@ -10539,7 +11139,7 @@ { "match": [ { - "for": "!= 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -10554,7 +11154,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_passing - 5] +[TestGetChecksForRule/for_match_/_passing#02 - 5] { "ci": { "maxCommits": 20, @@ -10587,9 +11187,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -10604,7 +11204,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_not_passing - 5] +[TestGetChecksForRule/for_match_/_passing#03 - 5] { "ci": { "maxCommits": 20, @@ -10637,9 +11237,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003c 15m" + "keep_firing_for": "\u003e 15m" } ], "annotation": [ @@ -10654,7 +11254,7 @@ } --- -[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 5] +[TestGetChecksForRule/for_match_/_recording_rules_/_not_passing - 5] { "ci": { "maxCommits": 20, @@ -10687,9 +11287,9 @@ }, "rules": [ { - "ignore": [ + "match": [ { - "for": "\u003e 0" + "for": "!= 15m" } ], "annotation": [ @@ -10704,7 +11304,7 @@ } --- -[TestGetChecksForRule/link - 5] +[TestGetChecksForRule/for_ignore_/_passing - 5] { "ci": { "maxCommits": 20, @@ -10737,15 +11337,15 @@ }, "rules": [ { - "link": [ + "ignore": [ { - "key": "https?://(.+)", - "uri": "http://localhost/$1", - "timeout": "10s", - "headers": { - "X-Auth": "xxx" - }, - "severity": "bug" + "for": "\u003c 15m" + } + ], + "annotation": [ + { + "key": "summary", + "required": true } ] } @@ -10754,677 +11354,7 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 5] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ], - "disabled": [ - "alerts/template" - ] - }, - "owners": {} -} ---- - -[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 5] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ], - "disabled": [ - "alerts/template", - "promql/regexp" - ] - }, - "owners": {} -} ---- - -[TestGetChecksForRule/two_prometheus_servers_/_expired_snooze - 5] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "1s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - } - ], - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ], - "disabled": [ - "alerts/template", - "promql/regexp" - ] - }, - "owners": {} -} ---- - -[TestGetChecksForRule/tag_disables_all_prometheus_checks - 5] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "tags": [ - "foo", - "disable", - "bar" - ], - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom3", - "uri": "http://localhost/3", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "tags": [ - "foo" - ], - "required": false - } - ], - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "owners": {} -} ---- - -[TestGetChecksForRule/tag_snoozes_all_prometheus_checks - 5] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "prometheus": [ - { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "tags": [ - "foo", - "disable", - "bar" - ], - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "required": false - }, - { - "name": "prom3", - "uri": "http://localhost/3", - "timeout": "2m0s", - "concurrency": 16, - "rateLimit": 100, - "uptime": "up", - "tags": [ - "foo" - ], - "required": false - } - ], - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#01 - 1] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#02 - 1] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#01 - 2] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#02 - 2] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#01 - 3] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#02 - 3] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#01 - 4] -{ - "ci": { - "maxCommits": 20, - "baseBranch": "master" - }, - "parser": {}, - "checks": { - "enabled": [ - "alerts/annotation", - "alerts/count", - "alerts/for", - "alerts/template", - "labels/conflict", - "promql/aggregate", - "alerts/comparison", - "promql/fragile", - "promql/range_query", - "promql/rate", - "promql/regexp", - "promql/syntax", - "promql/vector_matching", - "query/cost", - "promql/series", - "rule/duplicate", - "rule/for", - "rule/label", - "rule/link", - "rule/reject" - ] - }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], - "owners": {} -} ---- - -[TestGetChecksForRule/for_match_/_passing#02 - 4] +[TestGetChecksForRule/for_ignore_/_not_passing - 5] { "ci": { "maxCommits": 20, @@ -11457,9 +11387,9 @@ }, "rules": [ { - "match": [ + "ignore": [ { - "keep_firing_for": "\u003e 15m" + "for": "\u003c 15m" } ], "annotation": [ @@ -11474,7 +11404,7 @@ } --- -[TestGetChecksForRule/for_match_/_passing#01 - 5] +[TestGetChecksForRule/for_ignore_/_recording_rules_/_passing - 5] { "ci": { "maxCommits": 20, @@ -11507,9 +11437,9 @@ }, "rules": [ { - "match": [ + "ignore": [ { - "keep_firing_for": "\u003e 15m" + "for": "\u003e 0" } ], "annotation": [ @@ -11524,7 +11454,7 @@ } --- -[TestGetChecksForRule/for_match_/_passing#02 - 5] +[TestGetChecksForRule/link - 5] { "ci": { "maxCommits": 20, @@ -11557,15 +11487,15 @@ }, "rules": [ { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ + "link": [ { - "key": "summary", - "required": true + "key": "https?://(.+)", + "uri": "http://localhost/$1", + "timeout": "10s", + "headers": { + "X-Auth": "xxx" + }, + "severity": "bug" } ] } @@ -11574,13 +11504,33 @@ } --- -[TestGetChecksForRule/for_match_/_passing#03 - 1] +[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 5] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], "checks": { "enabled": [ "alerts/annotation", @@ -11603,34 +11553,42 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template" ] }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], "owners": {} } --- -[TestGetChecksForRule/for_match_/_passing#03 - 2] +[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 5] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], "checks": { "enabled": [ "alerts/annotation", @@ -11653,34 +11611,43 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template", + "promql/regexp" ] }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], "owners": {} } --- -[TestGetChecksForRule/for_match_/_passing#03 - 3] +[TestGetChecksForRule/two_prometheus_servers_/_expired_snooze - 5] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + } + ], "checks": { "enabled": [ "alerts/annotation", @@ -11703,34 +11670,60 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template", + "promql/regexp" ] }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], "owners": {} } --- -[TestGetChecksForRule/for_match_/_passing#03 - 4] +[TestGetChecksForRule/tag_disables_all_prometheus_checks - 5] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "tags": [ + "foo", + "disable", + "bar" + ], + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom3", + "uri": "http://localhost/3", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "tags": [ + "foo" + ], + "required": false + } + ], "checks": { "enabled": [ "alerts/annotation", @@ -11755,32 +11748,54 @@ "rule/reject" ] }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], "owners": {} } --- -[TestGetChecksForRule/for_match_/_passing#03 - 5] +[TestGetChecksForRule/tag_snoozes_all_prometheus_checks - 5] { "ci": { "maxCommits": 20, "baseBranch": "master" }, "parser": {}, + "prometheus": [ + { + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "tags": [ + "foo", + "disable", + "bar" + ], + "required": false + }, + { + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "required": false + }, + { + "name": "prom3", + "uri": "http://localhost/3", + "timeout": "2m0s", + "concurrency": 16, + "rateLimit": 100, + "uptime": "up", + "tags": [ + "foo" + ], + "required": false + } + ], "checks": { "enabled": [ "alerts/annotation", @@ -11805,21 +11820,6 @@ "rule/reject" ] }, - "rules": [ - { - "match": [ - { - "keep_firing_for": "\u003e 15m" - } - ], - "annotation": [ - { - "key": "summary", - "required": true - } - ] - } - ], "owners": {} } --- diff --git a/internal/config/config.go b/internal/config/config.go index 87fced91..fabacefc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/json" "fmt" + "log/slog" "os" "regexp" "strings" @@ -21,7 +22,6 @@ import ( "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/hclsimple" "github.com/prometheus/common/model" - "github.com/rs/zerolog/log" ) type Config struct { @@ -196,7 +196,7 @@ func (cfg *Config) GetChecksForRule(ctx context.Context, path string, r parser.R } else if r.RecordingRule != nil { name = r.RecordingRule.Record.Value.Value } - log.Debug().Strs("enabled", el).Str("path", path).Str("rule", name).Msg("Configured checks for rule") + slog.Debug("Configured checks for rule", slog.Any("enabled", el), slog.String("path", path), slog.String("rule", name)) return enabled } @@ -229,7 +229,7 @@ func Load(path string, failOnMissing bool) (cfg Config, err error) { } if _, err = os.Stat(path); err == nil || failOnMissing { - log.Info().Str("path", path).Msg("Loading configuration file") + slog.Info("Loading configuration file", slog.String("path", path)) ectx := getContext() err = hclsimple.DecodeFile(path, ectx, &cfg) if err != nil { diff --git a/internal/config/rule.go b/internal/config/rule.go index d369441b..3caf93ae 100644 --- a/internal/config/rule.go +++ b/internal/config/rule.go @@ -3,10 +3,10 @@ package config import ( "context" "fmt" + "log/slog" "regexp" "time" - "github.com/rs/zerolog/log" "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/checks" @@ -283,10 +283,11 @@ func isEnabled(enabledChecks, disabledChecks []string, rule parser.Rule, name st for _, comment := range comments { if rule.HasComment(comment) { - log.Debug(). - Str("check", instance). - Str("comment", comment). - Msg("Check disabled by comment") + slog.Debug( + "Check disabled by comment", + slog.String("check", instance), + slog.String("comment", comment), + ) return false } } @@ -303,12 +304,13 @@ func isEnabled(enabledChecks, disabledChecks []string, rule parser.Rule, name st if !slices.Contains(disabled, s.Text) { continue } - log.Debug(). - Str("check", instance). - Str("comment", comment.String()). - Time("until", s.Until). - Str("snooze", s.Text). - Msg("Check snoozed by comment") + slog.Debug( + "Check snoozed by comment", + slog.String("check", instance), + slog.String("comment", comment.String()), + slog.Time("until", s.Until), + slog.String("snooze", s.Text), + ) return false } diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index c297bfd9..4b274f10 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "io" + "log/slog" "regexp" "strings" @@ -12,8 +13,6 @@ import ( "github.com/cloudflare/pint/internal/output" "github.com/cloudflare/pint/internal/parser" - - "github.com/rs/zerolog/log" ) const ( @@ -119,12 +118,13 @@ func readRules(reportedPath, sourcePath string, r io.Reader, isStrict bool) (ent if !slices.Contains(disabledChecks, s.Text) { disabledChecks = append(disabledChecks, s.Text) } - log.Debug(). - Str("check", s.Text). - Str("comment", comment.String()). - Time("until", s.Until). - Str("snooze", s.Text). - Msg("Check snoozed by comment") + slog.Debug( + "Check snoozed by comment", + slog.String("check", s.Text), + slog.String("comment", comment.String()), + slog.Time("until", s.Until), + slog.String("snooze", s.Text), + ) } if content.Ignored { @@ -165,11 +165,12 @@ func readRules(reportedPath, sourcePath string, r io.Reader, isStrict bool) (ent rules, err := p.Parse(content.Body) if err != nil { - log.Error(). - Err(err). - Str("path", sourcePath). - Str("lines", output.FormatLineRangeString(contentLines)). - Msg("Failed to parse file content") + slog.Error( + "Failed to parse file content", + slog.Any("err", err), + slog.String("path", sourcePath), + slog.String("lines", output.FormatLineRangeString(contentLines)), + ) entries = append(entries, Entry{ ReportedPath: reportedPath, SourcePath: sourcePath, @@ -195,7 +196,7 @@ func readRules(reportedPath, sourcePath string, r io.Reader, isStrict bool) (ent }) } - log.Debug().Str("path", sourcePath).Int("rules", len(entries)).Msg("File parsed") + slog.Debug("File parsed", slog.String("path", sourcePath), slog.Int("rules", len(entries))) return entries, nil } diff --git a/internal/discovery/git_blame.go b/internal/discovery/git_blame.go index ffe563e6..88cc4b1c 100644 --- a/internal/discovery/git_blame.go +++ b/internal/discovery/git_blame.go @@ -2,13 +2,12 @@ package discovery import ( "fmt" + "log/slog" "os" "regexp" "strings" "github.com/cloudflare/pint/internal/git" - - "github.com/rs/zerolog/log" ) func NewGitBlameFinder( @@ -44,7 +43,7 @@ func (f GitBlameFinder) Find() (entries []Entry, err error) { return nil, fmt.Errorf("failed to get the list of commits to scan: %w", err) } - log.Debug().Str("from", cr.From).Str("to", cr.To).Msg("Got commit range from git") + slog.Debug("Got commit range from git", slog.String("from", cr.From), slog.String("to", cr.To)) if f.maxCommits > 0 && len(cr.Commits) > f.maxCommits { return nil, fmt.Errorf("number of commits to check (%d) is higher than maxCommits (%d), exiting", len(cr.Commits), f.maxCommits) @@ -66,9 +65,9 @@ func (f GitBlameFinder) Find() (entries []Entry, err error) { op := parts[0] srcPath := parts[1] dstPath := parts[len(parts)-1] - log.Debug().Str("path", dstPath).Str("commit", commit).Str("change", parts[0]).Msg("Git file change") + slog.Debug("Git file change", slog.String("change", parts[0]), slog.String("path", dstPath), slog.String("commit", commit)) if !f.isPathAllowed(dstPath) { - log.Debug().Str("path", dstPath).Msg("Skipping file due to include/exclude rules") + slog.Debug("Skipping file due to include/exclude rules", slog.String("path", dstPath)) continue } @@ -77,17 +76,17 @@ func (f GitBlameFinder) Find() (entries []Entry, err error) { return nil, fmt.Errorf("failed to get commit message for %s: %w", commit, err) } if strings.Contains(msg, "[skip ci]") { - log.Info().Str("commit", commit).Msg("Found a commit with '[skip ci]', skipping all checks") + slog.Info("Found a commit with '[skip ci]', skipping all checks", slog.String("commit", commit)) return []Entry{}, nil } if strings.Contains(msg, "[no ci]") { - log.Info().Str("commit", commit).Msg("Found a commit with '[no ci]', skipping all checks") + slog.Info("Found a commit with '[no ci]', skipping all checks", slog.String("commit", commit)) return []Entry{}, nil } // ignore directories if isDir, _ := isDirectoryPath(dstPath); isDir { - log.Debug().Str("path", dstPath).Msg("Skipping directory entry change") + slog.Debug("Skipping directory entry change", slog.String("path", dstPath)) continue } diff --git a/internal/discovery/git_branch.go b/internal/discovery/git_branch.go index 603e68e8..51d7105c 100644 --- a/internal/discovery/git_branch.go +++ b/internal/discovery/git_branch.go @@ -3,10 +3,10 @@ package discovery import ( "bytes" "fmt" + "log/slog" "regexp" "strings" - "github.com/rs/zerolog/log" "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/git" @@ -46,7 +46,7 @@ func (f GitBranchFinder) Find() (entries []Entry, err error) { if err != nil { return nil, fmt.Errorf("failed to get the list of commits to scan: %w", err) } - log.Debug().Str("from", cr.From).Str("to", cr.To).Msg("Got commit range from git") + slog.Debug("Got commit range from git", slog.String("from", cr.From), slog.String("to", cr.To)) if len(cr.Commits) > f.maxCommits { return nil, fmt.Errorf("number of commits to check (%d) is higher than maxCommits (%d), exiting", len(cr.Commits), f.maxCommits) @@ -67,7 +67,7 @@ func (f GitBranchFinder) Find() (entries []Entry, err error) { for _, change := range changes { if !f.isPathAllowed(change.Path.After.Name) { - log.Debug().Str("path", change.Path.After.Name).Msg("Skipping file due to include/exclude rules") + slog.Debug("Skipping file due to include/exclude rules", slog.String("path", change.Path.After.Name)) continue } @@ -93,48 +93,53 @@ func (f GitBranchFinder) Find() (entries []Entry, err error) { case me.before == nil && me.after != nil: me.after.State = Added me.after.ModifiedLines = commonLines(change.Body.ModifiedLines, me.after.ModifiedLines) - log.Debug(). - Str("name", me.after.Rule.Name()). - Stringer("state", me.after.State). - Str("path", me.after.SourcePath). - Str("ruleLines", output.FormatLineRangeString(me.after.Rule.Lines())). - Str("modifiedLines", output.FormatLineRangeString(me.after.ModifiedLines)). - Msg("Rule added on HEAD branch") + slog.Debug( + "Rule added on HEAD branch", + slog.String("name", me.after.Rule.Name()), + slog.String("state", me.after.State.String()), + slog.String("path", me.after.SourcePath), + slog.String("ruleLines", output.FormatLineRangeString(me.after.Rule.Lines())), + slog.String("modifiedLines", output.FormatLineRangeString(me.after.ModifiedLines)), + ) entries = append(entries, *me.after) case me.before != nil && me.after != nil: if me.isIdentical { - log.Debug(). - Str("name", me.after.Rule.Name()). - Str("lines", output.FormatLineRangeString(me.after.Rule.Lines())). - Msg("Rule content was not modified on HEAD, identical rule present before") + slog.Debug( + "Rule content was not modified on HEAD, identical rule present before", + slog.String("name", me.after.Rule.Name()), + slog.String("lines", output.FormatLineRangeString(me.after.Rule.Lines())), + ) continue } me.after.State = Modified me.after.ModifiedLines = commonLines(change.Body.ModifiedLines, me.after.ModifiedLines) - log.Debug(). - Str("name", me.after.Rule.Name()). - Stringer("state", me.after.State). - Str("path", me.after.SourcePath). - Str("ruleLines", output.FormatLineRangeString(me.after.Rule.Lines())). - Str("modifiedLines", output.FormatLineRangeString(me.after.ModifiedLines)). - Msg("Rule modified on HEAD branch") + slog.Debug( + "Rule modified on HEAD branch", + slog.String("name", me.after.Rule.Name()), + slog.String("state", me.after.State.String()), + slog.String("path", me.after.SourcePath), + slog.String("ruleLines", output.FormatLineRangeString(me.after.Rule.Lines())), + slog.String("modifiedLines", output.FormatLineRangeString(me.after.ModifiedLines)), + ) entries = append(entries, *me.after) case me.before != nil && me.after == nil: me.before.State = Removed - log.Debug(). - Str("name", me.before.Rule.Name()). - Stringer("state", me.before.State). - Str("path", me.before.SourcePath). - Str("ruleLines", output.FormatLineRangeString(me.before.Rule.Lines())). - Str("modifiedLines", output.FormatLineRangeString(me.before.ModifiedLines)). - Msg("Rule removed on HEAD branch") + slog.Debug( + "Rule removed on HEAD branch", + slog.String("name", me.before.Rule.Name()), + slog.String("state", me.before.State.String()), + slog.String("path", me.before.SourcePath), + slog.String("ruleLines", output.FormatLineRangeString(me.before.Rule.Lines())), + slog.String("modifiedLines", output.FormatLineRangeString(me.before.ModifiedLines)), + ) entries = append(entries, *me.before) default: - log.Debug(). - Stringer("state", me.before.State). - Str("path", me.before.SourcePath). - Str("modifiedLines", output.FormatLineRangeString(me.before.ModifiedLines)). - Msg("Unknown rule") + slog.Debug( + "Unknown rule", + slog.String("state", me.before.State.String()), + slog.String("path", me.before.SourcePath), + slog.String("modifiedLines", output.FormatLineRangeString(me.before.ModifiedLines)), + ) entries = append(entries, *me.after) } } @@ -189,7 +194,9 @@ func (f GitBranchFinder) shouldSkipAllChecks(changes []*git.FileChange) (bool, e } for _, comment := range []string{"[skip ci]", "[no ci]"} { if strings.Contains(msg, comment) { - log.Info().Str("commit", commit).Msgf("Found a commit with '%s', skipping all checks", comment) + slog.Info( + fmt.Sprintf("Found a commit with '%s', skipping all checks", comment), + slog.String("commit", commit)) return true, nil } } diff --git a/internal/discovery/symlinks.go b/internal/discovery/symlinks.go index 2afe0854..342951ea 100644 --- a/internal/discovery/symlinks.go +++ b/internal/discovery/symlinks.go @@ -3,10 +3,9 @@ package discovery import ( "fmt" "io/fs" + "log/slog" "os" "path/filepath" - - "github.com/rs/zerolog/log" ) type symlink struct { @@ -68,7 +67,7 @@ func addSymlinkedEntries(entries []Entry) ([]Entry, error) { for _, sl := range slinks { if sl.to == entry.SourcePath { - log.Debug().Str("to", sl.to).Str("from", sl.from).Msg("Found a symlink") + slog.Debug("Found a symlink", slog.String("to", sl.to), slog.String("from", sl.from)) nentries = append(nentries, Entry{ ReportedPath: sl.to, SourcePath: sl.from, diff --git a/internal/git/changes.go b/internal/git/changes.go index 9dff8383..0f4edd6e 100644 --- a/internal/git/changes.go +++ b/internal/git/changes.go @@ -4,11 +4,11 @@ import ( "bufio" "bytes" "fmt" + "log/slog" "os" "path" "strings" - "github.com/rs/zerolog/log" "golang.org/x/exp/slices" ) @@ -95,11 +95,11 @@ func Changes(cmd CommandRunner, cr CommitRangeResults) ([]*FileChange, error) { status := FileStatus(parts[0][0]) srcPath := parts[1] dstPath := parts[len(parts)-1] - log.Debug().Str("path", dstPath).Str("commit", commit).Str("change", parts[0]).Msg("Git file change") + slog.Debug("Git file change", slog.String("change", parts[0]), slog.String("path", dstPath), slog.String("commit", commit)) // ignore directories if isDir, _ := isDirectoryPath(dstPath); isDir { - log.Debug().Str("path", dstPath).Msg("Skipping directory entry change") + slog.Debug("Skipping directory entry change", slog.String("path", dstPath)) continue } @@ -137,13 +137,13 @@ func Changes(cmd CommandRunner, cr CommitRangeResults) ([]*FileChange, error) { // so there's both "BEFORE" and "AFTER" change.Body.Before = getContentAtCommit(cmd, commit+"^", change.Path.Before.SymlinkTarget) default: - log.Debug().Str("path", dstPath).Str("commit", commit).Str("change", parts[0]).Msg("Unknown git change") + slog.Debug("Unknown git change", slog.String("path", dstPath), slog.String("commit", commit), slog.String("change", parts[0])) } changes = append(changes, change) } change.Commits = append(change.Commits, commit) } - log.Debug().Int("changes", len(changes)).Msg("Parsed git log") + slog.Debug("Parsed git log", slog.Int("changes", len(changes))) for _, change := range changes { lastCommit := change.Commits[len(change.Commits)-1] @@ -171,7 +171,7 @@ func Changes(cmd CommandRunner, cr CommitRangeResults) ([]*FileChange, error) { // new file body is empty, meaning that every line was modified change.Body.ModifiedLines = CountLines(change.Body.Before) default: - log.Debug().Str("change", fmt.Sprintf("+%v", change)).Msg("Unhandled change") + slog.Debug("Unhandled change", slog.String("change", fmt.Sprintf("+%v", change))) } if change.Path.Before.Name == change.Path.Before.SymlinkTarget { @@ -195,7 +195,7 @@ func getChangeByPath(changes []*FileChange, fpath string) *FileChange { } func getModifiedLines(cmd CommandRunner, commits []string, fpath string) ([]int, error) { - log.Debug().Strs("commits", commits).Str("path", fpath).Msg("Getting list of modified lines") + slog.Debug("Getting list of modified lines", slog.String("commits", fmt.Sprint(commits)), slog.String("path", fpath)) lines, err := Blame(cmd, fpath) if err != nil { return nil, err @@ -215,7 +215,7 @@ func getTypeForPath(cmd CommandRunner, commit, fpath string) PathType { args := []string{"ls-tree", "--format=%(objectmode) %(objecttype) %(path)", commit, fpath} out, err := cmd(args...) if err != nil { - log.Debug().Err(err).Strs("args", args).Msg("git command returned an error") + slog.Debug("git command returned an error", slog.Any("err", err), slog.String("args", fmt.Sprint(args))) return Missing } @@ -266,7 +266,7 @@ func getContentAtCommit(cmd CommandRunner, commit, fpath string) []byte { args := []string{"cat-file", "blob", fmt.Sprintf("%s:%s", commit, fpath)} body, err := cmd(args...) if err != nil { - log.Debug().Err(err).Strs("args", args).Msg("git command returned an error") + slog.Debug("git command returned an error", slog.Any("err", err), slog.String("args", fmt.Sprint(args))) return nil } return body diff --git a/internal/git/git.go b/internal/git/git.go index a8ed5a6e..273fc39b 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -5,11 +5,10 @@ import ( "bytes" "errors" "fmt" + "log/slog" "os/exec" "strconv" "strings" - - "github.com/rs/zerolog/log" ) type LineBlame struct { @@ -25,7 +24,7 @@ type FileBlames map[string]LineBlames type CommandRunner func(args ...string) ([]byte, error) func RunGit(args ...string) (content []byte, err error) { - log.Debug().Strs("args", args).Msg("Running git command") + slog.Debug("Running git command", slog.Any("args", args)) cmd := exec.Command("git", args...) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout @@ -40,7 +39,7 @@ func RunGit(args ...string) (content []byte, err error) { } func Blame(cmd CommandRunner, path string) (lines LineBlames, err error) { - log.Debug().Str("path", path).Msg("Running git blame") + slog.Debug("Running git blame", slog.String("path", path)) output, err := cmd("blame", "--line-porcelain", "--", path) if err != nil { return nil, err @@ -122,7 +121,7 @@ func CommitRange(cmd CommandRunner, baseBranch string) (CommitRangeResults, erro cr.From = line } cr.To = line - log.Debug().Str("commit", line).Msg("Found commit to scan") + slog.Debug("Found commit to scan", slog.String("commit", line)) } } diff --git a/internal/log/handler.go b/internal/log/handler.go new file mode 100644 index 00000000..dfce218c --- /dev/null +++ b/internal/log/handler.go @@ -0,0 +1,141 @@ +package log + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "log/slog" + "strings" + "sync" +) + +const ( + reset = "\033[0m" + dim = "\033[2m" + normal = "\u001B[22m" + + fgHiRed = "\033[91m" + fgHiYellow = "\033[93m" + fgHiBlue = "\033[94m" + fgHiMagenta = "\033[95m" + fgHiCyan = "\033[96m" + fgHiWhite = "\033[97m" +) + +type handler struct { + mtx *sync.Mutex + dst io.Writer + level slog.Level + noColor bool + + escaper *strings.Replacer +} + +func newHandler(dst io.Writer, level slog.Level, noColor bool) *handler { + h := handler{ + mtx: &sync.Mutex{}, + dst: dst, + level: level, + noColor: noColor, + } + h.escaper = strings.NewReplacer(`"`, `\"`) + return &h +} + +func (h *handler) Enabled(_ context.Context, level slog.Level) bool { + return level >= h.level +} + +func (h *handler) Handle(_ context.Context, record slog.Record) error { + buf := bytes.NewBuffer(make([]byte, 0, 256)) + + lc := "" + switch record.Level { + case slog.LevelInfo: + lc = fgHiWhite + case slog.LevelError: + lc = fgHiRed + case slog.LevelWarn: + lc = fgHiYellow + case slog.LevelDebug: + lc = fgHiMagenta + } + h.printKey(buf, "level") + h.printVal(buf, record.Level.String(), lc) + _, _ = buf.WriteString(" ") + h.printKey(buf, "msg") + h.printVal(buf, record.Message, fgHiWhite) + + record.Attrs(func(attr slog.Attr) bool { + _, _ = buf.WriteString(" ") + h.appendAttr(buf, attr) + return true + }) + buf.WriteString("\n") + + h.mtx.Lock() + defer h.mtx.Unlock() + + if _, err := buf.WriteTo(h.dst); err != nil { + return fmt.Errorf("failed to write buffer: %w", err) + } + + return nil +} + +func (h *handler) WithAttrs(_ []slog.Attr) slog.Handler { + return h +} + +func (h *handler) WithGroup(_ string) slog.Handler { + return h +} + +func (h *handler) printKey(buf *bytes.Buffer, s string) { + _, _ = buf.WriteString(h.maybeWriteColor(s+"=", dim)) +} + +func (h *handler) printVal(buf *bytes.Buffer, s, color string) { + if !strings.HasPrefix(s, "[") && !strings.HasPrefix(s, "{") && strings.Contains(s, " ") { + s = "\"" + h.escaper.Replace(s) + "\"" + } + _, _ = buf.WriteString(h.maybeWriteColor(s, color)) +} + +func (h *handler) maybeWriteColor(s, color string) string { + if h.noColor { + return s + } + return fmt.Sprintf("%s%s%s", color, s, reset) +} + +func (h *handler) appendAttr(buf *bytes.Buffer, attr slog.Attr) { + attr.Value = attr.Value.Resolve() + + h.printKey(buf, attr.Key) + + // nolint: exhaustive + switch attr.Value.Kind() { + case slog.KindAny: + switch attr.Value.Any().(type) { + case error: + h.printVal(buf, attr.Value.String(), fgHiRed) + default: + h.printVal(buf, formatAny(attr), fgHiCyan) + } + case slog.KindString: + h.printVal(buf, attr.Value.String(), fgHiCyan) + default: + h.printVal(buf, formatAny(attr), fgHiBlue) + } +} + +func formatAny(attr slog.Attr) string { + data, err := json.Marshal(attr.Value.Any()) + if err != nil { + return attr.Value.String() + } + return string(data) +} diff --git a/internal/log/log.go b/internal/log/log.go new file mode 100644 index 00000000..d19a2125 --- /dev/null +++ b/internal/log/log.go @@ -0,0 +1,31 @@ +package log + +import ( + "fmt" + "log/slog" + "os" + "strings" +) + +var Level = &slog.LevelVar{} + +func Setup(level slog.Leveler, noColor bool) { + Level.Set(level.Level()) + logger := slog.New(newHandler(os.Stderr, Level.Level(), noColor)) + slog.SetDefault(logger) +} + +func ParseLevel(s string) (slog.Leveler, error) { + switch strings.ToLower(s) { + case "error": + return slog.LevelError, nil + case "warn": + return slog.LevelWarn, nil + case "info": + return slog.LevelInfo, nil + case "debug": + return slog.LevelDebug, nil + default: + return nil, fmt.Errorf("%q is not a valid log level", s) + } +} diff --git a/internal/parser/utils/absent.go b/internal/parser/utils/absent.go index f6355b76..e6cf5ea8 100644 --- a/internal/parser/utils/absent.go +++ b/internal/parser/utils/absent.go @@ -1,10 +1,11 @@ package utils import ( + "log/slog" + "github.com/cloudflare/pint/internal/parser" promParser "github.com/prometheus/prometheus/promql/parser" - "github.com/rs/zerolog/log" ) type PromQLFragment struct { @@ -63,7 +64,7 @@ func HasOuterAbsent(node *parser.PromQLNode) (calls []PromQLFragment) { } default: - log.Warn().Str("matching", n.VectorMatching.Card.String()).Msg("Unsupported VectorMatching operation") + slog.Warn("Unsupported VectorMatching operation", slog.String("matching", n.VectorMatching.Card.String())) } return calls } diff --git a/internal/parser/utils/aggregation.go b/internal/parser/utils/aggregation.go index 9e8d8059..f9709f00 100644 --- a/internal/parser/utils/aggregation.go +++ b/internal/parser/utils/aggregation.go @@ -1,10 +1,11 @@ package utils import ( + "log/slog" + "github.com/cloudflare/pint/internal/parser" promParser "github.com/prometheus/prometheus/promql/parser" - "github.com/rs/zerolog/log" ) func HasOuterAggregation(node *parser.PromQLNode) (aggs []*promParser.AggregateExpr) { @@ -25,7 +26,7 @@ func HasOuterAggregation(node *parser.PromQLNode) (aggs []*promParser.AggregateE goto NEXT case promParser.QUANTILE: default: - log.Warn().Str("op", n.Op.String()).Msg("Unsupported aggregation operation") + slog.Warn("Unsupported aggregation operation", slog.String("op", n.Op.String())) } aggs = append(aggs, n) return aggs @@ -54,7 +55,7 @@ NEXT: return a case promParser.CardManyToMany: default: - log.Warn().Str("matching", n.VectorMatching.Card.String()).Msg("Unsupported VectorMatching operation") + slog.Warn("Unsupported VectorMatching operation", slog.String("matching", n.VectorMatching.Card.String())) } } diff --git a/internal/parser/utils/rate.go b/internal/parser/utils/rate.go index 74694646..6d333bfc 100644 --- a/internal/parser/utils/rate.go +++ b/internal/parser/utils/rate.go @@ -1,8 +1,9 @@ package utils import ( + "log/slog" + promParser "github.com/prometheus/prometheus/promql/parser" - "github.com/rs/zerolog/log" "github.com/cloudflare/pint/internal/parser" ) @@ -41,7 +42,7 @@ func HasOuterRate(node *parser.PromQLNode) (calls []*promParser.Call) { return HasOuterRate(node.Children[0]) case promParser.CardManyToMany: default: - log.Warn().Str("matching", n.VectorMatching.Card.String()).Msg("Unsupported VectorMatching operation") + slog.Warn("Unsupported VectorMatching operation", slog.String("matching", n.VectorMatching.Card.String())) } } diff --git a/internal/parser/utils/sum.go b/internal/parser/utils/sum.go index 91aa23b1..6cce6cd3 100644 --- a/internal/parser/utils/sum.go +++ b/internal/parser/utils/sum.go @@ -1,8 +1,9 @@ package utils import ( + "log/slog" + promParser "github.com/prometheus/prometheus/promql/parser" - "github.com/rs/zerolog/log" "github.com/cloudflare/pint/internal/parser" ) @@ -38,7 +39,7 @@ func HasOuterSum(node *parser.PromQLNode) (calls []*promParser.AggregateExpr) { return HasOuterSum(node.Children[0]) case promParser.CardManyToMany: default: - log.Warn().Str("matching", n.VectorMatching.Card.String()).Msg("Unsupported VectorMatching operation") + slog.Warn("Unsupported VectorMatching operation", slog.String("matching", n.VectorMatching.Card.String())) } } diff --git a/internal/promapi/config.go b/internal/promapi/config.go index 638007d6..d3d4228c 100644 --- a/internal/promapi/config.go +++ b/internal/promapi/config.go @@ -5,13 +5,13 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "net/url" "time" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prymitive/current" - "github.com/rs/zerolog/log" "gopkg.in/yaml.v3" ) @@ -38,9 +38,7 @@ type configQuery struct { } func (q configQuery) Run() queryResult { - log.Debug(). - Str("uri", q.prom.safeURI). - Msg("Getting prometheus configuration") + slog.Debug("Getting prometheus configuration", slog.String("uri", q.prom.safeURI)) ctx, cancel := q.prom.requestContext(q.ctx) defer cancel() @@ -85,7 +83,7 @@ func (q configQuery) CacheTTL() time.Duration { } func (p *Prometheus) Config(ctx context.Context) (*ConfigResult, error) { - log.Debug().Str("uri", p.safeURI).Msg("Scheduling Prometheus configuration query") + slog.Debug("Scheduling Prometheus configuration query", slog.String("uri", p.safeURI)) key := "/api/v1/status/config" p.locker.lock(key) diff --git a/internal/promapi/errors.go b/internal/promapi/errors.go index 6d4f0faf..03b8a608 100644 --- a/internal/promapi/errors.go +++ b/internal/promapi/errors.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "net" "net/http" "strings" @@ -12,7 +13,6 @@ import ( v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prymitive/current" - "github.com/rs/zerolog/log" ) func IsUnavailableError(err error) bool { @@ -103,7 +103,7 @@ func decodeError(err error) string { } func tryDecodingAPIError(resp *http.Response) error { - log.Debug().Int("code", resp.StatusCode).Msg("Trying to parse Prometheus error response") + slog.Debug("Trying to parse Prometheus error response", slog.Int("code", resp.StatusCode)) var status, errType, errText string decoder := current.Object( diff --git a/internal/promapi/flags.go b/internal/promapi/flags.go index 6aae15fd..299b7881 100644 --- a/internal/promapi/flags.go +++ b/internal/promapi/flags.go @@ -5,13 +5,13 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "net/url" "time" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prymitive/current" - "github.com/rs/zerolog/log" ) type FlagsResult struct { @@ -26,9 +26,7 @@ type flagsQuery struct { } func (q flagsQuery) Run() queryResult { - log.Debug(). - Str("uri", q.prom.safeURI). - Msg("Getting prometheus flags") + slog.Debug("Getting prometheus flags", slog.String("uri", q.prom.safeURI)) ctx, cancel := q.prom.requestContext(q.ctx) defer cancel() @@ -70,7 +68,7 @@ func (q flagsQuery) CacheTTL() time.Duration { } func (p *Prometheus) Flags(ctx context.Context) (*FlagsResult, error) { - log.Debug().Str("uri", p.safeURI).Msg("Scheduling Prometheus flags query") + slog.Debug("Scheduling Prometheus flags query", slog.String("uri", p.safeURI)) key := "/api/v1/status/flags" p.locker.lock(key) diff --git a/internal/promapi/metadata.go b/internal/promapi/metadata.go index 9462808e..9090691a 100644 --- a/internal/promapi/metadata.go +++ b/internal/promapi/metadata.go @@ -5,13 +5,13 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "net/url" "time" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prymitive/current" - "github.com/rs/zerolog/log" ) type MetadataResult struct { @@ -27,10 +27,11 @@ type metadataQuery struct { } func (q metadataQuery) Run() queryResult { - log.Debug(). - Str("uri", q.prom.safeURI). - Str("metric", q.metric). - Msg("Getting prometheus metrics metadata") + slog.Debug( + "Getting prometheus metrics metadata", + slog.String("uri", q.prom.safeURI), + slog.String("metric", q.metric), + ) ctx, cancel := q.prom.requestContext(q.ctx) defer cancel() @@ -73,7 +74,7 @@ func (q metadataQuery) CacheTTL() time.Duration { } func (p *Prometheus) Metadata(ctx context.Context, metric string) (*MetadataResult, error) { - log.Debug().Str("uri", p.safeURI).Str("metric", metric).Msg("Scheduling Prometheus metrics metadata query") + slog.Debug("Scheduling Prometheus metrics metadata query", slog.String("uri", p.safeURI), slog.String("metric", metric)) key := fmt.Sprintf("/api/v1/metadata/%s", metric) p.locker.lock(key) diff --git a/internal/promapi/prometheus.go b/internal/promapi/prometheus.go index d7e89aef..4a61c661 100644 --- a/internal/promapi/prometheus.go +++ b/internal/promapi/prometheus.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "errors" "io" + "log/slog" "net/http" "net/url" "strconv" @@ -14,7 +15,6 @@ import ( "github.com/cespare/xxhash/v2" "github.com/klauspost/compress/gzhttp" - "github.com/rs/zerolog/log" "go.uber.org/ratelimit" ) @@ -119,18 +119,18 @@ func NewPrometheus(name, uri string, headers map[string]string, timeout time.Dur } func (prom *Prometheus) Close() { - log.Debug().Str("name", prom.name).Str("uri", prom.safeURI).Msg("Stopping query workers") + slog.Debug("Stopping query workers", slog.String("name", prom.name), slog.String("uri", prom.safeURI)) close(prom.queries) prom.wg.Wait() } func (prom *Prometheus) StartWorkers() { - log.Debug(). - Str("name", prom.name). - Str("uri", prom.safeURI). - Int("workers", prom.concurrency). - Msg("Starting query workers") - + slog.Debug( + "Starting query workers", + slog.String("name", prom.name), + slog.String("uri", prom.safeURI), + slog.Int("workers", prom.concurrency), + ) prom.queries = make(chan queryRequest, prom.concurrency*10) for w := 1; w <= prom.concurrency; w++ { @@ -203,11 +203,12 @@ func processJob(prom *Prometheus, job queryRequest) queryResult { return result } prometheusQueryErrorsTotal.WithLabelValues(prom.name, job.query.Endpoint(), errReason(result.err)).Inc() - log.Error(). - Err(result.err). - Str("uri", prom.safeURI). - Str("query", job.query.String()). - Msg("Query returned an error") + slog.Error( + "Query returned an error", + slog.Any("err", result.err), + slog.String("uri", prom.safeURI), + slog.String("query", job.query.String()), + ) return result } diff --git a/internal/promapi/query.go b/internal/promapi/query.go index b24a3459..43078a26 100644 --- a/internal/promapi/query.go +++ b/internal/promapi/query.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "math" "net/http" "net/url" @@ -14,7 +15,6 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/prymitive/current" - "github.com/rs/zerolog/log" ) type QueryResult struct { @@ -31,10 +31,11 @@ type instantQuery struct { } func (q instantQuery) Run() queryResult { - log.Debug(). - Str("uri", q.prom.safeURI). - Str("query", q.expr). - Msg("Running prometheus query") + slog.Debug( + "Running prometheus query", + slog.String("uri", q.prom.safeURI), + slog.String("query", q.expr), + ) ctx, cancel := q.prom.requestContext(q.ctx) defer cancel() @@ -78,7 +79,7 @@ func (q instantQuery) CacheTTL() time.Duration { } func (p *Prometheus) Query(ctx context.Context, expr string) (*QueryResult, error) { - log.Debug().Str("uri", p.safeURI).Str("query", expr).Msg("Scheduling prometheus query") + slog.Debug("Scheduling prometheus query", slog.String("uri", p.safeURI), slog.String("query", expr)) key := fmt.Sprintf("/api/v1/query/%s", expr) p.locker.lock(key) @@ -100,7 +101,7 @@ func (p *Prometheus) Query(ctx context.Context, expr string) (*QueryResult, erro Series: result.value.([]Sample), Stats: result.stats, } - log.Debug().Str("uri", p.safeURI).Str("query", expr).Int("series", len(qr.Series)).Msg("Parsed response") + slog.Debug("Parsed response", slog.String("uri", p.safeURI), slog.String("query", expr), slog.Int("series", len(qr.Series))) return &qr, nil } diff --git a/internal/promapi/range.go b/internal/promapi/range.go index 194f5c61..e6033df2 100644 --- a/internal/promapi/range.go +++ b/internal/promapi/range.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "log/slog" "math" "net/http" "net/url" @@ -17,7 +18,6 @@ import ( v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" "github.com/prymitive/current" - "github.com/rs/zerolog/log" "github.com/cloudflare/pint/internal/output" ) @@ -107,14 +107,14 @@ func (p *Prometheus) RangeQuery(ctx context.Context, expr string, params RangeQu slices = sliceRange(start, end, step, queryStep) } - log.Debug(). - Str("uri", p.safeURI). - Str("query", expr). - Str("lookback", output.HumanizeDuration(lookback)). - Str("step", output.HumanizeDuration(step)). - Str("slice", output.HumanizeDuration(queryStep)). - Int("slices", len(slices)). - Msg("Scheduling prometheus range query") + slog.Debug("Scheduling prometheus range query", + slog.String("uri", p.safeURI), + slog.String("query", expr), + slog.String("lookback", output.HumanizeDuration(lookback)), + slog.String("step", output.HumanizeDuration(step)), + slog.String("slice", output.HumanizeDuration(queryStep)), + slog.Int("slices", len(slices)), + ) key := fmt.Sprintf("/api/v1/query_range/%s/%s", expr, params.String()) p.locker.lock(key) @@ -199,7 +199,12 @@ func (p *Prometheus) RangeQuery(ctx context.Context, expr string, params RangeQu sort.Stable(merged.Series.Ranges) - log.Debug().Str("uri", p.safeURI).Str("query", expr).Int("samples", len(merged.Series.Ranges)).Msg("Parsed range response") + slog.Debug( + "Parsed range response", + slog.String("uri", p.safeURI), + slog.String("query", expr), + slog.Int("samples", len(merged.Series.Ranges)), + ) return &merged, nil } diff --git a/internal/reporter/bitbucket.go b/internal/reporter/bitbucket.go index 421618bb..6baac57f 100644 --- a/internal/reporter/bitbucket.go +++ b/internal/reporter/bitbucket.go @@ -5,14 +5,13 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "time" "github.com/cloudflare/pint/internal/checks" "github.com/cloudflare/pint/internal/git" "github.com/cloudflare/pint/internal/output" - - "github.com/rs/zerolog/log" ) const ( @@ -90,7 +89,7 @@ func (r BitBucketReporter) Submit(summary Summary) (err error) { if err != nil { return fmt.Errorf("failed to get HEAD commit: %w", err) } - log.Info().Str("commit", headCommit).Msg("Got HEAD commit from git") + slog.Info("Got HEAD commit from git", slog.String("commit", headCommit)) annotations := []BitBucketAnnotation{} for _, report := range summary.Reports() { @@ -118,10 +117,11 @@ func (r BitBucketReporter) Submit(summary Summary) (err error) { func (r BitBucketReporter) makeAnnotation(report Report) (annotations []BitBucketAnnotation) { if !shouldReport(report) { - log.Debug(). - Str("path", report.SourcePath). - Str("lines", output.FormatLineRangeString(report.Problem.Lines)). - Msg("Problem reported on unmodified line, skipping") + slog.Debug( + "Problem reported on unmodified line, skipping", + slog.String("path", report.SourcePath), + slog.String("lines", output.FormatLineRangeString(report.Problem.Lines)), + ) return annotations } @@ -165,8 +165,8 @@ func (r BitBucketReporter) makeAnnotation(report Report) (annotations []BitBucke } func (r BitBucketReporter) bitBucketRequest(method, url string, body []byte) error { - log.Debug().Str("url", url).Str("method", method).Msg("Sending a request to BitBucket") - log.Debug().Bytes("body", body).Msg("Request payload") + slog.Debug("Sending a request to BitBucket", slog.String("method", method), slog.String("url", url)) + slog.Debug("Request payload", slog.String("body", string(body))) req, err := http.NewRequest(method, url, bytes.NewBuffer(body)) if err != nil { return err @@ -184,13 +184,13 @@ func (r BitBucketReporter) bitBucketRequest(method, url string, body []byte) err } defer resp.Body.Close() - log.Debug().Int("status", resp.StatusCode).Msg("BitBucket request completed") + slog.Debug("BitBucket request completed", slog.Int("status", resp.StatusCode)) if resp.StatusCode >= 300 { body, err := io.ReadAll(resp.Body) if err != nil { - log.Error().Err(err).Msg("Failed to read response body") + slog.Error("Failed to read response body", slog.Any("err", err)) } - log.Error().Bytes("body", body).Str("url", url).Int("code", resp.StatusCode).Msg("Got a non 2xx response") + slog.Error("Got a non 2xx response", slog.String("body", string(body)), slog.String("url", url), slog.Int("code", resp.StatusCode)) return fmt.Errorf("%s request failed", method) } diff --git a/internal/reporter/bitbucket_test.go b/internal/reporter/bitbucket_test.go index 7e872322..d2dd11d7 100644 --- a/internal/reporter/bitbucket_test.go +++ b/internal/reporter/bitbucket_test.go @@ -4,23 +4,24 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "net" "net/http" "net/http/httptest" "testing" "time" - "github.com/rs/zerolog" "github.com/stretchr/testify/require" "github.com/cloudflare/pint/internal/checks" "github.com/cloudflare/pint/internal/git" + "github.com/cloudflare/pint/internal/log" "github.com/cloudflare/pint/internal/parser" "github.com/cloudflare/pint/internal/reporter" ) func TestBitBucketReporter(t *testing.T) { - zerolog.SetGlobalLevel(zerolog.FatalLevel) + log.Level.Set(slog.LevelError) type errorCheck func(err error) error diff --git a/internal/reporter/console.go b/internal/reporter/console.go index c4a33dec..09403ea8 100644 --- a/internal/reporter/console.go +++ b/internal/reporter/console.go @@ -3,13 +3,13 @@ package reporter import ( "fmt" "io" + "log/slog" "os" "sort" "strconv" "strings" "github.com/fatih/color" - "github.com/rs/zerolog/log" "golang.org/x/exp/slices" "github.com/cloudflare/pint/internal/checks" @@ -56,10 +56,11 @@ func (cr ConsoleReporter) Submit(summary Summary) error { } if !shouldReport(report) { - log.Debug(). - Str("path", report.SourcePath). - Str("lines", output.FormatLineRangeString(report.Problem.Lines)). - Msg("Problem reported on unmodified line, skipping") + slog.Debug( + "Problem reported on unmodified line, skipping", + slog.String("path", report.SourcePath), + slog.String("lines", output.FormatLineRangeString(report.Problem.Lines)), + ) continue } @@ -95,7 +96,10 @@ func (cr ConsoleReporter) Submit(summary Summary) error { lines := strings.Split(content, "\n") if lastLine > len(lines)-1 { lastLine = len(lines) - 1 - log.Warn().Str("path", report.SourcePath).Msgf("Tried to read more lines than present in the source file, this is likely due to '\n' usage in some rules, see https://github.com/cloudflare/pint/issues/20 for details") + slog.Warn( + "Tried to read more lines than present in the source file, this is likely due to '\n' usage in some rules, see https://github.com/cloudflare/pint/issues/20 for details", + slog.String("path", report.SourcePath), + ) } nrFmt := fmt.Sprintf("%%%dd", countDigits(lastLine)+1) diff --git a/internal/reporter/github.go b/internal/reporter/github.go index 282b6a3a..a5777258 100644 --- a/internal/reporter/github.go +++ b/internal/reporter/github.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "fmt" + "log/slog" "strconv" "strings" "time" "github.com/google/go-github/v55/github" - "github.com/rs/zerolog/log" "golang.org/x/oauth2" "github.com/cloudflare/pint/internal/checks" @@ -70,7 +70,7 @@ func (gr GithubReporter) Submit(summary Summary) error { if err != nil { return fmt.Errorf("failed to get HEAD commit: %w", err) } - log.Info().Str("commit", headCommit).Msg("Got HEAD commit from git") + slog.Info("Got HEAD commit from git", slog.String("commit", headCommit)) review, err := gr.findExistingReview() if err != nil { @@ -108,7 +108,7 @@ func (gr GithubReporter) findExistingReview() (*github.PullRequestReview, error) } func (gr GithubReporter) updateReview(review *github.PullRequestReview, summary Summary) error { - log.Info().Str("repo", fmt.Sprintf("%s/%s", gr.owner, gr.repo)).Msg("Updating pull request review") + slog.Info("Updating pull request review", slog.String("repo", fmt.Sprintf("%s/%s", gr.owner, gr.repo))) ctx, cancel := context.WithTimeout(context.Background(), gr.timeout) defer cancel() @@ -125,7 +125,7 @@ func (gr GithubReporter) updateReview(review *github.PullRequestReview, summary } func (gr GithubReporter) addReviewComments(headCommit string, summary Summary) error { - log.Info().Msg("Creating review comments") + slog.Info("Creating review comments") existingComments, err := gr.getReviewComments() if err != nil { @@ -143,7 +143,7 @@ func (gr GithubReporter) addReviewComments(headCommit string, summary Summary) e } } if found { - log.Debug().Str("body", comment.GetBody()).Str("commit", comment.GetCommitID()).Msg("Comment already exist") + slog.Debug("Comment already exist", slog.String("body", comment.GetBody()), slog.String("commit", comment.GetCommitID())) continue } @@ -164,7 +164,7 @@ func (gr GithubReporter) getReviewComments() ([]*github.PullRequestComment, erro } func (gr GithubReporter) createComment(comment *github.PullRequestComment) error { - log.Debug().Str("body", comment.GetBody()).Str("commit", comment.GetCommitID()).Msg("Creating review comment") + slog.Debug("Creating review comment", slog.String("body", comment.GetBody()), slog.String("commit", comment.GetCommitID())) ctx, cancel := context.WithTimeout(context.Background(), gr.timeout) defer cancel() @@ -174,7 +174,7 @@ func (gr GithubReporter) createComment(comment *github.PullRequestComment) error } func (gr GithubReporter) createReview(headCommit string, summary Summary) error { - log.Info().Str("repo", fmt.Sprintf("%s/%s", gr.owner, gr.repo)).Str("commit", headCommit).Msg("Creating pull request review") + slog.Info("Creating pull request review", slog.String("repo", fmt.Sprintf("%s/%s", gr.owner, gr.repo)), slog.String("commit", headCommit)) ctx, cancel := context.WithTimeout(context.Background(), gr.timeout) defer cancel() @@ -193,7 +193,7 @@ func (gr GithubReporter) createReview(headCommit string, summary Summary) error if err != nil { return fmt.Errorf("failed to create review: %w", err) } - log.Info().Str("status", resp.Status).Msg("Pull request review created") + slog.Info("Pull request review created", slog.String("status", resp.Status)) return nil } diff --git a/internal/reporter/github_test.go b/internal/reporter/github_test.go index d0aa4ded..b74b6fff 100644 --- a/internal/reporter/github_test.go +++ b/internal/reporter/github_test.go @@ -2,22 +2,23 @@ package reporter_test import ( "fmt" + "log/slog" "net/http" "net/http/httptest" "testing" "time" - "github.com/rs/zerolog" "github.com/stretchr/testify/require" "github.com/cloudflare/pint/internal/checks" "github.com/cloudflare/pint/internal/git" + "github.com/cloudflare/pint/internal/log" "github.com/cloudflare/pint/internal/parser" "github.com/cloudflare/pint/internal/reporter" ) func TestGithubReporter(t *testing.T) { - zerolog.SetGlobalLevel(zerolog.FatalLevel) + log.Level.Set(slog.LevelError) type testCaseT struct { description string