summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-09-27 07:02:50 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-09-27 07:02:50 +0000
commit859efd8c2880674b9c9f280bd3fc39899d514446 (patch)
tree4504b19ba32dcf0bfa2d312d30b17fa75c7f1d81 /utils
parent50f5122ab09ab0cbca792e853232adc6b5dae168 (diff)
parent418df95285daeedcf0ee71f44e1ae63838b08ecb (diff)
Merge "template-ize kibana visualization"
Diffstat (limited to 'utils')
-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": {}
+ }
+ }
+ ]
+}