Repair tests (#185)

* Update deprecated convert to converter

* Solve deprecated use of yAxis tuple

* Change deprecated imp to importlib

* Change Deprecated assoc to evolve

* Change Deprecated cmp to eq and sort
This commit is contained in:
Oriol Tauleria 2019-11-17 17:28:12 +01:00 committed by Bryan Boreham
parent b69b869073
commit 7336fcec55
10 changed files with 104 additions and 101 deletions

View File

@ -57,10 +57,10 @@ percentile latency:
refId='E', refId='E',
), ),
], ],
yAxes=[ yAxes=G.YAxes(
YAxis(format=OPS_FORMAT), YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT), YAxis(format=SHORT_FORMAT),
], ),
alert=Alert( alert=Alert(
name="Too many 500s on Nginx", name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes", message="More than 5 QPS of 500s on Nginx for 5 minutes",

View File

@ -38,7 +38,8 @@ g = Graph(
dataSource="elasticsearch", dataSource="elasticsearch",
targets=tgts, targets=tgts,
lines=False, lines=False,
legend=Legend(alignAsTable=True, rightSide=True, total=True, current=True, max=True), legend=Legend(alignAsTable=True, rightSide=True,
total=True, current=True, max=True),
lineWidth=1, lineWidth=1,
nullPointMode=NULL_AS_NULL, nullPointMode=NULL_AS_NULL,
seriesOverrides=[ seriesOverrides=[
@ -68,7 +69,7 @@ g = Graph(
"color": "#447EBC" "color": "#447EBC"
}, },
], ],
yAxes=[ yAxes=G.YAxes(
YAxis( YAxis(
label="Count", label="Count",
format=SHORT_FORMAT, format=SHORT_FORMAT,
@ -79,7 +80,7 @@ g = Graph(
format=SECONDS_FORMAT, format=SECONDS_FORMAT,
decimals=2 decimals=2
), ),
], ),
transparent=True, transparent=True,
span=12, span=12,
) )

View File

@ -35,10 +35,10 @@ dashboard = Dashboard(
refId='E', refId='E',
), ),
], ],
yAxes=[ yAxes=G.YAxes(
YAxis(format=OPS_FORMAT), YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT), YAxis(format=SHORT_FORMAT),
], ),
alert=Alert( alert=Alert(
name="Too many 500s on Nginx", name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes", message="More than 5 QPS of 500s on Nginx for 5 minutes",

View File

@ -1,7 +1,7 @@
"""Generate JSON Grafana dashboards.""" """Generate JSON Grafana dashboards."""
import argparse import argparse
import imp import importlib
import json import json
import os import os
import sys import sys
@ -21,7 +21,7 @@ def load_dashboard(path):
``dashboard``. ``dashboard``.
:return: A ``Dashboard`` :return: A ``Dashboard``
""" """
module = imp.load_source("dashboard", path) module = importlib.load_source("dashboard", path)
marker = object() marker = object()
dashboard = getattr(module, 'dashboard', marker) dashboard = getattr(module, 'dashboard', marker)
if dashboard is marker: if dashboard is marker:

View File

@ -455,7 +455,7 @@ def _balance_panels(panels):
auto_span = math.ceil( auto_span = math.ceil(
(TOTAL_SPAN - allotted_spans) / (len(no_span_set) or 1)) (TOTAL_SPAN - allotted_spans) / (len(no_span_set) or 1))
return [ return [
attr.assoc(panel, span=auto_span) if panel.span is None else panel attr.evolve(panel, span=auto_span) if panel.span is None else panel
for panel in panels for panel in panels
] ]
@ -483,7 +483,7 @@ class Row(object):
return iter(self.panels) return iter(self.panels)
def _map_panels(self, f): def _map_panels(self, f):
return attr.assoc(self, panels=list(map(f, self.panels))) return attr.evolve(self, panels=list(map(f, self.panels)))
def to_json_data(self): def to_json_data(self):
showTitle = False showTitle = False
@ -915,7 +915,7 @@ class Dashboard(object):
yield panel yield panel
def _map_panels(self, f): def _map_panels(self, f):
return attr.assoc(self, rows=[r._map_panels(f) for r in self.rows]) return attr.evolve(self, rows=[r._map_panels(f) for r in self.rows])
def auto_panel_ids(self): def auto_panel_ids(self):
"""Give unique IDs all the panels without IDs. """Give unique IDs all the panels without IDs.
@ -929,7 +929,7 @@ class Dashboard(object):
auto_ids = (i for i in itertools.count(1) if i not in ids) auto_ids = (i for i in itertools.count(1) if i not in ids)
def set_id(panel): def set_id(panel):
return panel if panel.id else attr.assoc(panel, id=next(auto_ids)) return panel if panel.id else attr.evolve(panel, id=next(auto_ids))
return self._map_panels(set_id) return self._map_panels(set_id)
def to_json_data(self): def to_json_data(self):

View File

@ -25,10 +25,10 @@ def test_serialization():
), ),
], ],
id=1, id=1,
yAxes=[ yAxes=G.YAxes(
G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"), G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
G.YAxis(format=G.SHORT_FORMAT), G.YAxis(format=G.SHORT_FORMAT),
], ),
) )
stream = StringIO() stream = StringIO()
_gen.write_dashboard(graph, stream) _gen.write_dashboard(graph, stream)
@ -51,10 +51,10 @@ def test_auto_id():
refId='A', refId='A',
), ),
], ],
yAxes=[ yAxes=G.YAxes(
G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds"), G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds"),
G.YAxis(format=G.SHORT_FORMAT), G.YAxis(format=G.SHORT_FORMAT),
], ),
) )
]), ]),
], ],

View File

@ -29,10 +29,10 @@ def test_serialization_opentsdb_target():
]), ]),
], ],
id=1, id=1,
yAxes=[ yAxes=G.YAxes(
G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"), G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
G.YAxis(format=G.SHORT_FORMAT), G.YAxis(format=G.SHORT_FORMAT),
], ),
) )
stream = StringIO() stream = StringIO()
_gen.write_dashboard(graph, stream) _gen.write_dashboard(graph, stream)

View File

@ -10,7 +10,9 @@ def create_attribute():
default=None, default=None,
validator=None, validator=None,
repr=True, repr=True,
cmp=True, cmp=None,
eq=True,
order=False,
hash=True, hash=True,
init=True) init=True)

View File

@ -27,10 +27,10 @@ def test_serialization_zabbix_target():
]), ]),
], ],
id=1, id=1,
yAxes=[ yAxes=G.YAxes(
G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"), G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
G.YAxis(format=G.SHORT_FORMAT), G.YAxis(format=G.SHORT_FORMAT),
], ),
) )
stream = StringIO() stream = StringIO()
_gen.write_dashboard(graph, stream) _gen.write_dashboard(graph, stream)

View File

@ -46,10 +46,10 @@ def QPSGraph(data_source, title, expressions, **kwargs):
title=title, title=title,
expressions=exprs, expressions=exprs,
aliasColors=ALIAS_COLORS, aliasColors=ALIAS_COLORS,
yAxes=[ yAxes=G.YAxes(
G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.OPS_FORMAT),
G.YAxis(format=G.SHORT_FORMAT), G.YAxis(format=G.SHORT_FORMAT),
], ),
**kwargs **kwargs
)) ))