Skip to content

feat(indexworker): add max users threshold for rollout#2374

Merged
fadymak merged 2 commits intomasterfrom
fm/index-worker-threshold-config
Feb 16, 2026
Merged

feat(indexworker): add max users threshold for rollout#2374
fadymak merged 2 commits intomasterfrom
fm/index-worker-threshold-config

Conversation

@fadymak
Copy link
Contributor

@fadymak fadymak commented Feb 12, 2026

Adds max users threshold config value to allow for a managed rollout.

┌──────────────────────────────┬───────────────────┬──────────────────────────────────────────────────────────────┐
│ EnsureUserSearchIndexesExist │ MaxUsersThreshold │                           Behavior                           │
├──────────────────────────────┼───────────────────┼──────────────────────────────────────────────────────────────┤
│ false                        │ 0                 │ Default — nothing happens                                    │
├──────────────────────────────┼───────────────────┼──────────────────────────────────────────────────────────────┤
│ true                         │ 0                 │ User opt-in — always creates indexes                         │
├──────────────────────────────┼───────────────────┼──────────────────────────────────────────────────────────────┤
│ true                         │ >0                │ User opt-in — always creates indexes (threshold ignored)     │
├──────────────────────────────┼───────────────────┼──────────────────────────────────────────────────────────────┤
│ false                        │ >0                │ Progressive rollout — creates only if user count ≤ threshold │
└──────────────────────────────┴───────────────────┴──────────────────────────────────────────────────────────────┘

@fadymak fadymak requested a review from a team as a code owner February 12, 2026 17:10
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Introduced configurable user count threshold for user search indexes, enabling conditional index creation based on instance size with an option for forced index creation regardless of threshold.

Walkthrough

Added a numeric gating mechanism for creating user-search indexes. A new configuration field MaxUsersThreshold (exposed via GOTRUE_INDEX_WORKER_MAX_USERS_THRESHOLD) was added to IndexWorkerConfiguration. The API worker now considers this threshold when deciding to invoke index creation. The index worker queries an approximate user count when the threshold is active and, if the count exceeds the threshold and the boolean opt-in EnsureUserSearchIndexesExist is false, it skips index creation and logs an index_creation_skipped event; otherwise it proceeds with index creation. Tests exercising these cases were added.

Sequence Diagram(s)

sequenceDiagram
    participant API as APIWorker
    participant IW as IndexWorker
    participant DB as Database
    participant Log as Logger

    API->>IW: maybeCreateIndexes(ctx)
    IW->>IW: check cfg.IndexWorker.EnsureUserSearchIndexesExist\nand cfg.IndexWorker.MaxUsersThreshold
    alt EnsureUserSearchIndexesExist == true
        IW->>Log: log "index_creation_starting" (opt-in)
        IW->>DB: acquire advisory lock / create indexes
        DB-->>IW: index creation result
        IW->>Log: log result or error
    else MaxUsersThreshold > 0 and EnsureUserSearchIndexesExist == false
        IW->>DB: query approximate users count
        DB-->>IW: returns userCount
        alt userCount > MaxUsersThreshold
            IW->>Log: log "index_creation_skipped" with userCount and threshold
        else
            IW->>Log: log "index_creation_starting" with userCount
            IW->>DB: acquire advisory lock / create indexes
            DB-->>IW: index creation result
            IW->>Log: log result or error
        end
    else
        IW->>Log: log "index_creation_starting"
        IW->>DB: acquire advisory lock / create indexes
        DB-->>IW: index creation result
        IW->>Log: log result or error
    end
Loading
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a max users threshold configuration to the index worker for managing rollout of index creation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cstockton cstockton left a comment

Choose a reason for hiding this comment

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

Is it possible to remove the default of 0 to mean any, and instead make "any" be something like math.MaxInt64? My main concern being if something sets enabled to true expecting an accompanying threshold to be set, but it doesn't and the default of 0 means any.

Approving ahead of time to keep you unblocked.

@fadymak fadymak force-pushed the fm/index-worker-threshold-config branch from 93c7263 to 00cb768 Compare February 16, 2026 16:47
@fadymak
Copy link
Contributor Author

fadymak commented Feb 16, 2026

Thanks @cstockton — I agree, I've decided to simplify the config and make the 2 configuration variables independent of one another:

  1. ensure_user_search_indexes_exist: signifies explicit user opt-in (always creates indexes if true)
  2. max_users_threshold: configurable threshold to set an upper bound for # of users (0 = disabled, will only run if number of users < threshold)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 22075075135

Details

  • 15 of 18 (83.33%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 69.034%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/apiworker/apiworker.go 0 1 0.0%
internal/indexworker/indexworker.go 15 17 88.24%
Totals Coverage Status
Change from base Build 22072312968: 0.01%
Covered Lines: 14941
Relevant Lines: 21643

💛 - Coveralls

@fadymak fadymak merged commit a2066c6 into master Feb 16, 2026
5 checks passed
@fadymak fadymak deleted the fm/index-worker-threshold-config branch February 16, 2026 19:47
cstockton pushed a commit that referenced this pull request Feb 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.187.0](v2.186.0...v2.187.0)
(2026-02-23)


### Features

* add metadata field to all hooks
([#2365](#2365))
([c675749](c675749))
* check current password on change
([#2364](#2364))
([33b87ae](33b87ae))
* **indexworker:** add max users threshold for rollout
([#2374](#2374))
([a2066c6](a2066c6))
* **metrics:** added a gauge with version information
([#2375](#2375))
([911ad0b](911ad0b))
* support custom oauth & oidc providers
([#2357](#2357))
([53021f6](53021f6))


### Bug Fixes

* case-insensitive Bearer token scheme matching
([#2387](#2387))
([36d712d](36d712d))
* correctly parse JWT ValidMethods from env by enabling split_words
([#2334](#2334))
([a6076bc](a6076bc))
* flaky index worker test
([#2366](#2366))
([961a7e6](961a7e6))
* **hooks:** propagate error objects from hook calls
([#2380](#2380))
([3ca1e88](3ca1e88))
* session upgrade percentage should be based on session, not request
([#2371](#2371))
([510e68b](510e68b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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