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

Disallow legacy visualizations #610

Merged
merged 24 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package semantic

import (
"path"

"github.com/elastic/kbncontent"
"github.com/elastic/package-spec/v2/code/go/internal/fspath"
"github.com/elastic/package-spec/v2/code/go/internal/pkgpath"
se "github.com/elastic/package-spec/v2/code/go/pkg/specerrors"
drewdaemon marked this conversation as resolved.
Show resolved Hide resolved
)

// ValidateKibanaNoLegacyVisualizations reports legacy Kibana visualizations in a package.
func ValidateKibanaNoLegacyVisualizations(fsys fspath.FS) se.ValidationErrors {
var errs se.ValidationErrors

// Collect by-reference visualizations for reference later.
// Note: this does not include Lens, Maps, or Discover. That's okay for this rule because none of those are legacy
drewdaemon marked this conversation as resolved.
Show resolved Hide resolved
visFilePaths := path.Join("kibana", "visualization", "*.json")
visFiles, _ := pkgpath.Files(fsys, visFilePaths)

for _, file := range visFiles {
visJSON, err := file.Values("$")

if err != nil {
errs = append(errs, se.NewStructuredErrorf("error getting JSON: %w", err))
continue
}


visMap, ok := visJSON.(map[string]interface{})
if !ok {
errs = append(errs, se.NewStructuredErrorf("JSON of unexpected type %T in file %s", visJSON, file.Name()))
continue
}

desc, err := kbncontent.DescribeVisualizationSavedObject(visMap)
if err != nil {
errs = append(errs, se.NewStructuredErrorf("error describing visualization saved object: %w", err))
continue
}

if desc.IsLegacy() {
var editor string
if result, err := desc.Editor(); err == nil {
editor = result
}
errs = append(errs, se.NewStructuredErrorf("file \"%s\" is invalid: found legacy visualization \"%s\" (%s, %s)", fsys.Path(file.Path()), desc.Title(), desc.SemanticType(), editor))
}
}

dashboardFilePaths := path.Join("kibana", "dashboard", "*.json")
dashboardFiles, err := pkgpath.Files(fsys, dashboardFilePaths)
if err != nil {
errs = append(errs, se.NewStructuredErrorf("error finding Kibana dashboard files: %w", err))
return errs
}

for _, file := range dashboardFiles {
dashboardJSON, err := file.Values("$")
if err != nil {
errs = append(errs, se.NewStructuredErrorf("error getting dashboard JSON: %w", err))
drewdaemon marked this conversation as resolved.
Show resolved Hide resolved
continue
}

dashboardTitle, err := kbncontent.GetDashboardTitle(dashboardJSON)
if err != nil {
errs = append(errs, se.NewStructuredErrorf("error fetching dashboard title: %w", err))
continue
}

visualizations, err := kbncontent.DescribeByValueDashboardPanels(dashboardJSON)
if err != nil {
errs = append(errs, se.NewStructuredErrorf("error describing dashboard panels for %s: %w", fsys.Path(file.Path()), err))
continue
}

for _, desc := range visualizations {
if desc.IsLegacy() {
var editor string
if result, err := desc.Editor(); err == nil {
editor = result
}
err := se.NewStructuredErrorf("file \"%s\" is invalid: \"%s\" contains legacy visualization: \"%s\" (%s, %s)", fsys.Path(file.Path()), dashboardTitle, desc.Title(), desc.SemanticType(), editor)
errs = append(errs, err)
}
}
}

return errs
}
1 change: 1 addition & 0 deletions code/go/internal/validator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (s Spec) rules(pkgType string, rootSpec spectypes.ItemSpec) validationRules
{fn: semantic.ValidateRoutingRulesAndDataset, types: []string{"integration"}, since: semver.MustParse("2.9.0")},
{fn: semantic.ValidateKibanaNoDanglingObjectIDs, since: semver.MustParse("3.0.0")},
{fn: semantic.ValidateKibanaFilterPresent, since: semver.MustParse("3.0.0")},
{fn: semantic.ValidateKibanaNoLegacyVisualizations, types: []string{"integration"}, since: semver.MustParse("3.0.0")},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this rule be limited to type "integration"?

Copy link
Contributor

Choose a reason for hiding this comment

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

That should we ok, since input packages are not allowed to have kibana assets, just integration packages.
https://github.com/elastic/package-spec/blob/49120aea627a1652823a7f344ba3d1c9b029fd5a/spec/input/spec.yml

}

