From d9dfe2828e3b9d2a42a0bb73eb71730f1cbbf5c9 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Tue, 22 Oct 2024 04:29:12 +0900 Subject: [PATCH] bundle analysis: move to prometheus --- services/bundle_analysis/report.py | 83 ++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/services/bundle_analysis/report.py b/services/bundle_analysis/report.py index b67bfcde8..49552a770 100644 --- a/services/bundle_analysis/report.py +++ b/services/bundle_analysis/report.py @@ -12,6 +12,7 @@ from shared.django_apps.bundle_analysis.service.bundle_analysis import ( BundleAnalysisCacheConfigService, ) +from shared.metrics import Counter from shared.reports.enums import UploadState, UploadType from shared.storage.exceptions import FileNotInStorageError, PutRequestRateLimitError from shared.utils.sessions import SessionType @@ -30,6 +31,17 @@ log = logging.getLogger(__name__) +BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER = Counter( + "bundle_analysis_report_processor_runs", + "Number of times a BA report processor was run and with what result", + [ + "result", + "plugin_name", + "repository", + ], +) + + @dataclass class ProcessingError: code: str @@ -87,12 +99,17 @@ def update_upload(self, carriedforward: Optional[bool] = False) -> None: self.upload.upload_type = SessionType.carriedforward.value self.upload_type_id = UploadType.CARRIEDFORWARD.db_id - sentry_sdk.metrics.incr( - "bundle_analysis_upload", - tags={ - "result": "upload_error" if self.error else "processed", - }, - ) + try: + BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER.labels( + result="upload_error" if self.error else "processed", + plugin_name="n/a", + repository=self.commit.repository.repoid, + ).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER", + exc_info=True, + ) db_session.flush() @@ -277,13 +294,17 @@ def process_upload( ) except PutRequestRateLimitError as e: plugin_name = getattr(e, "bundle_analysis_plugin_name", "unknown") - sentry_sdk.metrics.incr( - "bundle_analysis_upload", - tags={ - "result": "rate_limit_error", - "plugin_name": plugin_name, - }, - ) + try: + BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER.labels( + result="rate_limit_error", + plugin_name=plugin_name, + repository=commit.repository.repoid, + ).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER", + exc_info=True, + ) return ProcessingResult( upload=upload, commit=commit, @@ -296,13 +317,17 @@ def process_upload( except Exception as e: # Metrics to count number of parsing errors of bundle files by plugins plugin_name = getattr(e, "bundle_analysis_plugin_name", "unknown") - sentry_sdk.metrics.incr( - "bundle_analysis_upload", - tags={ - "result": "parser_error", - "plugin_name": plugin_name, - }, - ) + try: + BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER.labels( + result="parser_error", + plugin_name=plugin_name, + repository=commit.repository.repoid, + ).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER", + exc_info=True, + ) log.error( "Unable to parse upload for bundle analysis", exc_info=True, @@ -438,13 +463,17 @@ def save_measurements( commit=commit, ) except Exception: - sentry_sdk.metrics.incr( - "bundle_analysis_upload", - tags={ - "result": "parser_error", - "repository": commit.repository.repoid, - }, - ) + try: + BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER.labels( + result="parser_error", + plugin_name="n/a", + repository=commit.repository.repoid, + ).inc() + except Exception: + log.warn( + "Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER", + exc_info=True, + ) return ProcessingResult( upload=upload, commit=commit,