Skip to content

Commit c05f1ed

Browse files
committed
Fix formatting of mapStateJSON and layerListJSON in dashboard assets (#28530)
(cherry picked from commit 85d3591)
1 parent f0c5b73 commit c05f1ed

7 files changed

Lines changed: 64 additions & 16 deletions

File tree

auditbeat/tests/system/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from beat import common_tests
1010

1111

12-
class Test(BaseTest, common_tests.TestExportsMixin):
12+
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):
1313
def test_start_stop(self):
1414
"""
1515
Auditbeat starts and stops without error.

filebeat/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func GoIntegTest(ctx context.Context) error {
196196
// PythonIntegTest executes the python system tests in the integration environment (Docker).
197197
func PythonIntegTest(ctx context.Context) error {
198198
if !devtools.IsInIntegTestEnv() {
199-
mg.Deps(Fields)
199+
mg.Deps(Fields, Dashboards)
200200
}
201201
runner, err := devtools.NewDockerIntegrationRunner(append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "PYTEST_"), "GENERATE")...)
202202
if err != nil {

filebeat/tests/system/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from beat import common_tests
77

88

9-
class Test(BaseTest, common_tests.TestExportsMixin):
9+
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):
1010

1111
def test_base(self):
1212
"""

libbeat/dashboards/modify_json.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,26 +383,27 @@ func EncodeJSONObjects(content []byte) []byte {
383383
}
384384
}
385385

386-
fieldsToStr := []string{"visState", "uiStateJSON", "optionsJSON"}
386+
fieldsToStr := []string{
387+
"layerListJSON",
388+
"mapStateJSON",
389+
"optionsJSON",
390+
"panelsJSON",
391+
"uiStateJSON",
392+
"visState",
393+
}
387394
for _, field := range fieldsToStr {
388-
if rootField, ok := attributes[field].(map[string]interface{}); ok {
395+
switch rootField := attributes[field].(type) {
396+
case map[string]interface{}, []interface{}:
389397
b, err := json.Marshal(rootField)
390398
if err != nil {
391399
return content
392400
}
393401
attributes[field] = string(b)
402+
default:
403+
continue
394404
}
395405
}
396406

397-
if panelsJSON, ok := attributes["panelsJSON"].([]interface{}); ok {
398-
b, err := json.Marshal(panelsJSON)
399-
if err != nil {
400-
return content
401-
}
402-
attributes["panelsJSON"] = string(b)
403-
404-
}
405-
406407
b, err := json.Marshal(objectMap)
407408
if err != nil {
408409
logger.Error("Error marshaling modified dashboard: %+v", err)

libbeat/tests/system/beat/common_tests.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import json
2+
import os
3+
import pytest
4+
import requests
5+
import semver
6+
import shutil
27
import unittest
38
import yaml
49

10+
from elasticsearch import Elasticsearch
511
from beat.beat import INTEGRATION_TESTS
612

713
# Fail if the exported index pattern is larger than 10MiB
@@ -92,3 +98,44 @@ def test_export_config(self):
9298
output = self.run_export_cmd("config")
9399
yml = yaml.load(output, Loader=yaml.FullLoader)
94100
assert isinstance(yml, dict)
101+
102+
103+
class TestDashboardMixin:
104+
105+
@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
106+
@pytest.mark.timeout(5*60, func_only=True)
107+
def test_dashboards(self):
108+
"""
109+
Test that the dashboards can be loaded with `setup --dashboards`
110+
"""
111+
if not self.is_saved_object_api_available():
112+
raise unittest.SkipTest(
113+
"Kibana Saved Objects API is used since 7.15")
114+
115+
shutil.copytree(self.kibana_dir(), os.path.join(self.working_dir, "kibana"))
116+
117+
es = Elasticsearch([self.get_elasticsearch_url()])
118+
self.render_config_template(
119+
elasticsearch={"host": self.get_elasticsearch_url()},
120+
kibana={"host": self.get_kibana_url()},
121+
)
122+
exit_code = self.run_beat(extra_args=["setup", "--dashboards"])
123+
124+
assert exit_code == 0, 'Error output: ' + self.get_log()
125+
assert self.log_contains("Kibana dashboards successfully loaded.")
126+
127+
def is_saved_object_api_available(self):
128+
kibana_semver = semver.VersionInfo.parse(self.get_version())
129+
return semver.VersionInfo.parse("7.14.0") <= kibana_semver
130+
131+
def get_version(self):
132+
url = self.get_kibana_url() + "/api/status"
133+
134+
r = requests.get(url)
135+
body = r.json()
136+
version = body["version"]["number"]
137+
138+
return version
139+
140+
def kibana_dir(self):
141+
return os.path.join(self.beat_path, "build", "kibana")

packetbeat/tests/system/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
from packetbeat import BaseTest
55

66

7-
class Test(BaseTest, common_tests.TestExportsMixin):
7+
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):
88
pass

x-pack/filebeat/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func GoIntegTest(ctx context.Context) error {
164164
// PythonIntegTest executes the python system tests in the integration environment (Docker).
165165
func PythonIntegTest(ctx context.Context) error {
166166
if !devtools.IsInIntegTestEnv() {
167-
mg.Deps(Fields)
167+
mg.Deps(Fields, Dashboards)
168168
}
169169
runner, err := devtools.NewDockerIntegrationRunner(append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "PYTEST_"), "GENERATE")...)
170170
if err != nil {

0 commit comments

Comments
 (0)