Implement GrowthBook validator, adapter, and reconstructed experiment API endpoints
What?
- Extract GrowthBook-specific logic from
experimentConfigurationServiceinto:
-
validation/growthBookExperimentValidator.js- validates individual experiments and performs batch validation -
service/growthBookExperimentAdapter.js- transforms valid experiments into canonical Experiment instances -
util/growthBookUtil.js- buildssavedGroupsByIdfrom saved groups -
util/targetingConditionParser.js- parses wiki targeting from phase conditions -
util/experimentValidationRules.js- pure validation rules for GrowthBook experiments
- Validation covers:
- trackingKey/owner presence
- slug uniqueness against TK and GB experiments
- deployment-day dates (Mon–Fri)
- wiki count (1–100) with canonical ID checks
- variation and group allocation checks
- stream name validation
- TK experiments with
risk_levelare excluded
- Invalid experiments are skipped with a structured warning rather than failing the poll cycle.
- Introduce service adapters and a consumer formatter that routes each consumer format to its dedicated adapter (Varnish, Analytics, default)
- Route consumer formats through a dispatcher (
service/consumerFormatters.js) to dedicated adapters inservice/apiAdapters/ - MediaWiki consumer format is removed — unused, and the base format serves the same shape.
- Simplify experiment service:
-
findAllExperimentsdoesn't hold formatting logic - only used by Analytics consumer format -
fetchExperimentsFromCachereturns combined experiments - used by Varnish and default consumer formats
- Varnish and default consumer formats read from
experiments_cachetable (combined TK-registered and GB-sourced experiments) - Analytics consumer format continues to read experiments from the
instrumentstable (TK-registered experiments only) - Fix experiments storage:
- Preserve rows on transient saved-groups failure
- Clean up rows when experiments end or are turned off.
-
traffic_splitpreserves per-wiki rates so multiplesample_rates are not overwritten - Disable
/api/v1/experimentsendpoints integration tests temporarily with TODO - updated test fixtures coming in a follow up MR.
Why?
The experimentConfigurationService.js file accumulated too much responsibility — validation, adaptation, data fetching, and persistence all in one place. This refactor separates concerns so each component has a single, well-defined purpose, making the code easier to test, reason about, and extend.
The validation work requires GrowthBook experiments to be validated before reaching the API with structured rejection reasons logged for diagnostics.
The experiments endpoints should serve experiment configurations produced by the backend service (including stitched results), rather than assembling responses directly from the database queries.
By introducing dedicated adapters and a consumer formatter, we can add different kinds of consumer formats more readily in the future.
Testing Instructions:
- In
config.local.yaml- set
run_pollertotrue - set the
api_urltohttps://growthbook-api-next.wikimedia.org/api/v1/experiments - set the
saved_groups_urltohttp://growthbook-api-next.wikimedia.org/api/v1/saved-groups - add your api key from staging in the
growthbookconfig block
- set
- Run
make run-devin local dev environment - Check the
experiments_cachetable in your local docker database to see both TK-originated and GB-originated experiments - you should seetest-experimentandsample-experimentas the GB-originated experiments in the table alongside TK experiments. - Check the experiments endpoints:
-
http://localhost/api/v1/experiments (note
sample-experimentandtest-experimentfrom GB) -
http://localhost/api/v1/experiments?format=config&authority=varnish (note
sample-experimentfrom GB) - http://localhost/api/v1/experiments?format=analytics (note only TK-registered experiments)
-
http://localhost/api/v1/experiments (note