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 7 commits
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
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 @@ -200,7 +200,7 @@ func GoIntegTest(ctx context.Context) error {
// Use TESTING_FILEBEAT_FILESETS=fileset[,fileset] to limit what fileset to test.
func PythonIntegTest(ctx context.Context) error {
if !devtools.IsInIntegTestEnv() {
mg.Deps(Fields)
mg.Deps(Fields, devtools.KibanaDashboards)
}
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 @@ -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
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 @@ -87,3 +93,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")
29 changes: 1 addition & 28 deletions metricbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from elasticsearch import Elasticsearch


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

COMPOSE_SERVICES = ['elasticsearch', 'kibana']

Expand Down Expand Up @@ -58,33 +58,6 @@ def test_template(self):
assert self.log_contains('Loaded index template')
assert len(es.cat.templates(name='metricbeat-*', h='name')) > 0

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
@pytest.mark.timeout(180, func_only=True)
def test_dashboards(self):
"""
Test that the dashboards can be loaded with `setup --dashboards`
"""
if 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(
modules=[{
"name": "apache",
"metricsets": ["status"],
"hosts": ["localhost"],
}],
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.")

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_migration(self):
"""
Expand Down
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
6 changes: 3 additions & 3 deletions testing/environments/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: '2.3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
Copy link

Choose a reason for hiding this comment

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

why wouldn't this be 8.0.0 for the tests on master branch?

Copy link

Choose a reason for hiding this comment

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

are these only released builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

latest.yml contains the latests releases. We use the environment in snapshot.yml for the latest snapshots of 8.0.0 on master.

healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cat/health?h=status | grep -q green"]
retries: 300
Expand All @@ -20,7 +20,7 @@ services:
- "script.context.template.cache_max_size=2000"

logstash:
image: docker.elastic.co/logstash/logstash:7.14.0
image: docker.elastic.co/logstash/logstash:7.15.0
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9600/_node/stats"]
retries: 300
Expand All @@ -30,7 +30,7 @@ services:
- ./docker/logstash/pki:/etc/pki:ro

kibana:
image: docker.elastic.co/kibana/kibana:7.14.0
image: docker.elastic.co/kibana/kibana:7.15.0
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5601"]
retries: 300
Expand Down