Skip to content

Commit

Permalink
feat(indexer): probabilistic feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 17, 2024
1 parent 7a523d5 commit 1868f94
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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 percentage. If `FF_RAMP_UP_PERCENTAGE` is not set,
* it defaults to 10%.
*
* @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 percentage = env.FF_RAMP_UP_PERCENTAGE ? Number(env.FF_RAMP_UP_PERCENTAGE) : 0.1
const withIndexerEnabled = Math.random() <= percentage
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_PERCENTAGE?: 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_PERCENTAGE = "0.1"
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_PERCENTAGE = "1.0"
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_PERCENTAGE = "1.0"
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_PERCENTAGE = "1.0"
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

0 comments on commit 1868f94

Please sign in to comment.