From 700382a576519e0f8f2fcca14a3c71188238b90f Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Fri, 18 Oct 2024 06:20:25 +0900 Subject: [PATCH 1/2] bundle analysis: prometheus metrics --- upload/tests/views/test_bundle_analysis.py | 8 -------- upload/views/bundle_analysis.py | 2 -- 2 files changed, 10 deletions(-) diff --git a/upload/tests/views/test_bundle_analysis.py b/upload/tests/views/test_bundle_analysis.py index 5f5ee9108c..1ca1518b75 100644 --- a/upload/tests/views/test_bundle_analysis.py +++ b/upload/tests/views/test_bundle_analysis.py @@ -95,7 +95,6 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis): "version": "0.4.7", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -185,7 +184,6 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis): "version": "0.4.7", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -224,7 +222,6 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis): "version": "unknown-user-agent", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -271,7 +268,6 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis): "version": "unknown-user-agent", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -392,7 +388,6 @@ def test_upload_bundle_analysis_github_oidc_auth( "version": "unknown-user-agent", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -453,7 +448,6 @@ def test_upload_bundle_analysis_measurement_datasets_created( "version": "0.4.7", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -515,7 +509,6 @@ def test_upload_bundle_analysis_measurement_timeseries_disabled( "version": "0.4.7", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "private", "is_using_shelter": "no", "position": "end", }, @@ -612,7 +605,6 @@ def test_upload_bundle_analysis_tokenless_success(db, client, mocker, mock_redis "version": "0.4.7", "action": "bundle_analysis", "endpoint": "bundle_analysis", - "repo_visibility": "public", "is_using_shelter": "no", "position": "end", }, diff --git a/upload/views/bundle_analysis.py b/upload/views/bundle_analysis.py index f8b4af3989..6c60655eec 100644 --- a/upload/views/bundle_analysis.py +++ b/upload/views/bundle_analysis.py @@ -42,7 +42,6 @@ "action", "endpoint", "is_using_shelter", - "repo_visibility", "position", ], ) @@ -173,7 +172,6 @@ def post(self, request: HttpRequest) -> Response: action="bundle_analysis", endpoint="bundle_analysis", request=self.request, - repository=repo, is_shelter_request=self.is_shelter_request(), position="end", ) From ddd8572349be670b8973dad13a666e7e43ce2b3f Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Fri, 18 Oct 2024 06:30:38 +0900 Subject: [PATCH 2/2] try catch metrics --- upload/views/bundle_analysis.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/upload/views/bundle_analysis.py b/upload/views/bundle_analysis.py index 6c60655eec..f9a37e2cfe 100644 --- a/upload/views/bundle_analysis.py +++ b/upload/views/bundle_analysis.py @@ -80,15 +80,22 @@ def get_exception_handler(self) -> Callable: return repo_auth_custom_exception_handler def post(self, request: HttpRequest) -> Response: - BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels( - **generate_upload_sentry_metrics_tags( + try: + labels = generate_upload_sentry_metrics_tags( action="bundle_analysis", endpoint="bundle_analysis", request=self.request, is_shelter_request=self.is_shelter_request(), position="start", ) - ).inc() + BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(**labels).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER", + exc_info=True, + extra=labels, + ) + serializer = UploadSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) @@ -167,15 +174,21 @@ def post(self, request: HttpRequest) -> Response: task_arguments=task_arguments, ), ) - BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels( - **generate_upload_sentry_metrics_tags( + try: + labels = generate_upload_sentry_metrics_tags( action="bundle_analysis", endpoint="bundle_analysis", request=self.request, is_shelter_request=self.is_shelter_request(), position="end", ) - ).inc() + BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels(**labels).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER", + exc_info=True, + extra=labels, + ) dispatch_upload_task( task_arguments,