Skip to content

Commit

Permalink
Add map as another reference type to check to show warnings (#414)
Browse files Browse the repository at this point in the history
Add map as another element to show warning if it is added as a reference
in a dashboard.
  • Loading branch information
mrodm authored Sep 13, 2022
1 parent c8a0fe0 commit 1cbee8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func ValidateVisualizationsUsedByValue(fsys fspath.FS) ve.ValidationErrors {
for _, ref := range references[1:] {
s = fmt.Sprintf("%s, %s (%s)", s, ref.ID, ref.Type)
}

message := fmt.Sprintf("Warning: references found in dashboard %s: %s", filePath, s)
if warningsAsErrors {
errs = append(errs, errors.Errorf("Warning: references found in dashboard %s: %s", filePath, s))
errs = append(errs, errors.New(message))
} else {
log.Printf("Warning: references found in dashboard %s: %s", filePath, s)
log.Printf(message)
}

}
Expand All @@ -82,7 +84,7 @@ func anyReference(val interface{}) ([]reference, error) {
var references []reference
for _, reference := range allReferences {
switch reference.Type {
case "lens", "visualization":
case "lens", "visualization", "map":
references = append(references, reference)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,34 @@ func TestAnyReference(t *testing.T) {
},
map[string]interface{}{
"id": "4",
"name": "panel_1",
"name": "panel_2",
"type": "map",
},
map[string]interface{}{
"id": "42",
"name": "panel_1",
"name": "panel_3",
"type": "index-pattern",
},
map[string]interface{}{
"id": "44",
"name": "panel_4",
"type": "search",
},
map[string]interface{}{
"id": "45",
"name": "panel_5",
"type": "tag",
},
map[string]interface{}{
"id": "50",
"name": "panel_6",
"type": "dashboard",
},
},
[]reference{
{"12345", "panel_0", "visualization"},
{"9000", "panel_1", "lens"},
{"4", "panel_2", "map"},
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions spec/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
link: https://github.com/elastic/package-spec/pull/412
- version: 1.18.1-next
changes:
- description: Prepare for next patch release
- description: Add map as another reference type to check to show warnings
type: enhancement
link: https://github.com/elastic/package-spec/pull/411
link: https://github.com/elastic/package-spec/pull/414
- version: 1.18.0
changes:
- description: Update Go runtime to 1.19.1.
Expand Down

0 comments on commit 1cbee8f

Please sign in to comment.