Skip to content
Snippets Groups Projects
Commit c14cfd1b authored by Antoine Lambert's avatar Antoine Lambert
Browse files

misc/coverage: Display counters for bzr/cvs visit types conditionally

When loading task types are available for these visit types in the
swh deployment environment (currently staging and docker), display
the associated counters in the coverage widget.

Related to T3945

Related to T3835
parent 937a1d59
No related branches found
No related tags found
1 merge request!734misc/coverage: Display counters for bzr/cvs visit types conditionally
# Copyright (C) 2018-2021 The Software Heritage developers # Copyright (C) 2018-2022 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution # See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version # License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information # See top-level LICENSE file for more information
...@@ -17,6 +17,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt ...@@ -17,6 +17,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt
from swh.scheduler.model import SchedulerMetrics from swh.scheduler.model import SchedulerMetrics
from swh.web.common import archive from swh.web.common import archive
from swh.web.common.origin_save import get_savable_visit_types
from swh.web.common.utils import get_deposits_list, reverse from swh.web.common.utils import get_deposits_list, reverse
from swh.web.config import scheduler from swh.web.config import scheduler
...@@ -330,8 +331,11 @@ def _swh_coverage(request): ...@@ -330,8 +331,11 @@ def _swh_coverage(request):
origins["count"] = f"{count:,}" origins["count"] = f"{count:,}"
origins["instances"] = defaultdict(dict) origins["instances"] = defaultdict(dict)
for instance, metrics in listers_metrics[origins_type]: for instance, metrics in listers_metrics[origins_type]:
# not yet in production # these types are available in staging/docker but not yet in production
if metrics.visit_type in ("bzr", "cvs"): if (
metrics.visit_type in ("bzr", "cvs")
and metrics.visit_type not in get_savable_visit_types()
):
continue continue
instance_count = metrics.origins_known - metrics.origins_never_visited instance_count = metrics.origins_known - metrics.origins_never_visited
origins["instances"][instance].update( origins["instances"][instance].update(
......
# Copyright (C) 2021 The Software Heritage developers # Copyright (C) 2021-2022 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution # See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version # License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information # See top-level LICENSE file for more information
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
from datetime import datetime, timezone from datetime import datetime, timezone
from itertools import chain from itertools import chain
import os import os
from random import choice, randint from random import randint
import uuid import uuid
import pytest import pytest
...@@ -33,7 +33,7 @@ def clear_lru_caches(): ...@@ -33,7 +33,7 @@ def clear_lru_caches():
_get_deposits_netloc_counts.cache_clear() _get_deposits_netloc_counts.cache_clear()
def test_coverage_view_no_metrics(client): def test_coverage_view_no_metrics(client, swh_scheduler):
""" """
Check coverage view can be rendered when scheduler metrics and deposits Check coverage view can be rendered when scheduler metrics and deposits
data are not available. data are not available.
...@@ -54,6 +54,7 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker): ...@@ -54,6 +54,7 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker):
"swh.web.misc.coverage._get_nixguix_origins_count" "swh.web.misc.coverage._get_nixguix_origins_count"
).return_value = 30095 ).return_value = 30095
listers = [] listers = []
visit_types = ["git", "hg", "svn", "bzr", "svn"]
for origins in listed_origins["origins"]: for origins in listed_origins["origins"]:
# create some instances for each lister # create some instances for each lister
for instance in range(randint(1, 5)): for instance in range(randint(1, 5)):
...@@ -64,9 +65,8 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker): ...@@ -64,9 +65,8 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker):
# record some sample listed origins # record some sample listed origins
_origins = [] _origins = []
origin_visit_stats = [] origin_visit_stats = []
for i in range(randint(3, 10)): for i, visit_type in enumerate(visit_types):
url = str(uuid.uuid4()) url = str(uuid.uuid4())
visit_type = choice(["git", "hg", "svn"])
_origins.append( _origins.append(
ListedOrigin( ListedOrigin(
lister_id=lister.id, lister_id=lister.id,
...@@ -124,10 +124,13 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker): ...@@ -124,10 +124,13 @@ def test_coverage_view_with_metrics(client, swh_scheduler, mocker):
assert_contains(resp, f'src="{logo_url}"') assert_contains(resp, f'src="{logo_url}"')
if "instances" in origins: if "instances" in origins:
for visit_types in origins["instances"].values(): for visit_types_ in origins["instances"].values():
for data in visit_types.values(): for data in visit_types_.values():
if data["count"]: if data["count"]:
assert_contains(resp, f'<a href="{escape(data["search_url"])}"') assert_contains(resp, f'<a href="{escape(data["search_url"])}"')
else: else:
for search_url in origins["search_urls"].values(): for search_url in origins["search_urls"].values():
assert_contains(resp, f'<a href="{escape(search_url)}"') assert_contains(resp, f'<a href="{escape(search_url)}"')
for visit_type in visit_types:
assert_contains(resp, f"<td>{visit_type}</td>")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment