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

Fix formatting of mapStateJSON and layerListJSON in dashboard assets #28530

Merged
merged 9 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
42 changes: 42 additions & 0 deletions filebeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os
import unittest
import pytest
import semver
import requests
import shutil
from filebeat import BaseTest
from elasticsearch import Elasticsearch
from beat.beat import INTEGRATION_TESTS
Expand Down Expand Up @@ -57,3 +61,41 @@ def test_template_migration(self):
assert exit_code == 0
assert self.log_contains('Loaded index template')
assert len(es.cat.templates(name='filebeat-*', h='name')) > 0

@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")
23 changes: 12 additions & 11 deletions libbeat/dashboards/modify_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,26 +386,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
4 changes: 2 additions & 2 deletions metricbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def test_template(self):
assert len(es.cat.templates(name='metricbeat-*', h='name')) > 0

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
@pytest.mark.timeout(180, func_only=True)
@pytest.mark.timeout(5*60, func_only=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

math doesn't add up :-)

def test_dashboards(self):
"""
Test that the dashboards can be loaded with `setup --dashboards`
"""
if self.is_saved_object_api_available():
if not self.is_saved_object_api_available():
raise unittest.SkipTest(
"Kibana Saved Objects API is used since 7.15")

Expand Down
39 changes: 38 additions & 1 deletion packetbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,41 @@


class Test(BaseTest, common_tests.TestExportsMixin):
pass

@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")
kvch marked this conversation as resolved.
Show resolved Hide resolved