Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(indexer): probabilistic feature flag #136

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/middleware/withLocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import { Client } from '@storacha/indexing-service-client'
*/
export function withLocator (handler) {
return async (request, env, ctx) => {
const useIndexingService = new URL(request.url).searchParams
.getAll('ff')
.includes('indexing-service')
const useIndexingService = isIndexingServiceEnabled(request, env)

const locator = useIndexingService
? new IndexingServiceLocator({
Expand All @@ -46,3 +44,22 @@ export function withLocator (handler) {
return handler(request, env, { ...ctx, locator })
}
}

/**
* Determines if the indexing service is enabled. It is enabled if the request
* contains the `ff=indexing-service` query parameter or if a random chance
* falls within the ramp-up probability. If `FF_RAMP_UP_PROBABILITY` is not set,
* it defaults to 0%.
*
* @param {Request} request
* @param {LocatorEnvironment} env
* @returns {boolean}
*/
function isIndexingServiceEnabled (request, env) {
const withIndexingServicesArg = new URL(request.url).searchParams
.getAll('ff')
.includes('indexing-service')
const probability = env.FF_RAMP_UP_PROBABILITY ? Number(env.FF_RAMP_UP_PROBABILITY) : 0
const withIndexerEnabled = Math.random() * 100 <= probability
return withIndexingServicesArg || withIndexerEnabled
}
1 change: 1 addition & 0 deletions src/middleware/withLocator.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface LocatorEnvironment extends MiddlewareEnvironment {
CARPARK: R2Bucket
CARPARK_PUBLIC_BUCKET_URL?: string
INDEXING_SERVICE_URL?: string
FF_RAMP_UP_PROBABILITY?: string
}

export interface LocatorContext extends MiddlewareContext {
Expand Down
4 changes: 4 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ MAX_SHARDS = "825"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "false"
FF_TELEMETRY_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "10"
GATEWAY_SERVICE_DID = "did:web:w3s.link"
UPLOAD_SERVICE_DID = "did:web:web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://claims.web3.storage"
Expand Down Expand Up @@ -80,6 +81,7 @@ FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
FF_DELEGATIONS_STORAGE_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "100"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
Expand All @@ -100,6 +102,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "false"
FF_TELEMETRY_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "100"
MAX_SHARDS = "120"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
Expand Down Expand Up @@ -145,6 +148,7 @@ FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
FF_DELEGATIONS_STORAGE_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "100"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
Expand Down
Loading