Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 7987e60

Browse files
committed
Add metrics
1 parent 87e2a2b commit 7987e60

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

upload/views/combined_upload.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from rest_framework import status
66
from rest_framework.response import Response
77
from rest_framework.views import APIView
8+
from shared.metrics import inc_counter
89

910
from codecov_auth.authentication.repo_auth import (
1011
GitHubOIDCTokenAuthentication,
@@ -16,6 +17,8 @@
1617
repo_auth_custom_exception_handler,
1718
)
1819
from services.archive import ArchiveService
20+
from upload.helpers import generate_upload_prometheus_metrics_labels
21+
from upload.metrics import API_UPLOAD_COUNTER
1922
from upload.serializers import (
2023
CommitReportSerializer,
2124
CommitSerializer,
@@ -48,6 +51,17 @@ def get_exception_handler(self):
4851
return repo_auth_custom_exception_handler
4952

5053
def post(self, request: HttpRequest, *args, **kwargs) -> Response:
54+
inc_counter(
55+
API_UPLOAD_COUNTER,
56+
labels=generate_upload_prometheus_metrics_labels(
57+
action="coverage",
58+
endpoint="combined_upload",
59+
request=self.request,
60+
is_shelter_request=self.is_shelter_request(),
61+
position="start",
62+
),
63+
)
64+
5165
# Create commit
5266
create_commit_data = dict(
5367
commitid=request.data.get("commit_sha"),
@@ -62,6 +76,17 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:
6276
)
6377
log.info(f"Creating commit for {commit_serializer.validated_data}")
6478
repository = self.get_repo()
79+
80+
inc_counter(
81+
API_UPLOAD_COUNTER,
82+
labels=generate_upload_prometheus_metrics_labels(
83+
action="coverage",
84+
endpoint="combined_upload",
85+
request=self.request,
86+
is_shelter_request=self.is_shelter_request(),
87+
position="create_commit",
88+
),
89+
)
6590
commit = self.create_commit(commit_serializer, repository)
6691

6792
# Create report
@@ -73,6 +98,17 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:
7398
return Response(
7499
commit_report_serializer.errors, status=status.HTTP_400_BAD_REQUEST
75100
)
101+
102+
inc_counter(
103+
API_UPLOAD_COUNTER,
104+
labels=generate_upload_prometheus_metrics_labels(
105+
action="coverage",
106+
endpoint="combined_upload",
107+
request=self.request,
108+
is_shelter_request=self.is_shelter_request(),
109+
position="create_report",
110+
),
111+
)
76112
report = self.create_report(commit_report_serializer, repository, commit)
77113

78114
# Do upload
@@ -91,8 +127,29 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:
91127
upload_serializer.errors, status=status.HTTP_400_BAD_REQUEST
92128
)
93129

130+
inc_counter(
131+
API_UPLOAD_COUNTER,
132+
labels=generate_upload_prometheus_metrics_labels(
133+
action="coverage",
134+
endpoint="combined_upload",
135+
request=self.request,
136+
is_shelter_request=self.is_shelter_request(),
137+
position="create_upload",
138+
),
139+
)
94140
upload = self.create_upload(upload_serializer, repository, commit, report)
95141

142+
inc_counter(
143+
API_UPLOAD_COUNTER,
144+
labels=generate_upload_prometheus_metrics_labels(
145+
action="coverage",
146+
endpoint="combined_upload",
147+
request=self.request,
148+
is_shelter_request=self.is_shelter_request(),
149+
position="end",
150+
),
151+
)
152+
96153
if upload:
97154
url = f"{settings.CODECOV_DASHBOARD_URL}/{repository.author.service}/{repository.author.username}/{repository.name}/commit/{commit.commitid}"
98155
archive_service = ArchiveService(repository)

0 commit comments

Comments
 (0)