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',
),
],
yAxes=[
yAxes=G.YAxes(
YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT),
],
),
alert=Alert(
name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes",

View File

@ -38,7 +38,8 @@ g = Graph(
dataSource="elasticsearch",
targets=tgts,
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,
nullPointMode=NULL_AS_NULL,
seriesOverrides=[
@ -68,7 +69,7 @@ g = Graph(
"color": "#447EBC"
},
],
yAxes=[
yAxes=G.YAxes(
YAxis(
label="Count",
format=SHORT_FORMAT,
@ -79,7 +80,7 @@ g = Graph(
format=SECONDS_FORMAT,
decimals=2
),
],
),
transparent=True,
span=12,
)

View File

@ -2,78 +2,78 @@ from grafanalib.core import *
dashboard = Dashboard(
title="Frontend Stats",
rows=[
Row(panels=[
Graph(
title="Frontend QPS",
dataSource='My Prometheus',
targets=[
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"1.."}[1m]))',
legendFormat="1xx",
refId='A',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"2.."}[1m]))',
legendFormat="2xx",
refId='B',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"3.."}[1m]))',
legendFormat="3xx",
refId='C',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"4.."}[1m]))',
legendFormat="4xx",
refId='D',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
legendFormat="5xx",
refId='E',
),
],
yAxes=[
YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT),
],
alert=Alert(
name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes",
alertConditions=[
AlertCondition(
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
legendFormat="5xx",
refId='A',
),
timeRange=TimeRange("5m", "now"),
evaluator=GreaterThan(5),
operator=OP_AND,
reducerType=RTYPE_SUM,
title="Frontend Stats",
rows=[
Row(panels=[
Graph(
title="Frontend QPS",
dataSource='My Prometheus',
targets=[
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"1.."}[1m]))',
legendFormat="1xx",
refId='A',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"2.."}[1m]))',
legendFormat="2xx",
refId='B',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"3.."}[1m]))',
legendFormat="3xx",
refId='C',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"4.."}[1m]))',
legendFormat="4xx",
refId='D',
),
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
legendFormat="5xx",
refId='E',
),
],
yAxes=G.YAxes(
YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT),
),
],
)
),
Graph(
title="Frontend latency",
dataSource='My Prometheus',
targets=[
Target(
expr='histogram_quantile(0.5, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
legendFormat="0.5 quantile",
refId='A',
alert=Alert(
name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes",
alertConditions=[
AlertCondition(
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
legendFormat="5xx",
refId='A',
),
timeRange=TimeRange("5m", "now"),
evaluator=GreaterThan(5),
operator=OP_AND,
reducerType=RTYPE_SUM,
),
],
)
),
Graph(
title="Frontend latency",
dataSource='My Prometheus',
targets=[
Target(
expr='histogram_quantile(0.5, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
legendFormat="0.5 quantile",
refId='A',
),
Target(
expr='histogram_quantile(0.99, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
legendFormat="0.99 quantile",
refId='B',
),
],
yAxes=single_y_axis(format=SECONDS_FORMAT),
),
Target(
expr='histogram_quantile(0.99, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
legendFormat="0.99 quantile",
refId='B',
),
],
yAxes=single_y_axis(format=SECONDS_FORMAT),
),
]),
],
]),
],
).auto_panel_ids()

View File

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

View File

@ -455,7 +455,7 @@ def _balance_panels(panels):
auto_span = math.ceil(
(TOTAL_SPAN - allotted_spans) / (len(no_span_set) or 1))
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
]
@ -483,7 +483,7 @@ class Row(object):
return iter(self.panels)
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):
showTitle = False
@ -915,7 +915,7 @@ class Dashboard(object):
yield panel
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):
"""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)
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)
def to_json_data(self):

View File

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

View File

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

View File

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

View File

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

View File

@ -17,13 +17,13 @@ ORANGE = "#EF843C"
RED = "#E24D42"
ALIAS_COLORS = {
"1xx": YELLOW,
"2xx": GREEN,
"3xx": BLUE,
"4xx": ORANGE,
"5xx": RED,
"success": GREEN,
"error": RED,
"1xx": YELLOW,
"2xx": GREEN,
"3xx": BLUE,
"4xx": ORANGE,
"5xx": RED,
"success": GREEN,
"error": RED,
}
@ -46,10 +46,10 @@ def QPSGraph(data_source, title, expressions, **kwargs):
title=title,
expressions=exprs,
aliasColors=ALIAS_COLORS,
yAxes=[
yAxes=G.YAxes(
G.YAxis(format=G.OPS_FORMAT),
G.YAxis(format=G.SHORT_FORMAT),
],
),
**kwargs
))