summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-09-26 14:44:30 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-09-26 15:41:59 +0800
commit418df95285daeedcf0ee71f44e1ae63838b08ecb (patch)
tree16123de2303a23daa366b94197f9ff15972e0290 /utils/test
parent69e62ae2da472e35e558e3d43041555f29004cdf (diff)
template-ize kibana visualization
JIRA: FUNCTEST-492 Change-Id: I7235ff371ee16ae7f2e759d73735e1aa9b248c1c Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/dashboard/dashboard/elastic2kibana/main.py97
-rw-r--r--utils/test/dashboard/dashboard/elastic2kibana/templates/duration.json45
-rw-r--r--utils/test/dashboard/dashboard/elastic2kibana/templates/success_percentage.json45
-rw-r--r--utils/test/dashboard/dashboard/elastic2kibana/templates/tests_failures.json45
4 files changed, 166 insertions, 66 deletions
diff --git a/utils/test/dashboard/dashboard/elastic2kibana/main.py b/utils/test/dashboard/dashboard/elastic2kibana/main.py
index c1cbc308e..37ce03e52 100644
--- a/utils/test/dashboard/dashboard/elastic2kibana/main.py
+++ b/utils/test/dashboard/dashboard/elastic2kibana/main.py
@@ -3,6 +3,7 @@ import json
import urlparse
import argparse
+from jinja2 import PackageLoader, Environment
from common import logger_utils, elastic_access
from conf import testcases
@@ -51,12 +52,13 @@ class KibanaDashboard(dict):
scenario,
self.visualization))
- self._visualization_title = self._kibana_visualizations[0].vis_state_title
+ self._visualization_title = self._kibana_visualizations[0].vis_title
def _publish_visualizations(self):
for visualization in self._kibana_visualizations:
url = urlparse.urljoin(base_elastic_url, '/.kibana/visualization/{}'.format(visualization.id))
logger.debug("publishing visualization '{}'".format(url))
+ # logger.error("_publish_visualization: %s" % visualization)
elastic_access.publish_json(visualization, es_creds, url)
def _construct_panels(self):
@@ -163,67 +165,30 @@ class KibanaSearchSourceJSON(dict):
self["filter"].append({"match": {"pod_name": {"query": pod, "type": "phrase"}}})
-class VisualizationState(dict):
+class VisualizationBuilder(object):
def __init__(self, visualization):
- super(VisualizationState, self).__init__()
- name = visualization.get('name')
- fields = visualization.get('fields')
-
- if name == 'tests_failures':
- mode = 'grouped'
- metric_type = 'sum'
- self['type'] = 'histogram'
- else:
- # duration or success_percentage
- mode = 'stacked'
- metric_type = 'avg'
- self['type'] = 'line'
-
- self['params'] = {
- "shareYAxis": True,
- "addTooltip": True,
- "addLegend": True,
- "smoothLines": False,
- "scale": "linear",
- "interpolate": "linear",
- "mode": mode,
- "times": [],
- "addTimeMarker": False,
- "defaultYExtents": False,
- "setYExtents": False,
- "yAxis": {}
- }
+ super(VisualizationBuilder, self).__init__()
+ self.visualization = visualization
- self['aggs'] = []
+ def build(self):
+ name = self.visualization.get('name')
+ fields = self.visualization.get('fields')
- i = 1
+ aggs = []
+ index = 1
for field in fields:
- self['aggs'].append({
- "id": str(i),
- "type": metric_type,
- "schema": "metric",
- "params": {
- "field": field.get('field')
- }
- })
- i += 1
-
- self['aggs'].append({
- "id": str(i),
- "type": 'date_histogram',
- "schema": "segment",
- "params": {
- "field": "start_date",
- "interval": "auto",
- "customInterval": "2h",
- "min_doc_count": 1,
- "extended_bounds": {}
- }
+ aggs.append({
+ "id": index,
+ "field": field.get("field")
})
+ index += 1
+
+ env = Environment(loader=PackageLoader('elastic2kibana', 'templates'))
+ env.filters['jsonify'] = json.dumps
+ template = env.get_template('{}.json'.format(name))
+ vis = template.render(aggs=aggs)
+ return json.loads(vis)
- self['listeners'] = {}
- self['title'] = ' '.join(['{} {}'.format(x['type'], x['params']['field']) for x in self['aggs']
- if x['schema'] == 'metric'])
class KibanaVisualization(dict):
@@ -243,24 +208,24 @@ class KibanaVisualization(dict):
:return:
"""
super(KibanaVisualization, self).__init__()
- vis_state = VisualizationState(visualization)
- self.vis_state_title = vis_state['title']
+ vis = VisualizationBuilder(visualization).build()
+ self.vis_title = vis['title']
self['title'] = '{} {} {} {} {} {}'.format(project_name,
case_name,
- self.vis_state_title,
+ self.vis_title,
installer,
pod,
scenario)
self.id = self['title'].replace(' ', '-').replace('/', '-')
- self['visState'] = json.dumps(vis_state, separators=(',', ':'))
+ self['visState'] = json.dumps(vis, separators=(',', ':'))
self['uiStateJSON'] = "{}"
- self['description'] = "Kibana visualization for project_name '{}', case_name '{}', data '{}', installer '{}'," \
+ self['description'] = "Kibana visualization for project_name '{}', case_name '{}', metric '{}', installer '{}'," \
" pod '{}' and scenario '{}'".format(project_name,
- case_name,
- self.vis_state_title,
- installer,
- pod,
- scenario)
+ case_name,
+ self.vis_title,
+ installer,
+ pod,
+ scenario)
self['scenario'] = 1
self['kibanaSavedObjectMeta'] = {"searchSourceJSON": json.dumps(KibanaSearchSourceJSON(project_name,
case_name,
diff --git a/utils/test/dashboard/dashboard/elastic2kibana/templates/duration.json b/utils/test/dashboard/dashboard/elastic2kibana/templates/duration.json
new file mode 100644
index 000000000..f50a668db
--- /dev/null
+++ b/utils/test/dashboard/dashboard/elastic2kibana/templates/duration.json
@@ -0,0 +1,45 @@
+{% set aggs = aggs|default([]) -%}
+
+{
+ "title": "duration",
+ "type": "line",
+ "listeners": {},
+ "params": {
+ "addLegend": true,
+ "shareYAxis": true,
+ "addTooltip": true,
+ "smoothLines": false,
+ "scale": "linear",
+ "interpolate": "linear",
+ "times": [],
+ "addTimeMarker": false,
+ "defaultYExtents": false,
+ "setYExtents": false,
+ "yAxis": {},
+ "mode": "stacked"
+ },
+ "aggs": [
+ {% for agg in aggs %}
+ {
+ "id": {{agg.id }},
+ "type": "avg",
+ "schema": "metric",
+ "params": {
+ "field": "{{agg.field}}"
+ }
+ },
+ {% endfor %}
+ {
+ "id": {{ aggs|length + 1 }},
+ "type": "date_histogram",
+ "schema": "segment",
+ "params": {
+ "field": "start_date",
+ "interval": "auto",
+ "customInterval": "2h",
+ "min_doc_count": 1,
+ "extended_bounds": {}
+ }
+ }
+ ]
+}
diff --git a/utils/test/dashboard/dashboard/elastic2kibana/templates/success_percentage.json b/utils/test/dashboard/dashboard/elastic2kibana/templates/success_percentage.json
new file mode 100644
index 000000000..993070844
--- /dev/null
+++ b/utils/test/dashboard/dashboard/elastic2kibana/templates/success_percentage.json
@@ -0,0 +1,45 @@
+{% set aggs = aggs|default([]) -%}
+
+{
+ "title": "success_percentage",
+ "type": "line",
+ "listeners": {},
+ "params": {
+ "addLegend": true,
+ "shareYAxis": true,
+ "addTooltip": true,
+ "smoothLines": false,
+ "scale": "linear",
+ "interpolate": "linear",
+ "times": [],
+ "addTimeMarker": false,
+ "defaultYExtents": false,
+ "setYExtents": false,
+ "yAxis": {},
+ "mode": "stacked"
+ },
+ "aggs": [
+ {% for agg in aggs %}
+ {
+ "id": {{agg.id }},
+ "type": "avg",
+ "schema": "metric",
+ "params": {
+ "field": "{{agg.field}}"
+ }
+ },
+ {% endfor %}
+ {
+ "id": {{ aggs|length + 1 }},
+ "type": "date_histogram",
+ "schema": "segment",
+ "params": {
+ "field": "start_date",
+ "interval": "auto",
+ "customInterval": "2h",
+ "min_doc_count": 1,
+ "extended_bounds": {}
+ }
+ }
+ ]
+}
diff --git a/utils/test/dashboard/dashboard/elastic2kibana/templates/tests_failures.json b/utils/test/dashboard/dashboard/elastic2kibana/templates/tests_failures.json
new file mode 100644
index 000000000..01f9ba89e
--- /dev/null
+++ b/utils/test/dashboard/dashboard/elastic2kibana/templates/tests_failures.json
@@ -0,0 +1,45 @@
+{% set aggs = aggs|default([]) -%}
+
+{
+ "title": "tests_failures",
+ "type": "histogram",
+ "listeners": {},
+ "params": {
+ "addLegend": true,
+ "shareYAxis": true,
+ "addTooltip": true,
+ "smoothLines": false,
+ "scale": "linear",
+ "interpolate": "linear",
+ "times": [],
+ "addTimeMarker": false,
+ "defaultYExtents": false,
+ "setYExtents": false,
+ "yAxis": {},
+ "mode": "grouped"
+ },
+ "aggs": [
+ {% for agg in aggs %}
+ {
+ "id": {{agg.id }},
+ "type": "sum",
+ "schema": "metric",
+ "params": {
+ "field": "{{agg.field}}"
+ }
+ },
+ {% endfor %}
+ {
+ "id": {{ aggs|length + 1 }},
+ "type": "date_histogram",
+ "schema": "segment",
+ "params": {
+ "field": "start_date",
+ "interval": "auto",
+ "customInterval": "2h",
+ "min_doc_count": 1,
+ "extended_bounds": {}
+ }
+ }
+ ]
+}