var validationRules validationRules
Expand Down
12 changes: 12 additions & 0 deletions code/go/pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ func TestValidateFile(t *testing.T) {
`dangling reference found: bad_dangling_object_ids-8287a5d5-1576-4f3a-83c4-444e9058439c (search) (SVR00003)`,
},
},
"kibana_legacy_visualizations": {
"kibana/dashboard/kibana_legacy_visualizations-c36e9b90-596c-11ee-adef-4fe896364076.json",
[]string{
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"Legacy input control vis\" (input_control_vis, Aggs-based)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"TSVB time series\" (timeseries, TSVB)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"TSVB gauge\" (gauge, TSVB)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"Aggs-based table\" (table, Aggs-based)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"Aggs-based tag cloud\" (tagcloud, Aggs-based)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"\" (heatmap, Aggs-based)",
"\"Dashboard with mixed by-value visualizations\" contains legacy visualization: \"Timelion time series\" (timelion, Timelion)",
},
},
}

for pkgName, test := range tests {
Expand Down
2 changes: 2 additions & 0 deletions compliance/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (
github.com/elastic/go-resource v0.1.1 // indirect
github.com/elastic/go-ucfg v0.8.6 // indirect
github.com/elastic/gojsonschema v1.2.1 // indirect
github.com/elastic/kbncontent v0.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
Expand Down Expand Up @@ -125,6 +126,7 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
Expand Down
5 changes: 4 additions & 1 deletion compliance/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ github.com/elastic/go-ucfg v0.8.6 h1:stUeyh2goTgGX+/wb9gzKvTv0YB0231LTpKUgCKj4U0
github.com/elastic/go-ucfg v0.8.6/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
github.com/elastic/gojsonschema v1.2.1 h1:cUMbgsz0wyEB4x7xf3zUEvUVDl6WCz2RKcQPul8OsQc=
github.com/elastic/gojsonschema v1.2.1/go.mod h1:biw5eBS2Z4T02wjATMRSfecfjCmwaDPvuaqf844gLrg=
github.com/elastic/kbncontent v0.1.0 h1:JTeGDaENizxq8PAmIHvSYVLdmfIYLz0zpUvKGau7go0=
github.com/elastic/kbncontent v0.1.0/go.mod h1:kOPREITK9gSJsiw/WKe7QWSO+PRiZMyEFQCw+CMLAHI=
github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -351,8 +353,9 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/creasty/defaults v1.7.0
github.com/elastic/go-licenser v0.4.1
github.com/elastic/gojsonschema v1.2.1
github.com/elastic/kbncontent v0.1.0
github.com/evanphx/json-patch/v5 v5.7.0
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
github.com/mitchellh/mapstructure v1.5.0
Expand All @@ -33,6 +34,7 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/elastic/go-licenser v0.4.1 h1:1xDURsc8pL5zYT9R29425J3vkHdt4RT5TNEMeRN
github.com/elastic/go-licenser v0.4.1/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/elastic/gojsonschema v1.2.1 h1:cUMbgsz0wyEB4x7xf3zUEvUVDl6WCz2RKcQPul8OsQc=
github.com/elastic/gojsonschema v1.2.1/go.mod h1:biw5eBS2Z4T02wjATMRSfecfjCmwaDPvuaqf844gLrg=
github.com/elastic/kbncontent v0.1.0 h1:JTeGDaENizxq8PAmIHvSYVLdmfIYLz0zpUvKGau7go0=
github.com/elastic/kbncontent v0.1.0/go.mod h1:kOPREITK9gSJsiw/WKe7QWSO+PRiZMyEFQCw+CMLAHI=
github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc=
github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
Expand Down Expand Up @@ -58,8 +60,15 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
Expand Down
3 changes: 3 additions & 0 deletions spec/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
##
- version: 3.0.0-next
changes:
- description: Disallow legacy visualizations
type: breaking-change
link: https://github.com/elastic/package-spec/pull/610
drewdaemon marked this conversation as resolved.
Show resolved Hide resolved
- description: Validate processors used in ingest pipelines
type: breaking-change
link: https://github.com/elastic/package-spec/pull/586
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"attributes": {
"description": "",
"hits": 0,
"panelsJSON": "[]",
"kibanaSavedObjectMeta": {
"searchSourceJSON": {
"filter": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
{
"type": "visualization",
"id": "good_v3-visualization-abc-1",
"type": "visualization"
}
"attributes": {
"description": "",
"kibanaSavedObjectMeta": {
"searchSourceJSON": {
"filter": [],
"query": {
"language": "kuery",
"query": ""
}
}
},
"title": "Placeholder Title",
"uiStateJSON": {},
"version": 1,
"visState": {
"aggs": [],
"params": {
"fontSize": 12,
"markdown": "# A title",
"openLinksInNewTab": false
},
"title": "Placeholder Title",
"type": "markdown"
}
},
"coreMigrationVersion": "8.7.1",
"created_at": "2023-09-22T17:32:48.743Z",
"migrationVersion": {
"visualization": "8.5.0"
},
"references": []
}
5 changes: 5 additions & 0 deletions test/packages/kibana_legacy_visualizations/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- version: 0.1.2
changes:
- description: initial release
type: enhancement
link: https://github.com/elastic/package-spec/pull/160
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main
Loading