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

PHP SDK Relay Server #62

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

PHP SDK Relay Server #62

wants to merge 38 commits into from

Conversation

typotter
Copy link
Collaborator

@typotter typotter commented Sep 10, 2024

Eppo Internal:
Notion

Related PRs

Motivation and Context

The SDK Package Testing Cluster is a reusable scaffold for testing each SDK (and a specific version thereof) in a production-like environment using a shared test runner and mock API server. For each deployment variation of each SDK, a "Relay Server" is built in a Docker image capable of running with a specific version of the SDK (by Git tag, branch, or commit). A test runner application dictates to the API server what UFC and Bandit model data to serve and POSTs the test cases to the relay server.

The SDK Relay Server for PHP (SRS4PHP) is a simple application which takes requests from HTTP Posts, passes them to the php SDK and returns the results (and logs) in an HTTP response.

Overview of Changes

  • PHP app (built with Slim framework)
  • build.sh to build the relay app with a specific version of the SDK
  • Dockerfile to make the relay app portable
  • release.sh to encode the proper Image tag

Outstanding work

  • Push images to Container/Artifact registry
  • GH workflow to build and push new docker images when the underlying relay server is updated (not required for SDK updates as the build.sh file injects the desired version of the SDK at container run time)

What is requested of the reviewers

  • guidance (and patience) on Eppo's best practices for Shiny New Things
  • A hard look at the documentation provided here in the repository with a look at how it will hold up in the long term and how well any new engineer can find what they need
  • Suggestions of additional features/requirements/extensions so that we can capture them for future pulls

@typotter typotter marked this pull request as ready for review September 11, 2024 18:43
@typotter typotter requested review from leoromanovsky, aarsilv and greghuels and removed request for leoromanovsky, aarsilv and greghuels September 11, 2024 20:52
@typotter typotter self-assigned this Sep 11, 2024
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat stuff!

### With Docker
#### Build Docker Image
```shell
docker build -t Eppo-exp/php-sdk-relay .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

$subjectAttributes = $payload['subjectAttributes'];

try {
if (isset(self::$methods[$variationType])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making this a guard clause to spatially locate the error being thrown with why

if (!isset(self::$methods[$variationType])) {
    throw new Exception("Invalid variation type $variationType");   
}

...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

*/
public function getAssignment(array $payload): array
{
$variationType = $payload['variationType'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be too late in the game to change this, but "variation type" is not a good descriptor for this. Variation Type already means the type of value variations hold (e.g., booleans, strings, integer, numeric JSON) and now were overloading it to also mean the type of assignment we are requesting (note: bandits return string variation types... for now!).

I think a better name for this would be assignment type.

Sorry I didn't think of this until now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Let's plumb it through the test cluster as assignmentType - it's not too late.
The presence of "variationType" is how the test runner decides between the /flags and the /bandits endpoints of the relay server (should probably use actions instead). I had considered specifying an endpoint per assignment type and leave this field out altogether, but it makes for a lot of duplicated code.

"banditLog" => array_map('json_encode', $this->logger->banditLogs)
);
} finally {
$this->logger->resetLogs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why $this-> here and nowhere else we reference $logger?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified the two loggers; one is for this application to log to the console and one is catching Eppo events for the handler to return.


$app = AppFactory::create();

$app->get('/', function (Request $request, Response $response, array $args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thinking! Could be useful for docker healthcheck too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants