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

unit-rule: Fix panic on grafonnet generated dashboards #218

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
14 changes: 7 additions & 7 deletions lint/rule_panel_units.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func NewPanelUnitsRule() *PanelRuleFunc {
if p.Type == "stat" {
var opts StatOptions
err := json.Unmarshal(p.Options, &opts)
if err != nil {
r.AddError(d, p, err.Error())
}
if hasReduceOptionsNonNumericFields(&opts.ReduceOptions) {
Comment on lines -83 to -86
Copy link
Collaborator

Choose a reason for hiding this comment

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

Had to go to the whole file to grok the change here, I was worried you were skipping the error case ;}

Nice simplification, thank you!

if err == nil && hasReduceOptionsNonNumericFields(&opts.ReduceOptions) {
return r
}
}
Expand Down Expand Up @@ -114,7 +111,7 @@ func getConfiguredUnit(p Panel) string {
if p.FieldConfig != nil && len(p.FieldConfig.Overrides) > 0 {
for _, p := range p.FieldConfig.Overrides {
for _, o := range p.Properties {
if o.Id == "unit" {
if o.Id == "unit" && o.Value != nil {
configuredUnit = o.Value.(string)
}
}
Expand All @@ -128,12 +125,15 @@ func getConfiguredUnit(p Panel) string {

func getValueMappings(p Panel) []dashboard.ValueMapping {
valueMappings := make([]dashboard.ValueMapping, 0)
// First check if an override with unit exists - if no override then check if standard unit is present and valid
// First check if an override with value mapping exists - if no override then check if standard value mapping is present and valid
if p.FieldConfig != nil && len(p.FieldConfig.Overrides) > 0 {
for _, p := range p.FieldConfig.Overrides {
for _, o := range p.Properties {
if o.Id == "mappings" {
valueMappings = o.Value.([]dashboard.ValueMapping)
vm, ok := o.Value.([]dashboard.ValueMapping)
if ok {
valueMappings = vm
}
}
}
}
Expand Down
Loading