Skip to content

Bug 2007542 - Rate limit error reports#7139

Merged
bendk merged 1 commit intomozilla:mainfrom
bendk:push-urmzomqpyvuq
Jan 8, 2026
Merged

Bug 2007542 - Rate limit error reports#7139
bendk merged 1 commit intomozilla:mainfrom
bendk:push-urmzomqpyvuq

Conversation

@bendk
Copy link
Copy Markdown
Contributor

@bendk bendk commented Dec 23, 2025

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

@bendk bendk requested review from a team and lougeniaC64 December 23, 2025 16:43
@bendk bendk force-pushed the push-urmzomqpyvuq branch 3 times, most recently from afa5945 to 4cec688 Compare December 29, 2025 16:52
Copy link
Copy Markdown
Contributor

@skhamis skhamis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice! This should help cut how often we send (but still get us what we need). Did have a few nits/comments/suggestions, at least the comment updates but don't need to block on em. r+!

static GLOBALS: Mutex<Globals> = Mutex::new(Globals::new());

pub fn report_error_to_app(type_name: String, message: String) {
let mut globals = GLOBALS.lock();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe we should do all the lock work together? Something like:

    let breadcrumbs = {
        let mut globals = GLOBALS.lock();
        if !globals.rate_limiter.should_send_report(&type_name, Instant::now()) {
            return;
        }
        globals.breadcrumbs.get_breadcrumbs()
    };
    let breadcrumbs = breadcrumbs.join("\n");
    tracing_support::error!(target: "app-services-error-reporter::error", message, type_name, breadcrumbs);
}

breadcrumb[0..split_point].to_string()
}

/// Rate-limits error reports by type to 20 / hour
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make it more clear (based on the tests):

Rate-limits error reports per component by type to a max of 20/hr

// The first error report is okay
assert!(rate_limiter.should_send_report("test-type", start));
// The report should be rate limited until 3 minutes pass, then we can send another one.
// Subtract time from the instant to simulate time going forward.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: Add time

@bendk bendk force-pushed the push-urmzomqpyvuq branch 2 times, most recently from 42c546b to c41e0f4 Compare January 8, 2026 14:59
}
// For all other cases, fall through and allow the report to be sent.
//
// Note: this also covers the `None` case which happens when the clock is
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendk This is really in the weeds but out of (morbid) curiousity are we expecting the time since the last report was checked to be wall clock time more often than not?

Copy link
Copy Markdown
Contributor Author

@bendk bendk Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think so. I think this could get slightly messed up when the OS syncs with NTP or if users manually adjust their clocks, but that should be very marginal. If that happens, maybe an error report won't will be sent, but we should get back into a good state soon after.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no big deal. Worse case scenario we amend this logic. Thanks for humoring me and for calling this out in the comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was a great call-out and future me is probably going to have the same question . I updated the docs to explain things a bit better.

Copy link
Copy Markdown
Contributor

@lougeniaC64 lougeniaC64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendk Sorry for the delayed response but LGTM, @skhamis thanks for the review!

@bendk bendk force-pushed the push-urmzomqpyvuq branch from c41e0f4 to 83a8955 Compare January 8, 2026 15:59
@bendk bendk added this pull request to the merge queue Jan 8, 2026
Merged via the queue into mozilla:main with commit 93a0548 Jan 8, 2026
13 checks passed
@bendk bendk deleted the push-urmzomqpyvuq branch January 8, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants