Skip to content

Commit

Permalink
Fix formatting of mapStateJSON and layerListJSON in dashboard ass…
Browse files Browse the repository at this point in the history
…ets (#28530)

(cherry picked from commit 85d3591)
  • Loading branch information
kvch committed Oct 21, 2021
1 parent f0c5b73 commit c05f1ed
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion auditbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from beat import common_tests


class Test(BaseTest, common_tests.TestExportsMixin):
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):
def test_start_stop(self):
"""
Auditbeat starts and stops without error.
Expand Down
2 changes: 1 addition & 1 deletion filebeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func GoIntegTest(ctx context.Context) error {
// PythonIntegTest executes the python system tests in the integration environment (Docker).
func PythonIntegTest(ctx context.Context) error {
if !devtools.IsInIntegTestEnv() {
mg.Deps(Fields)
mg.Deps(Fields, Dashboards)
}
runner, err := devtools.NewDockerIntegrationRunner(append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "PYTEST_"), "GENERATE")...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion filebeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from beat import common_tests


class Test(BaseTest, common_tests.TestExportsMixin):
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):

def test_base(self):
"""
Expand Down
23 changes: 12 additions & 11 deletions libbeat/dashboards/modify_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,26 +383,27 @@ func EncodeJSONObjects(content []byte) []byte {
}
}

fieldsToStr := []string{"visState", "uiStateJSON", "optionsJSON"}
fieldsToStr := []string{
"layerListJSON",
"mapStateJSON",
"optionsJSON",
"panelsJSON",
"uiStateJSON",
"visState",
}
for _, field := range fieldsToStr {
if rootField, ok := attributes[field].(map[string]interface{}); ok {
switch rootField := attributes[field].(type) {
case map[string]interface{}, []interface{}:
b, err := json.Marshal(rootField)
if err != nil {
return content
}
attributes[field] = string(b)
default:
continue
}
}

if panelsJSON, ok := attributes["panelsJSON"].([]interface{}); ok {
b, err := json.Marshal(panelsJSON)
if err != nil {
return content
}
attributes["panelsJSON"] = string(b)

}

b, err := json.Marshal(objectMap)
if err != nil {
logger.Error("Error marshaling modified dashboard: %+v", err)
Expand Down
47 changes: 47 additions & 0 deletions libbeat/tests/system/beat/common_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import json
import os
import pytest
import requests
import semver
import shutil
import unittest
import yaml

from elasticsearch import Elasticsearch
from beat.beat import INTEGRATION_TESTS

# Fail if the exported index pattern is larger than 10MiB
Expand Down Expand Up @@ -92,3 +98,44 @@ def test_export_config(self):
output = self.run_export_cmd("config")
yml = yaml.load(output, Loader=yaml.FullLoader)
assert isinstance(yml, dict)


class TestDashboardMixin:

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
@pytest.mark.timeout(5*60, func_only=True)
def test_dashboards(self):
"""
Test that the dashboards can be loaded with `setup --dashboards`
"""
if not self.is_saved_object_api_available():
raise unittest.SkipTest(
"Kibana Saved Objects API is used since 7.15")

shutil.copytree(self.kibana_dir(), os.path.join(self.working_dir, "kibana"))

es = Elasticsearch([self.get_elasticsearch_url()])
self.render_config_template(
elasticsearch={"host": self.get_elasticsearch_url()},
kibana={"host": self.get_kibana_url()},
)
exit_code = self.run_beat(extra_args=["setup", "--dashboards"])

assert exit_code == 0, 'Error output: ' + self.get_log()
assert self.log_contains("Kibana dashboards successfully loaded.")

def is_saved_object_api_available(self):
kibana_semver = semver.VersionInfo.parse(self.get_version())
return semver.VersionInfo.parse("7.14.0") <= kibana_semver

def get_version(self):
url = self.get_kibana_url() + "/api/status"

r = requests.get(url)
body = r.json()
version = body["version"]["number"]

return version

def kibana_dir(self):
return os.path.join(self.beat_path, "build", "kibana")
2 changes: 1 addition & 1 deletion packetbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from packetbeat import BaseTest


class Test(BaseTest, common_tests.TestExportsMixin):
class Test(BaseTest, common_tests.TestExportsMixin, common_tests.TestDashboardMixin):
pass
2 changes: 1 addition & 1 deletion x-pack/filebeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func GoIntegTest(ctx context.Context) error {
// PythonIntegTest executes the python system tests in the integration environment (Docker).
func PythonIntegTest(ctx context.Context) error {
if !devtools.IsInIntegTestEnv() {
mg.Deps(Fields)
mg.Deps(Fields, Dashboards)
}
runner, err := devtools.NewDockerIntegrationRunner(append(devtools.ListMatchingEnvVars("TESTING_FILEBEAT_", "PYTEST_"), "GENERATE")...)
if err != nil {
Expand Down

0 comments on commit c05f1ed

Please sign in to comment.