Skip to content

Commit

Permalink
style adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
jubel-han committed Feb 24, 2018
1 parent 135af39 commit 49e9133
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions redash/query_runner/prometheus.py
Expand Up @@ -38,21 +38,6 @@ def get_range_rows(metrics_data):


class Prometheus(BaseQueryRunner):
def __init__(self, configuration):
self.columns = [
{
'friendly_name': 'timestamp',
'type': TYPE_DATETIME,
'name': 'timestamp'
},
{
'friendly_name': 'value',
'type': TYPE_STRING,
'name': 'value'
},
]

super(Prometheus, self).__init__(configuration)

@classmethod
def configuration_schema(cls):
Expand All @@ -71,6 +56,10 @@ def configuration_schema(cls):
def annotate_query(cls):
return False

@classmethod
def type(cls):
return "Prometheus"

def test_connection(self):
resp = requests.get(self.configuration.get("url", None))
return resp.ok
Expand Down Expand Up @@ -107,6 +96,18 @@ def run_query(self, query, user):
"""

base_url = self.configuration["url"]
columns = [
{
'friendly_name': 'timestamp',
'type': TYPE_DATETIME,
'name': 'timestamp'
},
{
'friendly_name': 'value',
'type': TYPE_STRING,
'name': 'value'
},
]

try:
error = None
Expand Down Expand Up @@ -135,17 +136,21 @@ def run_query(self, query, user):
metric_labels = metrics[0]['metric'].keys()

for label_name in metric_labels:
self.columns.append({
columns.append({
'friendly_name': label_name,
'type': TYPE_STRING,
'name': label_name
})

rows = get_range_rows(metrics) if query_type == 'query_range' else get_instant_rows(metrics)
if query_type == 'query_range':
rows = get_range_rows(metrics)
else:
rows = get_instant_rows(metrics)

json_data = json_dumps(
{
'rows': rows,
'columns': self.columns
'columns': columns
}
)

Expand Down

0 comments on commit 49e9133

Please sign in to comment.