Skip to content

Commit

Permalink
Merge pull request #10 from strava/mdavis/annotations
Browse files Browse the repository at this point in the history
Add Annotation model
  • Loading branch information
mattadav authored Apr 1, 2019
2 parents 31158b1 + 1b023c8 commit 080a9b5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

0.5.7 (2019-04-01)
==================

Fixes
-----
* Add `Annotation` model for defining dashboard annotations


0.5.6 (2019-02-21)
==================

Expand Down
90 changes: 90 additions & 0 deletions grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,3 +1743,93 @@ def to_json_data(self):
'transparent': self.transparent,
'type': TABLE_TYPE,
}


@attr.s
class Annotation(object):
"""
Annotation creates a new dashboard annotation. Annotations can be defined to query a
datasource and overlay information related to key events, such as container exits or deploys.
:param default: the default value for the variable
:param datasource: where to fetch the values for the variable from
:param label: the variable's human label
:param name: the variable's name
:param expr: the query users to fetch the valid values of the variable
:param step: the time window size to use when querying for annotation data
:param textFormat: text to display when hovering over annotation
:param refresh: Controls when to update values in the dropdown
:param allValue: specify a custom all value with regex,
globs or lucene syntax.
:param includeAll: Add a special All option whose value includes
all options.
:param regex: Regex to filter or capture specific parts of the names
return by your data source query.
:param multi: If enabled, the variable will support the selection of
multiple options at the same time.
:param type: The template type, can be one of: query (default),
interval, datasource, custom, constant, adhoc.
:param hide: Hide this variable in the dashboard, can be one of:
SHOW (default), HIDE_LABEL, HIDE_VARIABLE
"""
name = attr.ib()
expr = attr.ib(default=None)
target = attr.ib(default=None)
_current = attr.ib(init=False, default=attr.Factory(dict))
default = attr.ib(default=None)
datasource = attr.ib(default=None)
label = attr.ib(default=None)
allValue = attr.ib(default=None)
hide = attr.ib(default=SHOW)
iconColor = attr.ib(default=None)
enable = attr.ib(
default=True,
validator=instance_of(bool),
)
includeAll = attr.ib(
default=False,
validator=instance_of(bool),
)
multi = attr.ib(
default=False,
validator=instance_of(bool),
)
options = attr.ib(default=attr.Factory(list))
refresh = attr.ib(default=REFRESH_ON_DASHBOARD_LOAD,
validator=instance_of(int))
regex = attr.ib(default=None)
step = attr.ib(default=None)
tagsQuery = attr.ib(default=None)
tagValuesQuery = attr.ib(default=None)
textFormat = attr.ib(default=None)
type = attr.ib(default='query')
useTags = attr.ib(
default=False,
validator=instance_of(bool),
)

def to_json_data(self):
return {
'allValue': self.allValue,
'current': self._current,
'datasource': self.datasource,
'enable': self.enable,
'expr': self.expr,
'hide': self.hide,
'iconColor': self.iconColor,
'includeAll': self.includeAll,
'label': self.label,
'multi': self.multi,
'name': self.name,
'options': self.options,
'refresh': self.refresh,
'regex': self.regex,
'sort': 1,
'step': self.step,
'target': self.target,
'textFormat': self.textFormat,
'type': self.type,
'useTags': self.useTags,
'tagsQuery': self.tagsQuery,
'tagValuesQuery': self.tagValuesQuery,
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def local_file(name):
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.5.6',
version='0.5.7',
description='Library for building Grafana dashboards',
long_description=open(README).read(),
url='https://github.com/weaveworks/grafanalib',
Expand Down

0 comments on commit 080a9b5

Please sign in to comment.