Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 1173-add-list-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Jun 6, 2023
2 parents c75cd5c + ec60106 commit c042daa
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Cache can be forced to be refreshed with the ``?refresh={s3cr3t}`` querystring.
* ``/checks``: list all checks, without executing them.
* ``/checks/{a-project}``: execute all checks of project ``a-project``
* ``/checks/tags/{a-tag}``: execute all checks with tag ``a-tag``
* ``/checks/tags/{tag1}+{tag2}``: execute all checks having both tags ``tag1`` and ``tag2``

Output format:

Expand Down
72 changes: 36 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ aiohttp = "^3.8.4"
toml = "^0.10.2"
dockerflow = "^2022.8.0"
async-timeout = "^4.0.2"
sentry-sdk = "^1.24.0"
sentry-sdk = "^1.25.0"
termcolor = "^2.3.0"
aiohttp_cors = "^0.7.0"
backoff = "^2.2.1"
python-decouple = "^3.8"
logging-color-formatter = "^1.0.3"
google-cloud-bigquery = "^3.10.0"
google-cloud-bigquery = "^3.11.0"
detect-secrets = "^1.4.0"

[tool.poetry.group.dev.dependencies]
Expand All @@ -42,15 +42,15 @@ optional = true

[tool.poetry.group.remotesettings.dependencies]
kinto-http = "^11.0.1"
cryptography = "^40.0.2"
cryptography = "^41.0.1"
websockets = "^11.0"
requests = "^2.31.0"
beautifulsoup4 = "^4.12.2"
autograph-utils = "^0.1.1"
canonicaljson-rs = "^0.5.0"

[tool.poetry.group.taskcluster.dependencies]
taskcluster = "^51.0.0"
taskcluster = "^52.0.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
11 changes: 6 additions & 5 deletions telescope/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def lookup(
self,
project: Optional[str] = None,
name: Optional[str] = None,
tag: Optional[str] = None,
tags: Optional[str] = None,
):
selected = self.all

Expand All @@ -56,10 +56,11 @@ def lookup(
if len(selected) == 0:
raise ValueError(f"Unknown check '{project}.{name}'")

elif tag is not None:
selected = [c for c in selected if tag in c.tags]
elif tags is not None:
taglist: List[str] = tags.split("+")
selected = [c for c in selected if set(taglist).issubset(set(c.tags))]
if len(selected) == 0:
raise ValueError(f"No check with tag '{tag}'")
raise ValueError(f"No check with tags '{tags}'")

return selected

Expand Down Expand Up @@ -268,7 +269,7 @@ async def project_checkpoints(request):
)


@routes.get("/checks/tags/{tag}")
@routes.get("/checks/tags/{tags}")
@utils.render_checks
async def tags_checkpoints(request):
checks = request.app["telescope.checks"]
Expand Down
2 changes: 1 addition & 1 deletion tests/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ params.from_conf = 100
description = "Test plot"
module = "checks.core.heartbeat"
params.url = "http://server.local/__heartbeat__"
tags = [ "critical" ]
tags = [ "test", "critical" ]
plot = ".field"

[checks.project.env]
Expand Down
19 changes: 15 additions & 4 deletions tests/test_basic_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,34 @@ async def test_project_returns_only_cached(mock_aioresponses, cli):
assert body[1]["data"] == {"max_age": 999, "from_conf": 100}


# /tags/{tag}
# /tags/{tags}


async def test_check_tag_unknown(cli):
response = await cli.get("/checks/tags/foo")
assert response.status == 404


async def test_check_by_tag(cli, mock_aioresponses):
async def test_check_by_tags(cli, mock_aioresponses):
mock_aioresponses.get(
"http://server.local/__heartbeat__", status=200, payload={"ok": True}
)
response = await cli.get("/checks/tags/ops")
assert response.status == 200


async def test_check_by_tag_text_mode(cli, mock_aioresponses):
async def test_check_by_multiple_tags(cli, mock_aioresponses):
mock_aioresponses.get(
"http://server.local/__heartbeat__", status=200, payload={"ok": True}
)
response = await cli.get("/checks/tags/ops+test")
assert response.status == 200
body = await response.json()
# Only one check has "ops" and "test" tags in `config.toml`
assert len(body) == 1


async def test_check_by_tags_text_mode(cli, mock_aioresponses):
mock_aioresponses.get(
"http://server.local/__heartbeat__", status=500, payload={"ok": False}
)
Expand Down Expand Up @@ -371,7 +382,7 @@ async def test_logging_result(caplog, cli, mock_aioresponses):
assert result_logs[0].success
assert result_logs[0].project == "project"
assert result_logs[0].check == "plot"
assert result_logs[0].tags == ["critical"]
assert result_logs[0].tags == ["test", "critical"]
assert result_logs[0].plot == 12

assert result_logs[1].plot is None
Expand Down

0 comments on commit c042daa

Please sign in to comment.