-
Notifications
You must be signed in to change notification settings - Fork 24
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
add autofix option #128
add autofix option #128
Conversation
zeitlinger
commented
May 10, 2023
- for 1 rule in the beginning, to see if this is a good idea
- github.com/miracl/conflate has been forked - I'll create a PR upstream if this PR is accpeted - see miracl/conflate@master...zeitlinger:conflate:merge_slice
This looks great. It looks like you implemented auto-fix on the There are a few things which we should consider changing before adding this functionality.
I'd like to see the rules return a
If we implement 1 as I suggested (a "fix" func on the
|
I think I get the idea - it's a good separation of concerns. I've written just one method to make sure this is going into the right direction. Is that what you have in mind? func (f TargetRuleFunc) Lint(d *Dashboard, s *ResultSet) {
for pi, p := range d.GetPanels() {
p := p // capture loop variable
for ti, t := range p.Targets {
t := t // capture loop variable
results := f.fn(*d, p, t)
var rr []Result
for _, r := range results.Results {
var fix func(*Dashboard)
if r.Fix != nil {
fix = func(dashboard *Dashboard) {
r.Fix(*d, p, &t)
p.Targets[ti] = t
d.Panels[pi] = p
}
}
rr = append(rr, Result{
Severity: r.Severity,
Message: r.Message,
Fix: fix,
})
}
s.AddResult(ResultContext{
Result: RuleResults{rr},
Rule: f,
Dashboard: d,
Panel: &p,
Target: &t,
})
}
}
} |
Yes! This is exactly right. This would allow us to conditionally execute the fix, and allow one rule to provide multiple results/fixes. |
@rgeyer finally found the time - please have a look 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you for this contribution!
This PR is quite large, so I won't ask that you add it here, but.. Can you add some brief documentation on the autofix CLI flag, and what the outcome will be?
This should be in the docs/
path. Specifically, it would be useful to add detail to docs/rules/template-on-time-change-reload-rule.md
which explains what happens if autofix is executed for this rule.
Thank you again! 🎉 🚀
Label string `json:"label"` | ||
Type string `json:"type"` | ||
Query interface{} `json:"query"` | ||
Datasource interface{} `json:"datasource,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good abstraction here. I can see value in keeping the original definition of the data source, not only for marshalling into the struct as you do with GetDataSource
but potentially also for other validation/conversion later. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was a necessity actually - to keep the marshall/unmarshall symetric
func (r *TargetRuleResults) AddError(d Dashboard, p Panel, t Target, message string) { | ||
r.Results = append(r.Results, TargetResult{ | ||
Result: Result{ | ||
Severity: Error, | ||
Message: fmt.Sprintf("Dashboard '%s', panel '%s', target idx '%d' %s", d.Title, p.Title, t.Idx, message), | ||
}, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great helpers which will ensure continuity in the error/warning messages. Very good. 🎉
Hi @zeitlinger & @rgeyer - I reverted this due to #136, thought it best to revert first and ask questions later. Please do get this merged again ASAP, once we've figure out what to do about the |
Yes, absolutely. |
Here's the new PR: #138 |