Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle analysis: move to prometheus #802

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 56 additions & 27 deletions services/bundle_analysis/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -87,12 +99,17 @@
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(

Check warning on line 109 in services/bundle_analysis/report.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/bundle_analysis/report.py#L108-L109

Added lines #L108 - L109 were not covered by tests
"Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER",
exc_info=True,
)

db_session.flush()

Expand Down Expand Up @@ -277,13 +294,17 @@
)
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(

Check warning on line 304 in services/bundle_analysis/report.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/bundle_analysis/report.py#L303-L304

Added lines #L303 - L304 were not covered by tests
"Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER",
exc_info=True,
)
return ProcessingResult(
upload=upload,
commit=commit,
Expand All @@ -296,13 +317,17 @@
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(

Check warning on line 327 in services/bundle_analysis/report.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/bundle_analysis/report.py#L326-L327

Added lines #L326 - L327 were not covered by tests
"Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER",
exc_info=True,
)
log.error(
"Unable to parse upload for bundle analysis",
exc_info=True,
Expand Down Expand Up @@ -438,13 +463,17 @@
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(

Check warning on line 473 in services/bundle_analysis/report.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/bundle_analysis/report.py#L472-L473

Added lines #L472 - L473 were not covered by tests
"Failed to BUNDLE_ANALYSIS_REPORT_PROCESSOR_COUNTER",
exc_info=True,
)
return ProcessingResult(
upload=upload,
commit=commit,
Expand Down
Loading