Page MenuHomePhabricator

[GrowthBook Integration] Implement adapter for GrowthBook experiment configurations
Closed, ResolvedPublic5 Estimated Story Points

Description

Description

Transform validated GrowthBook experiments into the format required by the Test Kitchen API for MediaWiki and Varnish.

This includes normalizing fields such as variants, sampling configuration, stream name, and contextual attributes to match the expected contract.

Technical Notes

Relevant files:

  • util/experimentUtil.js
  • service/experimentService.js

New files:

  • service/adapters/growthBookToCanonicalAdapter.js
  • service/adapters/mediaWikiExperimentAdapter.js
  • service/adapters/varnishExperimentAdapter.js

util/experimentUtil.js already contains output-shaping logic:

  • formatVarnish
  • formatMediaWiki
  • formatAnalytics
  • formatBase

This is our current adapter logic. This task is about introducing an earlier adapter that maps GrowthBook to a canonical model, and possibly later splitting consumer adapters out too.

Acceptance Criteria

  • GrowthBook experiment payloads are transformed into the canonical experiment model.
    • Schema is fetched from the customFields.schema field of the response
    • Contextual attributes is fetched from the customFields.contextual_attributes field of the response
  • Required Test Kitchen fields are populated or derived consistently.
  • Adaptation failures are surfaced as structured errors or validation failures.
  • Unit tests cover the GrowthBook-to-canonical transformation.
  • Existing API formatting logic doesn't need to know about raw GrowthBook payload structure.

Event Timeline

What does it mean for an experiment in GrowthBook to define contextual attributes? Exposure events now have the contextual attributes we need.

@mpopov Do GB experiments have contextual attributes, in the same way that experiments in TK UI do? Same with stream name. Or are we doing away with those conceptual models?

@mpopov pointed out that stream and contextual attributes are modelled as custom fields in GrowthBook and has confirmed that GrowthBook custom fields are returned as part the API response. See the response sample here.

Do GB experiments have contextual attributes, in the same way that experiments in TK UI do? Same with stream name. Or are we doing away with those conceptual models?

They could be modelled as custom fields in GB, but I don't know that they should be at all. I guess maybe for some time, to ease the transition?

Like, the plan is for folks to eventually stop setting contextual attributes for the whole data collection activity, but that's a pretty big conceptual model shift and I don't think we're there yet.

What will get us there? How will we know when we've arrived? Is it only once we have all metrics defined (in eg the standard suite), or is it something else? That will help me determine the value of this intermediate step and how the data model will need to look.

KReid-WMF moved this task from Incoming to READY TO GROOM on the Test Kitchen board.

sfaci merged https://gitlab.wikimedia.org/repos/data-engineering/test-kitchen/-/merge_requests/329

Implement GrowthBook validator, adapter, and reconstructed experiment API endpoints

Change #1295092 had a related patch set uploaded (by Santiago Faci; author: Santiago Faci):

[operations/deployment-charts@master] test-kitchen: Update chart to add a new config property

https://gerrit.wikimedia.org/r/1295092

Change #1295094 had a related patch set uploaded (by Santiago Faci; author: Santiago Faci):

[operations/deployment-charts@master] Test Kitchen UI: Deploy v1.3.8 release to staging

https://gerrit.wikimedia.org/r/1295094

Change #1295092 merged by jenkins-bot:

[operations/deployment-charts@master] test-kitchen: Update chart to add a new config property

https://gerrit.wikimedia.org/r/1295092

Change #1295094 merged by jenkins-bot:

[operations/deployment-charts@master] Test Kitchen UI: Deploy v1.3.8 release to staging

https://gerrit.wikimedia.org/r/1295094

Added GrowthBook canonical adapter layer:

  • service/growthBookExperimentAdapter.js - adaptExperiment transforms a validated GrowthBook experiment into a canonical Experiment instance:
    • maps variations/trafficSplit + coverage into traffic_split ({groups: weights, wikis: per-wiki rates})
    • derives user_identifier_type from hashAttribute
    • normalizes dates to the deployment window,
    • pulls event_stream, schema_id, and contextual_attributes out of customFields
    • adaptAllExperiments maps over the validated set.
  • Supporting utils
    • util/growthBookUtil.js builds savedGroupsById
    • util/targetingConditionParser.js parses the wiki list from phase targeting conditions
  • Validation/adaptation split
    • only experiments that pass validateAllExperiments reach the adapter
    • adaptation failures surface as structured validation errors upstream rather than thrown mid-transform.
  • Decoupling
    • the consumer-facing API formatters (service/apiAdapters/: Varnish, Analytics, default) read from the canonical experiments_cache rows, never the raw GrowthBook payload
  • Unit tests in test/unit/growthBookExperimentAdapter.test.js cover the transformation.

Also updated the experiments endpoints per output of adapters:

  • Experiments endpoints no longer assemble config from raw DB queries:
    • The getExperiments function (controller/experimentController.js) delegates entirely to getFormattedExperiments
    • The base and Varnish formats read pre-stitched rows from experiments_cache via fetchExperimentsFromCache
    • Only Analytics still queries instruments via findExperimentsForAnalytics - it serves TK-registered experiments only
  • Experiments controller is leaner and delegates to a service:
    • The flow goes from validateParameters(req.query) to await getFormattedExperiments(format, authority) to res.send(data) and includes error mapping
    • All format/source routing lives in service/consumerFormatters.js which dispatches through getAdapter(authority) to the dedicated adapters in service/apiAdapters/
  • Experiments API responses function as before with some changes:
    • Varnish, Analytics, and the base (/api/v1/experiments) formats all work
    • MediaWiki format was removed (replaced by base format)
    • The cache-backed responses also return the stitched TK + GrowthBook experiments
  • Integration tests updated:
    • The /api/v1/experiments integration tests seed experiments_cache directly and assert the base and Varnish responses
    • Route behavior is covered without depending on the live GrowthBook poller

Change #1296660 had a related patch set uploaded (by Santiago Faci; author: Santiago Faci):

[operations/deployment-charts@master] Test Kitchen UI: Deploy v1.3.9 release to production

https://gerrit.wikimedia.org/r/1296660

Change #1296660 merged by jenkins-bot:

[operations/deployment-charts@master] Test Kitchen UI: Deploy v1.3.9 release to production

https://gerrit.wikimedia.org/r/1296660