Skip to content

Commit 1f06e60

Browse files
committed
Track Pagure metrics by package name (namespace/repo)
For Pagure projects, metrics are now tracked as "rpms/python-requests" instead of just "rpms" to provide better granularity per package.
1 parent 4c9b1f5 commit 1f06e60

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

ogr/metrics.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def track_ogr_request(service_type: str) -> Callable[[F], F]:
9898
The decorated method must be called on a GitProject instance
9999
(which has `namespace` and `service` attributes).
100100
101+
For Pagure projects, the namespace is combined with the repo name
102+
(e.g., "rpms/python-requests") to provide more granular metrics.
103+
101104
Args:
102105
service_type: The service type (e.g., "github", "gitlab", "pagure")
103106
@@ -113,6 +116,13 @@ def wrapper(self, *args, **kwargs):
113116
namespace = getattr(self, "namespace", None)
114117
if namespace:
115118
try:
119+
# For Pagure, append the repo name to the namespace
120+
# to get more granular metrics (e.g., "rpms/python-requests")
121+
if service_type == "pagure":
122+
repo = getattr(self, "repo", None)
123+
if repo:
124+
namespace = f"{namespace}/{repo}"
125+
116126
record_ogr_request(service_type, namespace)
117127
except Exception as e:
118128
logger.debug(f"Failed to record metrics: {e}")

tests/unit/test_metrics.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,62 @@ def get_issues(self):
276276
("github", "packit"): 2,
277277
("github", "rpms"): 1,
278278
}
279+
280+
def test_decorator_pagure_appends_repo_to_namespace(self):
281+
"""Test that Pagure decorator appends repo name to namespace."""
282+
tracker = get_metrics_tracker()
283+
tracker.reset()
284+
285+
# Create mock Pagure project with namespace and repo
286+
mock_project = flexmock(namespace="rpms", repo="python-requests")
287+
288+
@track_ogr_request("pagure")
289+
def test_method(self):
290+
return "success"
291+
292+
result = test_method(mock_project)
293+
294+
assert result == "success"
295+
296+
counts = tracker.get_all_counts()
297+
assert counts == {("pagure", "rpms/python-requests"): 1}
298+
299+
def test_decorator_pagure_without_repo(self):
300+
"""Test Pagure decorator when repo attribute is missing."""
301+
tracker = get_metrics_tracker()
302+
tracker.reset()
303+
304+
# Create mock Pagure project with only namespace
305+
mock_project = flexmock(namespace="rpms")
306+
307+
@track_ogr_request("pagure")
308+
def test_method(self):
309+
return "success"
310+
311+
result = test_method(mock_project)
312+
313+
assert result == "success"
314+
315+
# Should fall back to just namespace when repo is missing
316+
counts = tracker.get_all_counts()
317+
assert counts == {("pagure", "rpms"): 1}
318+
319+
def test_decorator_non_pagure_does_not_append_repo(self):
320+
"""Test that non-Pagure services don't append repo to namespace."""
321+
tracker = get_metrics_tracker()
322+
tracker.reset()
323+
324+
# Create mock project with both namespace and repo
325+
mock_project = flexmock(namespace="packit", repo="some-repo")
326+
327+
@track_ogr_request("github")
328+
def test_method(self):
329+
return "success"
330+
331+
result = test_method(mock_project)
332+
333+
assert result == "success"
334+
335+
# For non-Pagure services, repo should be ignored
336+
counts = tracker.get_all_counts()
337+
assert counts == {("github", "packit"): 1}

0 commit comments

Comments
 (0)