forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request getredash#2260 from Top20Talent/master
Extend the Prometheus query runner to support the range query
- Loading branch information
Showing
3 changed files
with
194 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import datetime | ||
import json | ||
from unittest import TestCase | ||
from redash.query_runner.prometheus import get_instant_rows, get_range_rows | ||
|
||
|
||
class TestPrometheus(TestCase): | ||
def setUp(self): | ||
self.instant_query_result = [ | ||
{ | ||
"metric": { | ||
"name": "example_metric_name", | ||
"foo_bar": "foo", | ||
}, | ||
"value": [1516937400.781, "7400_foo"] | ||
}, | ||
{ | ||
"metric": { | ||
"name": "example_metric_name", | ||
"foo_bar": "bar", | ||
}, | ||
"value": [1516937400.781, "7400_bar"] | ||
} | ||
] | ||
|
||
self.range_query_result = [ | ||
{ | ||
"metric": { | ||
"name": "example_metric_name", | ||
"foo_bar": "foo", | ||
}, | ||
"values": [ | ||
[1516937400.781, "7400_foo"], | ||
[1516938000.781, "8000_foo"], | ||
] | ||
}, | ||
{ | ||
"metric": { | ||
"name": "example_metric_name", | ||
"foo_bar": "bar", | ||
}, | ||
"values": [ | ||
[1516937400.781, "7400_bar"], | ||
[1516938000.781, "8000_bar"], | ||
] | ||
} | ||
] | ||
|
||
def test_get_instant_rows(self): | ||
instant_rows = [ | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "foo", | ||
"timestamp": datetime.datetime.fromtimestamp(1516937400.781), | ||
"value": "7400_foo" | ||
}, | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "bar", | ||
"timestamp": datetime.datetime.fromtimestamp(1516937400.781), | ||
"value": "7400_bar" | ||
}, | ||
] | ||
|
||
rows = get_instant_rows(self.instant_query_result) | ||
self.assertEqual(instant_rows, rows) | ||
|
||
def test_get_range_rows(self): | ||
|
||
range_rows = [ | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "foo", | ||
"timestamp": datetime.datetime.fromtimestamp(1516937400.781), | ||
"value": "7400_foo" | ||
}, | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "foo", | ||
"timestamp": datetime.datetime.fromtimestamp(1516938000.781), | ||
"value": "8000_foo" | ||
}, | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "bar", | ||
"timestamp": datetime.datetime.fromtimestamp(1516937400.781), | ||
"value": "7400_bar" | ||
}, | ||
{ | ||
"name": "example_metric_name", | ||
"foo_bar": "bar", | ||
"timestamp": datetime.datetime.fromtimestamp(1516938000.781), | ||
"value": "8000_bar" | ||
}, | ||
] | ||
|
||
rows = get_range_rows(self.range_query_result) | ||
self.assertEqual(range_rows, rows) |