Skip to content

Commit

Permalink
Add some counters for email stats
Browse files Browse the repository at this point in the history
Summary: After this lands and ships, we'll want to add an alarm if email notification success rates drop. It's signal that the RC release is buggy.

Reviewed By: chantra

Differential Revision: D66548174

fbshipit-source-id: 1e088502a76d7d72ddd856be818b4182975a8f8a
  • Loading branch information
Daniel Xu authored and facebook-github-bot committed Dec 2, 2024
1 parent cfb1bda commit f6b43d2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kernel_patches_daemon/branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
git_fetch_counter: metrics.Counter = meter.create_counter(name="fetch")
git_fetch_duration: metrics.Histogram = meter.create_histogram(name="fetch.duration_ms")
pr_summary_report: metrics.Counter = meter.create_counter(name="pr_summary_reports")
email_success_counter: metrics.Counter = meter.create_counter(name="email.success")
email_failure_counter: metrics.Counter = meter.create_counter(name="email.failure")
email_conflict_counter: metrics.Counter = meter.create_counter(name="email.conflict")
email_send_fail_counter: metrics.Counter = meter.create_counter(name="email.send_fail")
pr_created: metrics.Counter = meter.create_counter(name="pull_requests.created")
pr_updated: metrics.Counter = meter.create_counter(name="pull_requests.updated")
pr_closed: metrics.Counter = meter.create_counter(name="pull_requests.closed")
Expand Down Expand Up @@ -227,6 +231,15 @@ def furnish_ci_email_body(ctx: EmailBodyContext) -> str:
)


def bump_email_status_counters(status: Status):
if status == Status.SUCCESS:
email_success_counter.add(1)
elif status == Status.FAILURE:
email_failure_counter.add(1)
else:
email_conflict_counter.add(1)


def generate_msg_id(host: str) -> str:
"""Generate an email message ID based on the provided host."""
checksum = hashlib.sha256(str(time.time()).encode("utf-8")).hexdigest()
Expand Down Expand Up @@ -331,6 +344,7 @@ async def send_email(
rc = await proc.wait()
if rc != 0:
logger.error(f"failed to send email: {stdout.decode()} {stderr.decode()}")
email_send_fail_counter.add(1)


def _is_pr_flagged(pr: PullRequest) -> bool:
Expand Down Expand Up @@ -1201,6 +1215,7 @@ async def evaluate_ci_result(
ctx = build_email_body_context(self.repo, pr, status, series, inline_logs)
body = furnish_ci_email_body(ctx)
await send_email(email, series, subject, body)
bump_email_status_counters(status)

def expire_branches(self) -> None:
for branch in self.branches:
Expand Down

0 comments on commit f6b43d2

Please sign in to comment.