Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func actionCI(ctx context.Context, c *cli.Command) error {
schema := parseSchema(meta.cfg.Parser.Schema)
names := parseNames(meta.cfg.Parser.Names)
allowedOwners := meta.cfg.Owners.CompileAllowed()
var entries []discovery.Entry
var entries []*discovery.Entry
entries, err = discovery.NewGlobFinder([]string{"*"}, filter, schema, names, allowedOwners).Find()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func actionLint(ctx context.Context, c *cli.Command) error {
return nil
}

func verifyOwners(entries []discovery.Entry, allowedOwners []*regexp.Regexp) (reports []reporter.Report) {
func verifyOwners(entries []*discovery.Entry, allowedOwners []*regexp.Regexp) (reports []reporter.Report) {
for _, entry := range entries {
if entry.State == discovery.Removed {
continue
Expand Down
6 changes: 3 additions & 3 deletions cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cloudflare/pint/internal/reporter"
)

func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, cfg config.Config, entries []discovery.Entry) (summary reporter.Summary, err error) {
func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.PrometheusGenerator, cfg config.Config, entries []*discovery.Entry) (summary reporter.Summary, err error) {
slog.LogAttrs(ctx, slog.LevelInfo, "Checking Prometheus rules", slog.Int("entries", len(entries)), slog.Int("workers", workers), slog.Bool("online", !isOffline))
if isOffline {
slog.LogAttrs(ctx, slog.LevelInfo, "Offline mode, skipping Prometheus discovery")
Expand Down Expand Up @@ -143,8 +143,8 @@ func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.Pr

type scanJob struct {
check checks.RuleChecker
allEntries []discovery.Entry
entry discovery.Entry
entry *discovery.Entry
allEntries []*discovery.Entry
}

func scanWorker(ctx context.Context, jobs <-chan scanJob, results chan<- reporter.Report) {
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_absent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c AlertsAbsentCheck) Reporter() string {
return AlertsAbsentCheckName
}

func (c AlertsAbsentCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AlertsAbsentCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c AnnotationCheck) Reporter() string {
return AnnotationCheckName
}

func (c AnnotationCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AnnotationCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c ComparisonCheck) Reporter() string {
return ComparisonCheckName
}

func (c ComparisonCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c ComparisonCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c AlertsCheck) Reporter() string {
return AlertsCheckName
}

func (c AlertsCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AlertsCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_external_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c AlertsExternalLabelsCheck) Reporter() string {
return AlertsExternalLabelsCheckName
}

func (c AlertsExternalLabelsCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AlertsExternalLabelsCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c AlertsForChecksFor) Reporter() string {
return AlertForCheckName
}

func (c AlertsForChecksFor) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AlertsForChecksFor) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c TemplateCheck) Reporter() string {
return TemplateCheckName
}

func (c TemplateCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c TemplateCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
if entry.Rule.AlertingRule == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type RuleChecker interface {
String() string
Reporter() string
Meta() CheckMeta
Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) []Problem
Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) []Problem
}

func problemFromError(err error, rule parser.Rule, reporter, prom string, s Severity) Problem {
Expand Down
8 changes: 4 additions & 4 deletions internal/checks/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type checkTest struct {
snapshot snapshotFn
description string
content string
entries []discovery.Entry
entries []*discovery.Entry
mocks []*prometheusMock
problems bool
contentStrict bool
Expand Down Expand Up @@ -253,7 +253,7 @@ func runTests(t *testing.T, testCases []checkTest) {
}
}

func parseContent(content string, isStrict bool) (entries []discovery.Entry, _ error) {
func parseContent(content string, isStrict bool) (entries []*discovery.Entry, _ error) {
p := parser.NewParser(isStrict, parser.PrometheusSchema, model.UTF8Validation)
file := p.Parse(strings.NewReader(content))
if file.Error.Err != nil {
Expand All @@ -262,7 +262,7 @@ func parseContent(content string, isStrict bool) (entries []discovery.Entry, _ e

for _, group := range file.Groups {
for _, rule := range group.Rules {
entries = append(entries, discovery.Entry{
entries = append(entries, &discovery.Entry{
Path: discovery.Path{
Name: "fake.yml",
SymlinkTarget: "fake.yml",
Expand All @@ -278,7 +278,7 @@ func parseContent(content string, isStrict bool) (entries []discovery.Entry, _ e
return entries, nil
}

func mustParseContent(content string) (entries []discovery.Entry) {
func mustParseContent(content string) (entries []*discovery.Entry) {
entries, err := parseContent(content, false)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/checks/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
This usually means that it's missing some required fields.`
)

func NewErrorCheck(entry discovery.Entry) ErrorCheck {
func NewErrorCheck(entry *discovery.Entry) ErrorCheck {
return ErrorCheck{
problem: parseRuleError(entry.Rule, entry.PathError),
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c ErrorCheck) Reporter() string {
return c.problem.Reporter
}

func (c ErrorCheck) Check(_ context.Context, _ discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c ErrorCheck) Check(_ context.Context, _ *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
problems = append(problems, c.problem)
return problems
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/labels_conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c LabelsConflictCheck) Reporter() string {
return LabelsConflictCheckName
}

func (c LabelsConflictCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c LabelsConflictCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
var labels *parser.YamlMap
if entry.Rule.AlertingRule != nil && entry.Rule.AlertingRule.Expr.SyntaxError == nil && entry.Rule.AlertingRule.Labels != nil {
labels = entry.Rule.AlertingRule.Labels
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c AggregationCheck) Reporter() string {
return AggregationCheckName
}

func (c AggregationCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c AggregationCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c CounterCheck) Reporter() string {
return CounterCheckName
}

func (c CounterCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c CounterCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()

if expr.SyntaxError != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_fragile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c FragileCheck) Reporter() string {
return FragileCheckName
}

func (c FragileCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c FragileCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_impossible.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c ImpossibleCheck) Reporter() string {
return ImpossibleCheckName
}

func (c ImpossibleCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c ImpossibleCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return problems
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_range_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c RangeQueryCheck) Reporter() string {
return RangeQueryCheckName
}

func (c RangeQueryCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c RangeQueryCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return problems
Expand Down
4 changes: 2 additions & 2 deletions internal/checks/promql_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c RateCheck) Reporter() string {
return RateCheckName
}

func (c RateCheck) Check(ctx context.Context, entry discovery.Entry, entries []discovery.Entry) (problems []Problem) {
func (c RateCheck) Check(ctx context.Context, entry *discovery.Entry, entries []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()

if expr.SyntaxError != nil {
Expand All @@ -95,7 +95,7 @@ func (c RateCheck) Check(ctx context.Context, entry discovery.Entry, entries []d
return problems
}

func (c RateCheck) checkNode(ctx context.Context, rule parser.Rule, expr parser.PromQLExpr, node *parser.PromQLNode, entries []discovery.Entry, cfg *promapi.ConfigResult, done *completedList) (problems []Problem) {
func (c RateCheck) checkNode(ctx context.Context, rule parser.Rule, expr parser.PromQLExpr, node *parser.PromQLNode, entries []*discovery.Entry, cfg *promapi.ConfigResult, done *completedList) (problems []Problem) {
if n, ok := node.Expr.(*promParser.Call); ok && (n.Func.Name == "rate" || n.Func.Name == "irate" || n.Func.Name == "deriv") {
for _, arg := range n.Args {
m, ok := arg.(*promParser.MatrixSelector)
Expand Down
4 changes: 2 additions & 2 deletions internal/checks/promql_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestRateCheck(t *testing.T) {
{
description: "sum_over_rate / ignore entry with PathError",
content: "- alert: my alert\n expr: rate(my:sum[5m])\n",
entries: []discovery.Entry{{PathError: errors.New("mock error")}},
entries: []*discovery.Entry{{PathError: errors.New("mock error")}},
checker: newRateCheck,
prometheus: newSimpleProm,
mocks: []*prometheusMock{
Expand All @@ -605,7 +605,7 @@ func TestRateCheck(t *testing.T) {
{
description: "sum_over_rate / ignore entry with rule error",
content: "- alert: my alert\n expr: rate(my:sum[5m])\n",
entries: []discovery.Entry{
entries: []*discovery.Entry{
{
Rule: parser.Rule{
Error: parser.ParseError{
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c RegexpCheck) Reporter() string {
return RegexpCheckName
}

func (c RegexpCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c RegexpCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c SelectorCheck) Reporter() string {
return SelectorCheckName
}

func (c SelectorCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c SelectorCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return problems
Expand Down
6 changes: 3 additions & 3 deletions internal/checks/promql_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c SeriesCheck) Reporter() string {
return SeriesCheckName
}

func (c SeriesCheck) Check(ctx context.Context, entry discovery.Entry, entries []discovery.Entry) (problems []Problem) {
func (c SeriesCheck) Check(ctx context.Context, entry *discovery.Entry, entries []*discovery.Entry) (problems []Problem) {
var settings *PromqlSeriesSettings
if s := ctx.Value(SettingsKey(c.Reporter())); s != nil {
settings = s.(*PromqlSeriesSettings)
Expand Down Expand Up @@ -196,7 +196,7 @@ func (c SeriesCheck) Check(ctx context.Context, entry discovery.Entry, entries [
if entry.Rule.AlertingRule != nil &&
entry.Rule.Error.Err == nil &&
entry.Rule.AlertingRule.Alert.Value == alertname {
arEntry = &entry
arEntry = entry
break
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (c SeriesCheck) Check(ctx context.Context, entry discovery.Entry, entries [
if entries[ei].Rule.RecordingRule != nil &&
entries[ei].Rule.Error.Err == nil &&
entries[ei].Rule.RecordingRule.Record.Value == bareSelectorString {
rrEntry = &entries[ei]
rrEntry = entries[ei]
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c SyntaxCheck) Reporter() string {
return SyntaxCheckName
}

func (c SyntaxCheck) Check(_ context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c SyntaxCheck) Check(_ context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
diag := diags.Diagnostic{
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_vector_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c VectorMatchingCheck) Reporter() string {
return VectorMatchingCheckName
}

func (c VectorMatchingCheck) Check(ctx context.Context, entry discovery.Entry, _ []discovery.Entry) (problems []Problem) {
func (c VectorMatchingCheck) Check(ctx context.Context, entry *discovery.Entry, _ []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/checks/query_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c CostCheck) Reporter() string {
return CostCheckName
}

func (c CostCheck) Check(ctx context.Context, entry discovery.Entry, entries []discovery.Entry) (problems []Problem) {
func (c CostCheck) Check(ctx context.Context, entry *discovery.Entry, entries []*discovery.Entry) (problems []Problem) {
expr := entry.Rule.Expr()

if expr.SyntaxError != nil {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (c CostCheck) getQueryCost(ctx context.Context, expr string) (*promapi.Quer
func (c CostCheck) suggestRecordingRules(
ctx context.Context,
expr parser.PromQLExpr,
entry discovery.Entry, entries []discovery.Entry,
entry *discovery.Entry, entries []*discovery.Entry,
beforeStats promapi.QueryStats, beforeSeries int,
) (problems []Problem) {
src := utils.LabelsSource(expr.Value.Value, expr.Query.Expr)
Expand Down
8 changes: 4 additions & 4 deletions internal/checks/rule_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c RuleDependencyCheck) Reporter() string {
return RuleDependencyCheckName
}

func (c RuleDependencyCheck) Check(_ context.Context, entry discovery.Entry, entries []discovery.Entry) (problems []Problem) {
func (c RuleDependencyCheck) Check(_ context.Context, entry *discovery.Entry, entries []*discovery.Entry) (problems []Problem) {
if entry.Path.Name != entry.Path.SymlinkTarget {
// Don't reported symlinks that are being removed.
return problems
Expand Down Expand Up @@ -134,7 +134,7 @@ func (c RuleDependencyCheck) Check(_ context.Context, entry discovery.Entry, ent
return problems
}

func (c RuleDependencyCheck) usesVector(entry discovery.Entry, name string) *brokenDependency {
func (c RuleDependencyCheck) usesVector(entry *discovery.Entry, name string) *brokenDependency {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand All @@ -155,7 +155,7 @@ func (c RuleDependencyCheck) usesVector(entry discovery.Entry, name string) *bro
return nil
}

func (c RuleDependencyCheck) usesAlert(entry discovery.Entry, name string) *brokenDependency {
func (c RuleDependencyCheck) usesAlert(entry *discovery.Entry, name string) *brokenDependency {
expr := entry.Rule.Expr()
if expr.SyntaxError != nil {
return nil
Expand Down Expand Up @@ -189,7 +189,7 @@ type brokenDependency struct {
line int
}

func nonRemovedEntries(src []discovery.Entry) (dst []discovery.Entry) {
func nonRemovedEntries(src []*discovery.Entry) (dst []*discovery.Entry) {
for _, entry := range src {
if entry.State == discovery.Removed {
continue
Expand Down
Loading
Loading