Skip to content

follow-ups (fxa-13811): #20695

Open
groovecoder wants to merge 4 commits into
mainfrom
fxa-13811
Open

follow-ups (fxa-13811): #20695
groovecoder wants to merge 4 commits into
mainfrom
fxa-13811

Conversation

@groovecoder

Copy link
Copy Markdown
Member

Because

This pull request

  • Adds optional StatsD param to RateLimitBqWriter; emits rate_limit.bq_writer.flush_error on insert failures.
  • Self-creates the rate_limit_checks BigQuery table on startup via ensureTable() with RATE_LIMIT_CHECK_SCHEMA. (Non-fatal if permissions don't allow creation.)

Issue that this pull request solves

Closes: FXA-13811

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

Other information (Optional)

  • Feature remains off by default (RATE_LIMIT__BIGQUERY__ENABLED=false).

… to writer

Because:
- Review feedback: flush errors were logged but not metricked, so
  alerting on BQ outages was not possible.

This commit:
- Adds optional StatsD param to RateLimitBqWriter constructor.
- Emits rate_limit.bq_writer.flush_error on insert failures.
- Passes statsd through from key_server.js and NestJS provider.
- Renames describe('bqWriter integration') to describe('bqWriter')
  since the writer is mocked.

Fixes FXA-13811
Because:
- The rate_limit_checks table must exist before inserts work, but
  BQ tables can't be created via the normal SQL migration path.
  Self-creation keeps the schema in code and avoids SRE tickets for
  every schema change.

This commit:
- Exports RATE_LIMIT_CHECK_SCHEMA matching RateLimitCheckEvent fields.
- Adds ensureTable() that checks existence and creates the table on
  first startup. Errors are caught — missing permissions degrade to
  the same insert-time failure as before.
- Waits for table readiness before first flush.
- Adds tests for table creation, skip-when-exists, and error handling.

Fixes FXA-13811
@groovecoder groovecoder requested a review from a team as a code owner June 4, 2026 20:43
Comment thread libs/accounts/rate-limit/src/lib/bq-writer.ts Outdated
try {
const [exists] = await this.tableRef.exists();
if (!exists) {
await this.tableRef.create({ schema: RATE_LIMIT_CHECK_SCHEMA });

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.

I'm not sure this will actually work. The credentials given to the service probably shouldn't have permissions to do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ensureTable catch block already handles this. I updated the comment to explicitly note the service account may lack bigquery.tables.create. If it does fail, Sentry captures the error and inserts proceed (they'll fail with a clear error if the table truly doesn't exist).

But should we have SRE pre-create the table and remove ensureTable entirely?

@dschom dschom Jun 10, 2026

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.

Yes. I think the better approach would be to just have SRE do this. We can still fail, and capture insert failures.

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.

2 participants