mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-30 02:12:38 +00:00
Enable better titles in Grafana dashboards with multiple test tags
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
@@ -280,7 +280,7 @@ class GhostRequest:
|
||||
subtest_pass_fail = list()
|
||||
subtest_pass_total = 0
|
||||
subtest_fail_total = 0
|
||||
test_tag = dict()
|
||||
test_tag_1 = list()
|
||||
columns = ['test-rig', 'dut-hw-version', 'dut-sw-version',
|
||||
'dut-model-num', 'dut-serial-num']
|
||||
duts = dict()
|
||||
@@ -296,10 +296,7 @@ class GhostRequest:
|
||||
duts[column] = column_data
|
||||
except:
|
||||
print('no column named %s' % column)
|
||||
try:
|
||||
test_tag[test_id] = csvreader.get_column(df, 'test-tag')[0]
|
||||
except:
|
||||
print('no test-id')
|
||||
test_tag_1.append([test_id, list(set(csvreader.get_column(df, 'test-tag')))])
|
||||
pass_fail = Counter(csvreader.get_column(df, 'pass/fail'))
|
||||
test_pass_fail.append(pass_fail)
|
||||
subtest_pass = csvreader.get_column(df, 'Subtest-Pass')
|
||||
@@ -387,17 +384,25 @@ class GhostRequest:
|
||||
pass
|
||||
|
||||
low_priority = csvreader.filter_df(results, 'test-priority', 'less than', 94)
|
||||
print('Low Priority results %s' % len(low_priority))
|
||||
if self.debug:
|
||||
print('Low Priority results %s' % len(low_priority))
|
||||
high_priority = csvreader.filter_df(results, 'test-priority', 'greater than or equal to', 95)
|
||||
high_priority_list.append(high_priority)
|
||||
low_priority_list.append(low_priority)
|
||||
|
||||
except:
|
||||
print("Failure")
|
||||
print("Failed to process %s" % target_folder)
|
||||
target_folders.remove(target_folder)
|
||||
failuredict = dict()
|
||||
failuredict[target_folder] = ['Failure']
|
||||
web_pages_and_pdfs.append(failuredict)
|
||||
test_tag = dict()
|
||||
for x in list(set([x[0] for x in test_tag_1])):
|
||||
l3 = list()
|
||||
for sublist in test_tag_1:
|
||||
if sublist[0] == x:
|
||||
l3 += sublist[1]
|
||||
test_tag[x] = l3
|
||||
if len(times) == 0:
|
||||
return ArithmeticError("There are no datapoints in any folders passed into Ghost")
|
||||
|
||||
@@ -447,7 +452,8 @@ class GhostRequest:
|
||||
short_description = 'Tests passed' # variable name
|
||||
numeric_score = test_pass_fail_results['PASS'] # value
|
||||
tags = dict()
|
||||
print(datetime.utcfromtimestamp(max(times)))
|
||||
if self.debug:
|
||||
print(datetime.utcfromtimestamp(max(times)))
|
||||
tags['testbed'] = testbeds[0]
|
||||
tags['script'] = 'GhostRequest'
|
||||
tags['Graph-Group'] = 'PASS'
|
||||
@@ -466,7 +472,8 @@ class GhostRequest:
|
||||
short_description = 'Subtests passed' # variable name
|
||||
numeric_score = subtest_pass_fail_results['PASS'] # value
|
||||
tags = dict()
|
||||
print(datetime.utcfromtimestamp(max(times)))
|
||||
if self.debug:
|
||||
print(datetime.utcfromtimestamp(max(times)))
|
||||
tags['testbed'] = testbeds[0]
|
||||
tags['script'] = 'GhostRequest'
|
||||
tags['Graph-Group'] = 'Subtest PASS'
|
||||
@@ -483,11 +490,14 @@ class GhostRequest:
|
||||
influxdb.post_to_influx(short_description, numeric_score, tags, date)
|
||||
|
||||
text = 'Testbed: %s<br />' % testbeds[0]
|
||||
raw_test_tags = list()
|
||||
test_tag_table = ''
|
||||
for tag in list(set(test_tag.values())):
|
||||
print(tag)
|
||||
for value in tag:
|
||||
raw_test_tags.append(value)
|
||||
for value in list(set(raw_test_tags)):
|
||||
test_tag_table += (
|
||||
'<tr><td style="border-color: gray; border-style: solid; border-width: 1px; ">Test Tag</td><td colspan="3" style="border-color: gray; border-style: solid; border-width: 1px; ">%s</td></tr>' % tag)
|
||||
'<tr><td style="border-color: gray; border-style: solid; border-width: 1px; ">Test Tag</td><td colspan="3" style="border-color: gray; border-style: solid; border-width: 1px; ">%s</td></tr>' % value)
|
||||
dut_table_column_names = {'test-rig': 'Testbed',
|
||||
'dut-hw-version': 'DUT HW',
|
||||
'dut-sw-version': 'DUT SW',
|
||||
@@ -540,9 +550,11 @@ class GhostRequest:
|
||||
if grafana_token is not None:
|
||||
grafana = GrafanaRequest(grafana_token,
|
||||
grafana_host,
|
||||
grafanajson_port=grafana_port
|
||||
grafanajson_port=grafana_port,
|
||||
debug_=self.debug
|
||||
)
|
||||
print(test_tag)
|
||||
if self.debug:
|
||||
print('Test Tag: %s' % test_tag)
|
||||
grafana.create_custom_dashboard(target_csvs=target_files,
|
||||
title=title,
|
||||
datasource=grafana_datasource,
|
||||
|
||||
@@ -209,7 +209,7 @@ class GrafanaRequest:
|
||||
from_date='now-1y',
|
||||
to_date='now',
|
||||
graph_height=8,
|
||||
graph__width=12,
|
||||
graph_width=12,
|
||||
pass_fail=None,
|
||||
test_tag=None):
|
||||
options = string.ascii_lowercase + string.ascii_uppercase + string.digits
|
||||
@@ -248,126 +248,37 @@ class GrafanaRequest:
|
||||
if pass_fail is not None:
|
||||
graph_groups[pass_fail] = ['PASS', 'FAIL']
|
||||
|
||||
print('Test Tag in Grafana: %s' % test_tag)
|
||||
|
||||
for scriptname in graph_groups.keys():
|
||||
print(scriptname)
|
||||
for graph_group in graph_groups[scriptname]:
|
||||
panel = dict()
|
||||
|
||||
gridpos = dict()
|
||||
gridpos['h'] = graph_height
|
||||
gridpos['w'] = graph__width
|
||||
gridpos['x'] = 0
|
||||
gridpos['y'] = 0
|
||||
|
||||
legend = dict()
|
||||
legend['avg'] = False
|
||||
legend['current'] = False
|
||||
legend['max'] = False
|
||||
legend['min'] = False
|
||||
legend['show'] = True
|
||||
legend['total'] = False
|
||||
legend['values'] = False
|
||||
|
||||
options = dict()
|
||||
options['alertThreshold'] = True
|
||||
|
||||
groupBy = list()
|
||||
groupBy.append(self.groupby('$__interval', 'time'))
|
||||
groupBy.append(self.groupby('null', 'fill'))
|
||||
|
||||
targets = list()
|
||||
counter = 0
|
||||
try:
|
||||
new_target = self.maketargets(bucket,
|
||||
scriptname,
|
||||
groupBy,
|
||||
counter,
|
||||
graph_group,
|
||||
testbed,
|
||||
test_tag=test_tag[scriptname])
|
||||
except:
|
||||
new_target = self.maketargets(bucket, scriptname, groupBy, counter, graph_group, testbed)
|
||||
targets.append(new_target)
|
||||
|
||||
fieldConfig = dict()
|
||||
fieldConfig['defaults'] = dict()
|
||||
fieldConfig['overrides'] = list()
|
||||
|
||||
transformation = dict()
|
||||
transformation['id'] = "renameByRegex"
|
||||
transformation_options = dict()
|
||||
transformation_options['regex'] = "(.*) value.*"
|
||||
transformation_options['renamePattern'] = "$1"
|
||||
transformation['options'] = transformation_options
|
||||
|
||||
xaxis = dict()
|
||||
xaxis['buckets'] = None
|
||||
xaxis['mode'] = "time"
|
||||
xaxis['name'] = None
|
||||
xaxis['show'] = True
|
||||
xaxis['values'] = list()
|
||||
|
||||
yaxis = dict()
|
||||
yaxis['format'] = 'short'
|
||||
try:
|
||||
yaxis['label'] = self.units[scriptname][graph_group]
|
||||
except:
|
||||
pass
|
||||
yaxis['logBase'] = 1
|
||||
yaxis['max'] = None
|
||||
yaxis['min'] = None
|
||||
yaxis['show'] = True
|
||||
|
||||
yaxis1 = dict()
|
||||
yaxis1['align'] = False
|
||||
yaxis1['alignLevel'] = None
|
||||
|
||||
panel['aliasColors'] = dict()
|
||||
panel['bars'] = False
|
||||
panel['dashes'] = False
|
||||
panel['dashLength'] = 10
|
||||
panel['datasource'] = datasource
|
||||
panel['fieldConfig'] = fieldConfig
|
||||
panel['fill'] = 0
|
||||
panel['fillGradient'] = 0
|
||||
panel['gridPos'] = gridpos
|
||||
panel['hiddenSeries'] = False
|
||||
panel['id'] = index
|
||||
panel['legend'] = legend
|
||||
panel['lines'] = True
|
||||
panel['linewidth'] = 1
|
||||
panel['nullPointMode'] = 'null'
|
||||
panel['options'] = options
|
||||
panel['percentage'] = False
|
||||
panel['pluginVersion'] = '7.5.4'
|
||||
panel['pointradius'] = 2
|
||||
panel['points'] = True
|
||||
panel['renderer'] = 'flot'
|
||||
panel['seriesOverrides'] = list()
|
||||
panel['spaceLength'] = 10
|
||||
panel['stack'] = False
|
||||
panel['steppedLine'] = False
|
||||
panel['targets'] = targets
|
||||
panel['thresholds'] = list()
|
||||
panel['timeFrom'] = None
|
||||
panel['timeRegions'] = list()
|
||||
panel['timeShift'] = None
|
||||
if graph_group is not None:
|
||||
panel['title'] = scriptname + ' ' + graph_group
|
||||
else:
|
||||
panel['title'] = scriptname
|
||||
print(panel['title'])
|
||||
panel['transformations'] = list()
|
||||
panel['transformations'].append(transformation)
|
||||
panel['type'] = "graph"
|
||||
panel['xaxis'] = xaxis
|
||||
panel['yaxes'] = list()
|
||||
panel['yaxes'].append(yaxis)
|
||||
panel['yaxes'].append(yaxis)
|
||||
panel['yaxis'] = yaxis1
|
||||
|
||||
if scriptname in test_tag.keys():
|
||||
for tag in test_tag[scriptname]:
|
||||
print('Script: %s, Tag: %s' % (scriptname, tag))
|
||||
panel = self.create_panel(graph_groups,
|
||||
graph_height,
|
||||
graph_width,
|
||||
scriptname,
|
||||
bucket,
|
||||
testbed,
|
||||
tag,
|
||||
datasource,
|
||||
index)
|
||||
panels.append(panel)
|
||||
index = index + 1
|
||||
else:
|
||||
panel = self.create_panel(graph_groups,
|
||||
graph_height,
|
||||
graph_width,
|
||||
scriptname,
|
||||
bucket,
|
||||
testbed,
|
||||
None,
|
||||
datasource,
|
||||
index)
|
||||
panels.append(panel)
|
||||
index = index + 1
|
||||
|
||||
input1['annotations'] = annot
|
||||
input1['editable'] = True
|
||||
input1['gnetId'] = None
|
||||
@@ -387,10 +298,138 @@ class GrafanaRequest:
|
||||
input1['version'] = 11
|
||||
return self.create_dashboard_from_dict(dictionary=json.dumps(input1))
|
||||
|
||||
# def create_custom_dashboard(self,
|
||||
# datastore=None):
|
||||
# data = json.dumps(datastore, indent=4)
|
||||
# return requests.post(self.grafanajson_url, headers=self.headers, data=data, verify=False)
|
||||
def create_panel(self,
|
||||
graph_groups,
|
||||
graph_height,
|
||||
graph_width,
|
||||
scriptname,
|
||||
bucket,
|
||||
testbed,
|
||||
test_tag,
|
||||
datasource,
|
||||
index):
|
||||
print('Test Tag: %s' % test_tag)
|
||||
for graph_group in graph_groups[scriptname]:
|
||||
panel = dict()
|
||||
|
||||
gridpos = dict()
|
||||
gridpos['h'] = graph_height
|
||||
gridpos['w'] = graph_width
|
||||
gridpos['x'] = 0
|
||||
gridpos['y'] = 0
|
||||
|
||||
legend = dict()
|
||||
legend['avg'] = False
|
||||
legend['current'] = False
|
||||
legend['max'] = False
|
||||
legend['min'] = False
|
||||
legend['show'] = True
|
||||
legend['total'] = False
|
||||
legend['values'] = False
|
||||
|
||||
options = dict()
|
||||
options['alertThreshold'] = True
|
||||
|
||||
groupBy = list()
|
||||
groupBy.append(self.groupby('$__interval', 'time'))
|
||||
groupBy.append(self.groupby('null', 'fill'))
|
||||
|
||||
targets = list()
|
||||
counter = 0
|
||||
try:
|
||||
new_target = self.maketargets(bucket,
|
||||
scriptname,
|
||||
groupBy,
|
||||
counter,
|
||||
graph_group,
|
||||
testbed,
|
||||
test_tag=test_tag)
|
||||
except:
|
||||
new_target = self.maketargets(bucket, scriptname, groupBy, counter, graph_group, testbed)
|
||||
targets.append(new_target)
|
||||
|
||||
fieldConfig = dict()
|
||||
fieldConfig['defaults'] = dict()
|
||||
fieldConfig['overrides'] = list()
|
||||
|
||||
transformation = dict()
|
||||
transformation['id'] = "renameByRegex"
|
||||
transformation_options = dict()
|
||||
transformation_options['regex'] = "(.*) value.*"
|
||||
transformation_options['renamePattern'] = "$1"
|
||||
transformation['options'] = transformation_options
|
||||
|
||||
xaxis = dict()
|
||||
xaxis['buckets'] = None
|
||||
xaxis['mode'] = "time"
|
||||
xaxis['name'] = None
|
||||
xaxis['show'] = True
|
||||
xaxis['values'] = list()
|
||||
|
||||
yaxis = dict()
|
||||
yaxis['format'] = 'short'
|
||||
try:
|
||||
yaxis['label'] = self.units[scriptname][graph_group]
|
||||
except:
|
||||
pass
|
||||
yaxis['logBase'] = 1
|
||||
yaxis['max'] = None
|
||||
yaxis['min'] = None
|
||||
yaxis['show'] = True
|
||||
|
||||
yaxis1 = dict()
|
||||
yaxis1['align'] = False
|
||||
yaxis1['alignLevel'] = None
|
||||
|
||||
panel['aliasColors'] = dict()
|
||||
panel['bars'] = False
|
||||
panel['dashes'] = False
|
||||
panel['dashLength'] = 10
|
||||
panel['datasource'] = datasource
|
||||
panel['fieldConfig'] = fieldConfig
|
||||
panel['fill'] = 0
|
||||
panel['fillGradient'] = 0
|
||||
panel['gridPos'] = gridpos
|
||||
panel['hiddenSeries'] = False
|
||||
panel['id'] = index
|
||||
panel['legend'] = legend
|
||||
panel['lines'] = True
|
||||
panel['linewidth'] = 1
|
||||
panel['nullPointMode'] = 'null'
|
||||
panel['options'] = options
|
||||
panel['percentage'] = False
|
||||
panel['pluginVersion'] = '7.5.4'
|
||||
panel['pointradius'] = 2
|
||||
panel['points'] = True
|
||||
panel['renderer'] = 'flot'
|
||||
panel['seriesOverrides'] = list()
|
||||
panel['spaceLength'] = 10
|
||||
panel['stack'] = False
|
||||
panel['steppedLine'] = False
|
||||
panel['targets'] = targets
|
||||
panel['thresholds'] = list()
|
||||
panel['timeFrom'] = None
|
||||
panel['timeRegions'] = list()
|
||||
panel['timeShift'] = None
|
||||
|
||||
if graph_group is not None:
|
||||
scriptname = '%s: %s' % (scriptname, graph_group)
|
||||
if test_tag is not None:
|
||||
scriptname = '%s: %s' % (scriptname, test_tag)
|
||||
scriptname = '%s: %s' % (scriptname, testbed)
|
||||
panel['title'] = scriptname
|
||||
|
||||
if self.debug:
|
||||
print(panel['title'])
|
||||
panel['transformations'] = list()
|
||||
panel['transformations'].append(transformation)
|
||||
panel['type'] = "graph"
|
||||
panel['xaxis'] = xaxis
|
||||
panel['yaxes'] = list()
|
||||
panel['yaxes'].append(yaxis)
|
||||
panel['yaxes'].append(yaxis)
|
||||
panel['yaxis'] = yaxis1
|
||||
return panel
|
||||
|
||||
def create_snapshot(self, title):
|
||||
print('create snapshot')
|
||||
@@ -427,4 +466,4 @@ class GrafanaRequest:
|
||||
d = dict()
|
||||
d[maxunit] = maxtest
|
||||
print(maxunit, maxtest)
|
||||
return d
|
||||
return d
|
||||
Reference in New Issue
Block a user