Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative time in cloudwatch queries #4649

Merged
merged 1 commit into from
Feb 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions redash/query_runner/cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime

from redash.query_runner import BaseQueryRunner, register
from redash.utils import json_dumps
from redash.utils import json_dumps, parse_human_time


def parse_response(results):
Expand All @@ -30,6 +30,18 @@ def parse_response(results):
return rows, columns


def parse_query(query):
query = yaml.safe_load(query)

for timeKey in ["StartTime", "EndTime"]:
if isinstance(query.get(timeKey), str):
query[timeKey] = int(parse_human_time(query[timeKey]).timestamp())
if not query.get("EndTime"):
query["EndTime"] = int(datetime.datetime.now().timestamp())

return query


class CloudWatch(BaseQueryRunner):
should_annotate_query = False

Expand Down Expand Up @@ -89,7 +101,7 @@ def get_schema(self, get_stats=False):
def run_query(self, query, user):
cloudwatch = self._get_client()

query = yaml.safe_load(query)
query = parse_query(query)

results = []
paginator = cloudwatch.get_paginator("get_metric_data")
Expand Down