Skip to content

Commit

Permalink
Fix safety check for uptake max age (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Mar 4, 2020
1 parent baa9d0c commit 4c608eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
15 changes: 5 additions & 10 deletions checks/remotesettings/uptake_max_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ async def run(
# Fetch latest results from Redash JSON API.
rows = await fetch_redash(REDASH_QUERY_ID, api_key)
rows = [row for row in rows if row["channel"].lower() in channels]
if len(rows) == 0:
raise ValueError(f"No data for channels {channels}")

age_percentiles = rows[0]["age_percentiles"]
# If no changes were published during this period, then percentiles can be empty.
if len(rows) == 0:
return True, {"percentiles": "No broadcast data during this period."}

min_timestamp = min(r["min_timestamp"] for r in rows)
max_timestamp = max(r["max_timestamp"] for r in rows)
data = {
"min_timestamp": min_timestamp,
"max_timestamp": max_timestamp,
}
data = {"min_timestamp": min_timestamp, "max_timestamp": max_timestamp}

# If no changes were published during this period, then percentiles can be empty.
if len(age_percentiles) == 0:
return True, {**data, "percentiles": "No broadcast data during this period."}
age_percentiles = rows[0]["age_percentiles"]

percentiles = {}
for percentile, max_value in max_percentiles.items():
Expand Down
16 changes: 4 additions & 12 deletions tests/checks/remotesettings/test_uptake_max_age.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from checks.remotesettings.uptake_max_age import run
from tests.utils import patch_async

Expand Down Expand Up @@ -38,10 +36,10 @@ async def test_positive():


async def test_positive_no_data():
with patch_async(
f"{MODULE}.fetch_redash", return_value=[{**FAKE_ROWS[0], "age_percentiles": []}]
):
status, data = await run(api_key="", max_percentiles={"50": 42})
with patch_async(f"{MODULE}.fetch_redash", return_value=FAKE_ROWS):
status, data = await run(
api_key="", max_percentiles={"50": 42}, channels=["aurora"]
)

assert status is True
assert data["percentiles"] == "No broadcast data during this period."
Expand Down Expand Up @@ -71,9 +69,3 @@ async def test_filter_by_channel():
"max_timestamp": "2019-09-16T02:00:00.000",
"percentiles": {"10": {"value": 100, "max": 99}},
}


async def test_wrong_channel():
with patch_async(f"{MODULE}.fetch_redash", return_value=FAKE_ROWS):
with pytest.raises(ValueError):
await run(api_key="", max_percentiles={"10": 99}, channels=["unknown"])

0 comments on commit 4c608eb

Please sign in to comment.