Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# limitations under the License.
import re
import attr
from grafanalib import core as g
DECREASING_ORDER_TOOLTIP = g.Tooltip(sort=g.SORT_DESC)
PANEL_HEIGHT = g.Pixels(300)
QUANTILES = [0.99, 0.9, 0.5]
SOURCE_TEMPLATE = g.Template(name="source", type="datasource", query="prometheus")
@attr.s
class Dashboard(g.Dashboard):
time = attr.ib(default=g.Time("now-30d", "now"))
# Make it possible to use $source as a source.
templating = attr.ib(default=g.Templating(list=[SOURCE_TEMPLATE]))
# Graph is a g.Graph with reasonable defaults applied.
@attr.s
class Graph(g.Graph):
dataSource = attr.ib(default="$source")
span = attr.ib(default=g.TOTAL_SPAN)
tooltip = attr.ib(default=DECREASING_ORDER_TOOLTIP)
nullPointMode = attr.ib(default=None)
@attr.s
class Row(g.Row):
height = attr.ib(default=PANEL_HEIGHT)
links = attr.ib(default=attr.Factory(list))
refresh = attr.ib(default=DEFAULT_REFRESH)
schemaVersion = attr.ib(default=SCHEMA_VERSION)
sharedCrosshair = attr.ib(
default=False,
validator=instance_of(bool),
)
style = attr.ib(default=DARK_STYLE)
tags = attr.ib(default=attr.Factory(list))
templating = attr.ib(
default=attr.Factory(Templating),
validator=instance_of(Templating),
)
time = attr.ib(
default=attr.Factory(lambda: DEFAULT_TIME),
validator=instance_of(Time),
)
timePicker = attr.ib(
default=attr.Factory(lambda: DEFAULT_TIME_PICKER),
validator=instance_of(TimePicker),
)
timezone = attr.ib(default=UTC)
version = attr.ib(default=0)
uid = attr.ib(default=None)
def _iter_panels(self):
for row in self.rows:
for panel in row._iter_panels():
yield panel
def _map_panels(self, f):
return attr.evolve(self, rows=[r._map_panels(f) for r in self.rows])
}
@attr.s
class Time(object):
start = attr.ib()
end = attr.ib()
def to_json_data(self):
return {
'from': self.start,
'to': self.end,
}
DEFAULT_TIME = Time('now-1h', 'now')
@attr.s
class TimePicker(object):
refreshIntervals = attr.ib()
timeOptions = attr.ib()
def to_json_data(self):
return {
'refresh_intervals': self.refreshIntervals,
'time_options': self.timeOptions,
}
DEFAULT_TIME_PICKER = TimePicker(
refreshIntervals=[