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

Conversation

v-zhuravlev
Copy link
Contributor

@v-zhuravlev v-zhuravlev commented Dec 9, 2024

Example:

panic: interface conversion: interface {} is []interface {}, not []dashboard.ValueMapOrRangeMapOrRegexMapOrSpecialValueMap

goroutine 1 [running]:
github.com/grafana/dashboard-linter/lint.getValueMappings(...)
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/lint/rule_panel_units.go:136
github.com/grafana/dashboard-linter/lint.NewPanelUnitsRule.func1({{0x0, 0x0, 0x0}, {0xc00039e490, 0x10}, {{0xc00022c2c8, 0x3, 0x4}}, {{0x0, 0x0, ...}}, ...}, ...)
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/lint/rule_panel_units.go:92 +0x6a5
github.com/grafana/dashboard-linter/lint.PanelRuleFunc.Lint({{0x1500a72, 0x10}, {0x1538a1c, 0x34}, 0xc0001130a0}, {{0x0, 0x0, 0x0}, {0xc00039e490, 0x10}, ...}, ...)
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/lint/rules.go:69 +0x276
github.com/grafana/dashboard-linter/lint.(*RuleSet).Lint(0xc0001299c0, {0xc000129a00, 0x1, 0xc00039e490?})
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/lint/rules.go:209 +0x127
main.init.func2(0xc0000ed700?, {0xc000543670?, 0x1?, 0x14f1b27?})
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/main.go:73 +0x510
github.com/spf13/cobra.(*Command).execute(0x2125820, {0xc000543640, 0x1, 0x1})
        /home/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:985 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0x2125de0)
        /home/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /home/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
main.main()
        /home/code/go/pkg/mod/github.com/grafana/[email protected]/main.go:176 +0x1a

when empty mapping is provided:

            "fieldConfig": {
               "overrides": [
                  {
                     "matcher": {
                        "id": "byName",
                        "options": "Topic start offset"
                     },
                     "properties": [
                        {
                           "id": "mappings",
                           "value": [ ]
                        },
                        {
                           "id": "unit",
                           "value": "none"
                        }
                     ]
                  },
...

@v-zhuravlev v-zhuravlev requested a review from rgeyer December 9, 2024 18:48
Comment on lines -83 to -86
if err != nil {
r.AddError(d, p, err.Error())
}
if hasReduceOptionsNonNumericFields(&opts.ReduceOptions) {
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!

@v-zhuravlev v-zhuravlev merged commit 0b7c7a2 into main Dec 10, 2024
7 checks passed
@v-zhuravlev v-zhuravlev deleted the fix_unit_rule branch December 10, 2024 04:22
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.

2 participants