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

ARGO-3664 Rewrite metric / metric template page #619

Open
wants to merge 22 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c4ec986
Include profile information in metrics GET method
kzailac Jun 12, 2024
81fd7e3
New message when deleting metrics
kzailac Jun 13, 2024
1cc7a01
Move metric templates table to a separate function
kzailac Jun 13, 2024
6791860
Fix changing metrics when using filtered view
kzailac Jun 13, 2024
082023f
Fix deleting of metrics in filtered view
kzailac Jun 13, 2024
2bc9b2b
Change format of metric tags response
kzailac Jun 14, 2024
ae9ea40
Fix all problems with adding and deleting metrics in the UI
kzailac Jun 17, 2024
730c188
When importing internal metrics, leave out the ones that have reached…
kzailac Jun 17, 2024
0923af9
Treat internal metrics same as all the others when syncing metrics
kzailac Jun 17, 2024
fefe788
Fix handling of state in list of metric templates
kzailac Jun 18, 2024
3a0b9c3
Add import .csv button in metric profile addview
kzailac Jun 18, 2024
3fd1314
Add public API view for default ports
kzailac Jun 18, 2024
f043883
Create public default ports in the UI
kzailac Jun 18, 2024
7a96b63
Add public default ports links to public home page
kzailac Jun 18, 2024
61f8e40
JSON import/export button for metric overrides
kzailac Jun 18, 2024
e2d483a
Disable export on addview for metric overrides
kzailac Jun 18, 2024
5958eab
Import data option for metric tags
kzailac Jun 19, 2024
774bebb
Export data option for metric tags
kzailac Jun 20, 2024
c3b818a
Add tests for csv import in addview
kzailac Jun 20, 2024
257f38f
Remove dependency field from the UI
kzailac Jun 25, 2024
b9a6603
Handle form when having metric (template) with dependency
kzailac Jun 26, 2024
89a41c7
Leave out placeholder for dependency field for metric form
kzailac Jun 26, 2024
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
7 changes: 5 additions & 2 deletions poem/Poem/api/internal_views/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ def get(self, request, name=None):
if name:
metrics = poem_models.Metric.objects.filter(name=name)
if metrics.count() == 0:
raise NotFound(status=404,
detail='Metric not found')
raise NotFound(status=404, detail='Metric not found')
else:
metrics = poem_models.Metric.objects.all()

profiles4metrics = get_metrics_in_profiles(request.tenant)

results = []
for metric in metrics:
if metric.probeversion:
Expand Down Expand Up @@ -88,6 +89,8 @@ def get(self, request, name=None):
name=metric.name,
mtype=mt.mtype.name,
tags=[tag.name for tag in mt.tags.all()],
profiles=profiles4metrics[metric.name]
if metric.name in profiles4metrics else [],
probeversion=metric.probeversion if metric.probeversion else "",
group=group,
description=mt.description,
Expand Down
33 changes: 26 additions & 7 deletions poem/Poem/api/internal_views/metrictemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,10 @@ def get(self, request, name=None):
return Response({
"id": tag.id,
"name": tag.name,
"metrics": sorted([metric.name for metric in metrics])
"metrics": sorted(
[{"name": metric.name} for metric in metrics],
key=lambda m: m["name"]
)
})

except admin_models.MetricTags.DoesNotExist:
Expand All @@ -777,7 +780,10 @@ def get(self, request, name=None):
data.append({
"id": tag.id,
"name": tag.name,
"metrics": sorted([metric.name for metric in metrics])
"metrics": sorted(
[{"name": metric.name} for metric in metrics],
key=lambda m: m["name"]
)
})

return Response(data)
Expand Down Expand Up @@ -831,14 +837,16 @@ def post(self, request):

if len(missing_metrics) > 0:
if len(missing_metrics) == 1:
warn_msg = \
f"{warn_msg}Metric {list(missing_metrics)[0]} " \
warn_msg = (
f"{warn_msg}Metric {list(missing_metrics)[0]} "
f"does not exist."
)

else:
warn_msg = "{}Metrics {} do not exist.".format(
warn_msg,
", ".join(sorted(list(missing_metrics)))
warn_msg = (
f"{warn_msg}Metrics "
f"{', '.join(sorted(list(missing_metrics)))} "
f"do not exist."
)

if warn_msg:
Expand Down Expand Up @@ -1103,3 +1111,14 @@ def post(self, request):
status_code=status.HTTP_401_UNAUTHORIZED,
detail="You do not have permission to add ports"
)


class ListPublicDefaultPorts(ListDefaultPorts):
authentication_classes = ()
permission_classes = ()

def _denied(self):
return Response(status=status.HTTP_403_FORBIDDEN)

