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

Commit 1203a60

Browse files
authored
bundle analysis: prometheus metrics fix (#903)
1 parent 3895811 commit 1203a60

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

upload/tests/views/test_bundle_analysis.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
9595
"version": "0.4.7",
9696
"action": "bundle_analysis",
9797
"endpoint": "bundle_analysis",
98-
"repo_visibility": "private",
9998
"is_using_shelter": "no",
10099
"position": "end",
101100
},
@@ -185,7 +184,6 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis):
185184
"version": "0.4.7",
186185
"action": "bundle_analysis",
187186
"endpoint": "bundle_analysis",
188-
"repo_visibility": "private",
189187
"is_using_shelter": "no",
190188
"position": "end",
191189
},
@@ -224,7 +222,6 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis):
224222
"version": "unknown-user-agent",
225223
"action": "bundle_analysis",
226224
"endpoint": "bundle_analysis",
227-
"repo_visibility": "private",
228225
"is_using_shelter": "no",
229226
"position": "end",
230227
},
@@ -271,7 +268,6 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis):
271268
"version": "unknown-user-agent",
272269
"action": "bundle_analysis",
273270
"endpoint": "bundle_analysis",
274-
"repo_visibility": "private",
275271
"is_using_shelter": "no",
276272
"position": "end",
277273
},
@@ -392,7 +388,6 @@ def test_upload_bundle_analysis_github_oidc_auth(
392388
"version": "unknown-user-agent",
393389
"action": "bundle_analysis",
394390
"endpoint": "bundle_analysis",
395-
"repo_visibility": "private",
396391
"is_using_shelter": "no",
397392
"position": "end",
398393
},
@@ -453,7 +448,6 @@ def test_upload_bundle_analysis_measurement_datasets_created(
453448
"version": "0.4.7",
454449
"action": "bundle_analysis",
455450
"endpoint": "bundle_analysis",
456-
"repo_visibility": "private",
457451
"is_using_shelter": "no",
458452
"position": "end",
459453
},
@@ -515,7 +509,6 @@ def test_upload_bundle_analysis_measurement_timeseries_disabled(
515509
"version": "0.4.7",
516510
"action": "bundle_analysis",
517511
"endpoint": "bundle_analysis",
518-
"repo_visibility": "private",
519512
"is_using_shelter": "no",
520513
"position": "end",
521514
},
@@ -612,7 +605,6 @@ def test_upload_bundle_analysis_tokenless_success(db, client, mocker, mock_redis
612605
"version": "0.4.7",
613606
"action": "bundle_analysis",
614607
"endpoint": "bundle_analysis",
615-
"repo_visibility": "public",
616608
"is_using_shelter": "no",
617609
"position": "end",
618610
},

upload/views/bundle_analysis.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"action",
4343
"endpoint",
4444
"is_using_shelter",
45-
"repo_visibility",
4645
"position",
4746
],
4847
)
@@ -81,15 +80,22 @@ def get_exception_handler(self) -> Callable:
8180
return repo_auth_custom_exception_handler
8281

8382
def post(self, request: HttpRequest) -> Response:
84-
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(
85-
**generate_upload_sentry_metrics_tags(
83+
try:
84+
labels = generate_upload_sentry_metrics_tags(
8685
action="bundle_analysis",
8786
endpoint="bundle_analysis",
8887
request=self.request,
8988
is_shelter_request=self.is_shelter_request(),
9089
position="start",
9190
)
92-
).inc()
91+
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(**labels).inc()
92+
except Exception:
93+
log.warn(
94+
"Failed to BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER",
95+
exc_info=True,
96+
extra=labels,
97+
)
98+
9399
serializer = UploadSerializer(data=request.data)
94100
if not serializer.is_valid():
95101
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@@ -168,16 +174,21 @@ def post(self, request: HttpRequest) -> Response:
168174
task_arguments=task_arguments,
169175
),
170176
)
171-
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(
172-
**generate_upload_sentry_metrics_tags(
177+
try:
178+
labels = generate_upload_sentry_metrics_tags(
173179
action="bundle_analysis",
174180
endpoint="bundle_analysis",
175181
request=self.request,
176-
repository=repo,
177182
is_shelter_request=self.is_shelter_request(),
178183
position="end",
179184
)
180-
).inc()
185+
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(**labels).inc()
186+
except Exception:
187+
log.warn(
188+
"Failed to BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER",
189+
exc_info=True,
190+
extra=labels,
191+
)
181192

182193
dispatch_upload_task(
183194
task_arguments,

0 commit comments

Comments
 (0)