0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-12 05:37:26 +08:00
discourse/app/services/problem_check
Régis Hanol 36a8a51ef0
FEATURE: Route all GitHub API requests through one rate-limited client (#40637)
GitHub oneboxes and the discourse-github plugin talked to GitHub's REST
and
GraphQL API with no rate-limit awareness. On busy instances this
exhausted
GitHub's limits (60 requests/hour unauthenticated, 5000 authenticated),
and
because there was no backoff every render kept hitting GitHub and
re-failing
-- which GitHub's docs warn can get an integration banned. The recently
added PR-status onebox multiplied the number of calls and made it far
worse.

GitHub access was also fragmented: the core onebox engines used OpenURI,
the
discourse-github plugin used Octokit, and the discourse-ai bot tools
used
FinalDestination::HTTP -- three HTTP stacks, three tokens, and
inconsistent
(or entirely missing) error and rate-limit handling.

This introduces a single client, Discourse::GithubApi, that every GitHub
data-API request now flows through. It is built on Faraday with the
SSRF-safe
FinalDestination adapter and:

- authenticates per token (Bearer) and returns plain string-keyed Hashes
(get/post) or raw bodies (raw_get) -- one response shape, no
Octokit/Sawyer
- only ever sends the access token to api.github.com and
  raw.githubusercontent.com, rejecting any other absolute URL, so a
  user-derived path can never leak a token to an arbitrary host
- backs off on rate limits both reactively (403/429) and proactively
(when
X-RateLimit-Remaining hits 0), honouring Retry-After /
X-RateLimit-Reset,
via a shared Redis flag (GithubRateLimit) keyed per token so each
token's
  budget and the shared unauthenticated/IP budget back off independently
- short-circuits while backing off without ever sleeping, so onebox
rendering
  and post baking degrade to a plain link instead of blocking a request
- caches ETags and sends If-None-Match, so unchanged resources return
304s
  that do not count against the rate limit

Every caller was moved onto it:

- the 6 core GitHub onebox engines, via a slimmed
Onebox::Mixins::GithubApi
adapter that keeps their public methods and translates client errors
back
to the OpenURI::HTTPError vocabulary they already rescue (engines
unchanged)
- the github_blob raw.githubusercontent.com fetch
- the discourse-github plugin (badges, linkback, permalinks, token
validator),
which no longer uses the octokit and sawyer gems (they stay in the
Gemfile for
the discourse-code-review official plugin, which still depends on them)
- the discourse-ai bot's GitHub tools (search code, diff, file content,
  search files)

Also adds a GithubOneboxBackoff admin problem check that surfaces while
one of
the onebox token identities is backing off -- scoped to the tokens
resolved by
Onebox::GithubAccess (each configured github_onebox_access_tokens entry
plus the
unauthenticated client) so a backoff on the AI bot or linkback token is
not
misattributed to onebox. Its message points admins at the relevant
setting with
the {{setting:...}} link marker, which problem-check messages now expand
too.
Onebox token resolution is centralised in Onebox::GithubAccess, and the
onebox
cache TTL for transient GitHub failures is shortened so they recover
quickly.

GitHub OAuth login, theme git-clone, the inbound webhook, and the
Oneboxer
FinalDestination URL-resolution special-cases for github.com are
intentionally
out of scope -- they are different concerns, not the rate-limited data
API.
2026-06-15 10:59:10 +02:00
..
bad_favicon_url.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
content_security_policy_disabled.rb FEATURE: Warn admins when Content Security Policy is disabled (#40791) 2026-06-11 11:34:37 +01:00
email_polling_errored_recently.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
email_sending_failures.rb FEATURE: Add PM whisper feedback for email sending failures (#40250) 2026-05-22 17:17:15 -03:00
facebook_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
failing_emails.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
force_https.rb FIX: Fix scheduled targeted problem checks (#35696) 2025-11-10 10:09:14 +08:00
github_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
github_onebox_backoff.rb FEATURE: Route all GitHub API requests through one rate-limited client (#40637) 2026-06-15 10:59:10 +02:00
google_analytics_version.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
google_oauth2_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
group_email_credentials.rb DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
host_names.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
image_magick.rb DEV: replace imagemagick convert commands with magick (#27767) 2024-07-08 16:55:59 +08:00
inline_problem_check.rb FIX: Don't clear inline problems when loading admin dashboard (#28220) 2024-08-05 11:45:55 +08:00
maxmind_db_configuration.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
missing_mailgun_api_key.rb Revert "DEV: Replace MissingMailgunApiKey check with comprehensive Em… (#38038) 2026-02-24 19:38:30 +00:00
out_of_date_themes.rb FIX: Fix broken out of date themes admin notice (#27916) 2024-07-15 16:12:44 +08:00
poll_pop3_auth_error.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
poll_pop3_timeout.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
problem.rb DEV: Support target in problem check problem constructor (#31922) 2025-03-24 10:10:41 +08:00
qq_mail_smtp.rb FEATURE: Warn admins when QQ Mail SMTP is configured 2026-01-30 16:39:24 +00:00
rails_env.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
ram.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
s3_backup_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
s3_cdn.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
s3_upload_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
sidekiq_check.rb I18n: Fix reference to sidekiq_check string (#40416) 2026-06-01 11:16:10 -04:00
starttls_disabled.rb FIX: actually disable SMTP starttls if the user is attempting to disable it 2025-11-04 23:42:14 -05:00
subfolder_ends_in_slash.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
translation_overrides.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
twitter_config.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
twitter_login.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00
unreachable_themes.rb FIX: Fix broken out of date themes admin notice (#27916) 2024-07-15 16:12:44 +08:00
upcoming_change_stable_opted_out.rb DEV: Remove enable_upcoming_changes global setting gate (#38360) 2026-03-10 10:08:20 +10:00
watched_words.rb DEV: Database backed admin notices (#26192) 2024-05-23 09:29:08 +08:00