def post(self, request):
return self._denied()
36 changes: 24 additions & 12 deletions poem/Poem/api/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3587,10 +3587,13 @@ def test_sync_active_metrics(self, mock_get_metrics):
self.assertEqual(err, [])
self.assertEqual(unavailable, [])
self.assertEqual(
sorted(deleted),
["eu.egi.cloud.OpenStack-Swift", "test.Metric-Template"]
sorted(deleted), [
"argo.poem-tools.check",
"eu.egi.cloud.OpenStack-Swift",
"test.Metric-Template"
]
)
self.assertEqual(len(poem_models.Metric.objects.all()), 5)
self.assertEqual(len(poem_models.Metric.objects.all()), 4)
self.assertRaises(
poem_models.Metric.DoesNotExist,
poem_models.Metric.objects.get,
Expand Down Expand Up @@ -3635,10 +3638,13 @@ def test_sync_passive_metrics(self, mock_get_metrics):
self.assertEqual(err, [])
self.assertEqual(unavailable, [])
self.assertEqual(
sorted(deleted),
["eu.egi.cloud.OpenStack-Swift", "test.Metric-Template"]
sorted(deleted), [
"argo.poem-tools.check",
"eu.egi.cloud.OpenStack-Swift",
"test.Metric-Template"
]
)
self.assertEqual(len(poem_models.Metric.objects.all()), 5)
self.assertEqual(len(poem_models.Metric.objects.all()), 4)
self.assertRaises(
poem_models.Metric.DoesNotExist,
poem_models.Metric.objects.get,
Expand Down Expand Up @@ -3683,10 +3689,13 @@ def test_sync_metrics_with_warning(self, mock_get_metrics):
self.assertEqual(err, [])
self.assertEqual(unavailable, [])
self.assertEqual(
sorted(deleted),
["eu.egi.cloud.OpenStack-Swift", "test.Metric-Template"]
sorted(deleted), [
"argo.poem-tools.check",
"eu.egi.cloud.OpenStack-Swift",
"test.Metric-Template"
]
)
self.assertEqual(len(poem_models.Metric.objects.all()), 5)
self.assertEqual(len(poem_models.Metric.objects.all()), 4)
self.assertRaises(
poem_models.Metric.DoesNotExist,
poem_models.Metric.objects.get,
Expand Down Expand Up @@ -3731,10 +3740,13 @@ def test_sync_metrics_if_version_unavailable(self, mock_get_metrics):
self.assertEqual(err, [])
self.assertEqual(unavailable, ["test.MetricTemplate"])
self.assertEqual(
sorted(deleted),
["eu.egi.cloud.OpenStack-Swift", "test.Metric-Template"]
sorted(deleted), [
"argo.poem-tools.check",
"eu.egi.cloud.OpenStack-Swift",
"test.Metric-Template"
]
)
self.assertEqual(len(poem_models.Metric.objects.all()), 4)
self.assertEqual(len(poem_models.Metric.objects.all()), 3)
self.assertRaises(
poem_models.Metric.DoesNotExist,
poem_models.Metric.objects.get,
Expand Down
19 changes: 17 additions & 2 deletions poem/Poem/api/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ def mock_db():
content_type=ct
)

profiles4metrics = {
"argo.AMS-Check": ["ARGO_MON", "ARGO_MON_CRITICAL"],
"argo.AMSPublisher-Check": ["ARGO_MON_INTERNAL"]
}


class ListAllMetricsAPIViewTests(TenantTestCase):
@factory.django.mute_signals(pre_save)
Expand Down Expand Up @@ -424,8 +429,11 @@ def setUp(self):
name="org.apel.APEL-Pub"
)

def test_get_metric_list(self):
@patch("Poem.api.internal_views.metrics.get_metrics_in_profiles")
def test_get_metric_list(self, mock_profiles4metrics):
mock_profiles4metrics.return_value = profiles4metrics
request = self.factory.get(self.url)
request.tenant = self.tenant
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(
Expand All @@ -436,6 +444,7 @@ def test_get_metric_list(self):
'name': 'argo.AMS-Check',
'mtype': 'Active',
'tags': ['test_tag1', 'test_tag2'],
"profiles": ["ARGO_MON", "ARGO_MON_CRITICAL"],
'probeversion': 'ams-probe (0.1.7)',
'group': 'EGI',
'description': 'Description of argo.AMS-Check',
Expand Down Expand Up @@ -490,6 +499,7 @@ def test_get_metric_list(self):
'name': 'argo.AMSPublisher-Check',
'mtype': 'Active',
'tags': ['test_tag1'],
"profiles": ["ARGO_MON_INTERNAL"],
'probeversion': 'ams-publisher-probe (0.1.7)',
'group': 'EUDAT',
'description': '',
Expand Down Expand Up @@ -538,6 +548,7 @@ def test_get_metric_list(self):
'name': 'org.apel.APEL-Pub',
'mtype': 'Passive',
'tags': [],
"profiles": [],
'probeversion': '',
'group': 'EGI',
'description': '',
Expand All @@ -563,8 +574,11 @@ def test_get_metric_list(self):
]
)

def test_get_metric_by_name(self):
@patch("Poem.api.internal_views.metrics.get_metrics_in_profiles")
def test_get_metric_by_name(self, mock_profiles4metrics):
mock_profiles4metrics.return_value = profiles4metrics
request = self.factory.get(self.url + 'argo.AMS-Check')
request.tenant = self.tenant
force_authenticate(request, user=self.user)
response = self.view(request, 'argo.AMS-Check')
self.assertEqual(
Expand All @@ -574,6 +588,7 @@ def test_get_metric_by_name(self):
'name': 'argo.AMS-Check',
'mtype': 'Active',
'tags': ['test_tag1', 'test_tag2'],
"profiles": ["ARGO_MON", "ARGO_MON_CRITICAL"],
'probeversion': 'ams-probe (0.1.7)',
'group': 'EGI',
'description': 'Description of argo.AMS-Check',
Expand Down
72 changes: 56 additions & 16 deletions poem/Poem/api/tests/test_metrictemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10022,17 +10022,25 @@ def test_get_metric_tags_admin_superuser(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [{
"name": "argo.AMS-Check"
}]
},
{
"id": self.tag3.id,
"name": "test_tag1",
"metrics": ["argo.AMS-Check", "argo.EGI-Connectors-Check"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "argo.EGI-Connectors-Check"}
]
},
{
"id": self.tag4.id,
"name": "test_tag2",
"metrics": ["argo.AMS-Check", "org.apel.APEL-Pub"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "org.apel.APEL-Pub"}
]
}
]
)
Expand All @@ -10052,17 +10060,25 @@ def test_get_metric_tags_admin_regular_user(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
},
{
"id": self.tag3.id,
"name": "test_tag1",
"metrics": ["argo.AMS-Check", "argo.EGI-Connectors-Check"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "argo.EGI-Connectors-Check"}
]
},
{
"id": self.tag4.id,
"name": "test_tag2",
"metrics": ["argo.AMS-Check", "org.apel.APEL-Pub"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "org.apel.APEL-Pub"}
]
}
]
)
Expand All @@ -10082,17 +10098,25 @@ def test_get_metric_tags_tenant_superuser(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
},
{
"id": self.tag3.id,
"name": "test_tag1",
"metrics": ["argo.AMS-Check", "argo.EGI-Connectors-Check"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "argo.EGI-Connectors-Check"}
]
},
{
"id": self.tag4.id,
"name": "test_tag2",
"metrics": ["argo.AMS-Check", "org.apel.APEL-Pub"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "org.apel.APEL-Pub"}
]
}
]
)
Expand All @@ -10112,17 +10136,25 @@ def test_get_metric_tags_tenant_regular_user(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
},
{
"id": self.tag3.id,
"name": "test_tag1",
"metrics": ["argo.AMS-Check", "argo.EGI-Connectors-Check"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "argo.EGI-Connectors-Check"}
]
},
{
"id": self.tag4.id,
"name": "test_tag2",
"metrics": ["argo.AMS-Check", "org.apel.APEL-Pub"]
"metrics": [
{"name": "argo.AMS-Check"},
{"name": "org.apel.APEL-Pub"}
]
}
]
)
Expand All @@ -10141,7 +10173,9 @@ def test_get_metric_tag_by_name_admin_superuser(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
}
)

Expand All @@ -10154,7 +10188,9 @@ def test_get_metric_tag_by_name_admin_regular_user(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
}
)

Expand All @@ -10167,7 +10203,9 @@ def test_get_metric_tag_by_name_tenant_superuser(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
}
)

Expand All @@ -10180,7 +10218,9 @@ def test_get_metric_tag_by_name_tenant_regular_user(self):
{
"id": self.tag1.id,
"name": "internal",
"metrics": ["argo.AMS-Check"]
"metrics": [
{"name": "argo.AMS-Check"}
]
}
)

Expand Down
1 change: 1 addition & 0 deletions poem/Poem/api/urls_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
path("metricconfiguration/", views_internal.ListMetricConfiguration.as_view(), name="metricconfiguration"),
path("metricconfiguration/<str:name>", views_internal.ListMetricConfiguration.as_view(), name="metricconfiguration"),
path("default_ports/", views_internal.ListDefaultPorts.as_view(), name="default_ports"),
path("public_default_ports/", views_internal.ListPublicDefaultPorts.as_view(), name="default_ports"),
path("probecandidates/", views_internal.ListProbeCandidates.as_view(), name="probecandidates"),
path("probecandidates/<str:cid>", views_internal.ListProbeCandidates.as_view(), name="probecandidates"),
path("probecandidatestatuses/", views_internal.ListProbeCandidateStatuses.as_view(), name="probecandidatestatus")
Expand Down
Loading