Eppo-exp / node-server-sdk

Eppo Node.js SDK
MIT License
9 stars 0 forks source link

Implement SDK polling, in-memory cache #4

Closed ploomiz closed 2 years ago

ploomiz commented 2 years ago

Fixes: #issue

Motivation and Context

The client SDK needs to know when an experiment's configuration changes. For example, if the experiment percent exposure changes from 100% to 0%, the SDK assign function will stop assigning variations and always return null.

Description

This PR implements polling of the RAC endpoint to retrieve the most up-to-date configurations (the design doc also considered a push-based approach instead of polling). Once the RAC is retrieved, the SDK stores it in a local in-memory cache:

"experiment1": => { ...config }
"experiment2": => { ...config }

How has this been tested?

Getting assignment Getting configurations from local cache Got assignment variation-1

Polling experiment configurations... Getting assignment Getting configurations from local cache Got assignment variation-1

Polling experiment configurations... Getting assignment Getting configurations from local cache Got assignment variation-1


- Verified query params are sent in the HTTP request:
  - `apiKey`: "test-api-key"
  - `sdkName`: "node-server-sdk"
  - `sdkVersion`: "1.0.0"

- The `assign function responds to RAC changes on the backend

Getting assignment Got assignment variation-1

Getting assignment Got assignment variation-1

------ CHANGE to ZERO PERCENT EXPOSURE ----

Getting assignment Got assignment null

Getting assignment Got assignment null



[//]: # (OPTIONAL)
[//]: # (Add one or multiple labels: enhancement, refactoring, bugfix)
ploomiz commented 2 years ago

@petzel Updated to address comments