Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel to target migration #37

Merged
merged 7 commits into from
Apr 11, 2022
Merged

Panel to target migration #37

merged 7 commits into from
Apr 11, 2022

Conversation

rgeyer
Copy link
Collaborator

@rgeyer rgeyer commented Apr 5, 2022

Several jobs had an anti-pattern of linting a panel, but iterating over that panels targets/queries.

The Target rule type exists for this purpose, and the RuleSet iterates over them externally.

This PR migrates those panel rules to target rules and cleans up a couple minor things along the way.

@rgeyer rgeyer requested a review from tomwilkie April 5, 2022 22:13
Comment on lines +36 to +39
if !panelHasQueries(p) {
// Don't lint certain types of panels.
return ResultSuccess
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this check is necessary anymore, since this will only be run for panels which have targets (so it would naturally exclude rows, text, and other non dataviz panels) and we're already checking that the panel is of the correct "type", namely that it uses a prometheus DS.

default:
t.Errorf("No concrete target required matcher rule for '%s", matcher)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Super minor nit, feel free to ignore) To avoid this I'd be tempter to pass the linter in the testcase structs below, or even stick an inner loop inside the test (will give an example).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agonized over that a bit. Ultimately the bigger problem is getting the error messages to match up with the provided name, so I'll leave it as-is for now.

I'm actually planning some additional changes that will allow specific exceptions to the names of these (sometimes job is actually named cluster, and sometimes instance is actually called node), so I'll refactor the tests at that point.

Thanks for the review!

},
}

testRule(t, linter, dashboard, tc.result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testRule(t, linter, dashboard, tc.result)
for _, linter in []Rule{NewTargetJobRule(), NewTargetInstanceRule()} {
testRule(t, linter, dashboard, tc.result)
}

Copy link
Contributor

@tomwilkie tomwilkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nit, otherwise LGTM - thanks Ryan!

@rgeyer rgeyer merged commit 7b390be into main Apr 11, 2022
@rgeyer rgeyer deleted the panel-to-target-migration branch April 11, 2022 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants