Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# 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):
G.Target(
expr='sum(wormhole_signup_failure{pod=~"s4-signup.*"})',
legendFormat="Wormhole Signups Failed",
refId="C",
),
],
),
G.Graph(
title="Usage",
dataSource=PROMETHEUS,
# Stack the connection graphs on each other, revealing
# both a total and a distribution across different grid
# router instances.
stack=True,
tooltip=G.Tooltip(
valueType=G.INDIVIDUAL,
),
xAxis=X_TIME,
yAxes=[
G.YAxis(
format="none",
label="Count",
),
G.YAxis(
format="none",
label="Count",
),
],
targets=[
G.Target(
links = attr.ib(default=attr.Factory(list))
minSpan = attr.ib(default=None)
nullPointMode = attr.ib(default=NULL_CONNECTED)
percentage = attr.ib(default=False, validator=instance_of(bool))
pointRadius = attr.ib(default=DEFAULT_POINT_RADIUS)
points = attr.ib(default=False, validator=instance_of(bool))
renderer = attr.ib(default=DEFAULT_RENDERER)
repeat = attr.ib(default=None)
seriesOverrides = attr.ib(default=attr.Factory(list))
span = attr.ib(default=None)
stack = attr.ib(default=False, validator=instance_of(bool))
steppedLine = attr.ib(default=False, validator=instance_of(bool))
timeFrom = attr.ib(default=None)
timeShift = attr.ib(default=None)
tooltip = attr.ib(
default=attr.Factory(Tooltip),
validator=instance_of(Tooltip),
)
transparent = attr.ib(default=False, validator=instance_of(bool))
xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis))
# XXX: This isn't a *good* default, rather it's the default Grafana uses.
yAxes = attr.ib(
default=attr.Factory(YAxes),
converter=to_y_axes,
validator=instance_of(YAxes),
)
alert = attr.ib(default=None)
def to_json_data(self):
graphObject = {
'aliasColors': self.aliasColors,
'bars': self.bars,
def stacked(graph):
"""Turn a graph into a stacked graph."""
return attr.assoc(
graph,
lineWidth=0,
nullPointMode=G.NULL_AS_ZERO,
stack=True,
fill=10,
tooltip=G.Tooltip(
sort=G.SORT_DESC,
valueType=G.INDIVIDUAL,
),
minSpan = attr.ib(default=None)
nullPointMode = attr.ib(default=NULL_CONNECTED)
percentage = attr.ib(default=False, validator=instance_of(bool))
pointRadius = attr.ib(default=DEFAULT_POINT_RADIUS)
points = attr.ib(default=False, validator=instance_of(bool))
renderer = attr.ib(default=DEFAULT_RENDERER)
repeat = attr.ib(default=None)
seriesOverrides = attr.ib(default=attr.Factory(list))
span = attr.ib(default=None)
stack = attr.ib(default=False, validator=instance_of(bool))
steppedLine = attr.ib(default=False, validator=instance_of(bool))
timeFrom = attr.ib(default=None)
timeShift = attr.ib(default=None)
tooltip = attr.ib(
default=attr.Factory(Tooltip),
validator=instance_of(Tooltip),
)
transparent = attr.ib(default=False, validator=instance_of(bool))
xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis))
# XXX: This isn't a *good* default, rather it's the default Grafana uses.
yAxes = attr.ib(
default=attr.Factory(YAxes),
converter=to_y_axes,
validator=instance_of(YAxes),
)
alert = attr.ib(default=None)
def to_json_data(self):
graphObject = {
'aliasColors': self.aliasColors,
'bars': self.bars,
'datasource': self.dataSource,