Skip to content

Conversation

leoromanovsky
Copy link
Member

@leoromanovsky leoromanovsky commented Nov 16, 2024

Motivation

Eppo is launching a server-based assignment service hosted on the Fastly Compute platform. This is an edge-product that makes

Design details available in the internal doc.

PR goals

  • Create a service that is able to respond to POST /assignments with a subjectKey and subjectAttributes and return assignments for active allocations.

PR non-goals

This work does not include integration testing or CICD integration beyond compilation. This functionality will be added before a 1.0.0 release in the coming weeks.

Description

  • Service responds to requests on GET /health and POST /assignments?apiKey - the apiKey format is re-used for legacy reasons although the marketing copy is SDK Key.
  • The incoming apiKey is converted to a hash and used to look up items in the attached KV store. An external process populates the KV store on Flag changes.
  • The handler performs assignment across all available flags in series and returns the ones with success evaluation. Any errors in evaluation are logged and the flags are not included in the response.

@leoromanovsky leoromanovsky marked this pull request as ready for review November 21, 2024 00:29

# Build only the `fastly-edge-assignments` package for WASM
.PHONY: fastly-edge-assignments-build
fastly-edge-assignments-build:
Copy link
Member Author

Choose a reason for hiding this comment

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

Are these changes helpful? I got tired of putting the various parameters in the right place.

[local_server.kv_stores]
[[local_server.kv_stores.edge-assignment-kv-store]]
key = "ufc-by-sdk-key-token-hash-V--77TScV5Etm78nIMTSOdiroOh1__NsupwUwsetEVM"
file = "../sdk-test-data/ufc/flags-v1.json"
Copy link
Member Author

Choose a reason for hiding this comment

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

this instructs the fastly serve process to populate the local in-memory KV store with one key, a UFC configuration at a precomputed hash. See the unit test in this repo for the associate SDK key to use.

allocation_key: String,
variation_key: String,
variation_type: String,
variation_value: serde_json::Value,
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: inside core we have ValueWire that represents this better

}

const KV_STORE_NAME: &str = "edge-assignment-kv-store";
const SDK_KEY_QUERY_PARAM: &str = "apiKey"; // For legacy reasons this is named `apiKey`
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: given this is a completely new service, I think we can go with sdkKey as there are no legacy clients?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to do this as well - @sameerank used our existing javascript client to access this service to setup a connection for our eppo.cloud QA environment so we can start collect telemetry on real-world use. Eppo-exp/js-sdk-common#137

I have a couple of goals to evolve the network architecture of this service:

  • Serve it behind our existing CDN (with no caching) to be able to share the same domain name and SSL certificate
  • Since Sameeran developed the new client separately from the old we have a lot of control over the query parameters and should make this change; or even better, pass the auth information in a Authorization header.

base64_url::encode(&hasher.finalize())
}

pub fn handle_assignments(mut req: Request) -> Result<Response, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: this function has potential to be split into multiple helper functions, which is currently hindered by the fact that error responses are constructed inline. If we have an explicit error type, that would make splitting much easier and the main body more pleasant and straightforward

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I see what you mean - ideally we return explicit errors and this handle just is responsible to rendering those into various http codes and messages?


impl FlagAssignment {
pub fn try_from_assignment(assignment: Assignment) -> Option<Self> {
// WARNING! There is a problem here. The event is only populated for splits
Copy link
Member Author

Choose a reason for hiding this comment

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

@rasendubi @sameerank I believe this is a problem as described here: https://github.com/Eppo-exp/eppo-multiplatform/blob/main/eppo_core/src/ufc/compiled_flag_config.rs#L231

During compilation, an optimization step to reduce the configuration, event is only populated for splits with do_log == True.

A possible solution is to produce a configuration that is "not optimized" for use in this function so that we can access do_log

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another option is to make fields from event optional. There's no reason to include keys and extra logging if doLog is false.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think its a problem because we want the precomputed server to return evaluations for all flags and do_log is true or false depending on if the user wants them log, but they still need to be present. The flag will be present in the response which changes the behavior of the SDK / application instead of now the flag will not be present and the default value will be used. Am I understanding that correctly?

pub(crate) struct UniversalFlagConfigWire {
/// When configuration was last updated.
pub created_at: Timestamp,
pub format: AssignmentFormat,
Copy link
Member Author

Choose a reason for hiding this comment

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

heads up @sameerank I added a new key to UFC parsing. I see it is being returned now always so I feel it is safe to make it required.

base64_url::encode(&hasher.finalize())
}

pub fn handle_assignments(mut req: Request) -> Result<Response, Error> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I see what you mean - ideally we return explicit errors and this handle just is responsible to rendering those into various http codes and messages?

@leoromanovsky
Copy link
Member Author

leoromanovsky commented Nov 23, 2024

@sameerank I'm going to merge this PR even though we still have some feedback from Oleksii and improvements I pointed out in the comments, to have a milestone to match your JS SDK release; the do_log issue is most pressing to figure out.

@leoromanovsky leoromanovsky merged commit 760d58d into main Nov 23, 2024
25 checks passed
@leoromanovsky leoromanovsky deleted the lr/ff-3552/edge-function branch November 23, 2024 04:37
Comment on lines +50 to +55
extra_logging: event
.base
.extra_logging
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as:

extra_logging: event.base.extra_logging.clone(),

}

impl FlagAssignment {
pub fn try_from_assignment(assignment: Assignment) -> Option<Self> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: prefer implementing From and TryFrom traits

Comment on lines +127 to +146
let subject_assignments = flag_keys
.iter()
.filter_map(|key| {
match evaluator.get_assignment(key, &subject_key, &subject_attributes, None) {
Ok(Some(assignment)) => FlagAssignment::try_from_assignment(assignment)
.map(|flag_assignment| (key.clone(), flag_assignment)),
Ok(None) => None,
Err(e) => {
eprintln!("Failed to evaluate assignment for key {}: {:?}", key, e);
None
}
}
})
.collect::<HashMap<_, _>>();

// Create the response
let assignments_response = PrecomputedAssignmentsServiceResponse::from_configuration(
configuration,
subject_assignments,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

major: computing subject assignments should be part of core. super-weird to have request/response formats in the core but the way to calculate assignment not in the core

Comment on lines +7 to +9
// Request
#[derive(Debug, Deserialize)]
pub struct PrecomputedAssignmentsServiceRequestBody {
Copy link
Collaborator

Choose a reason for hiding this comment

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

major: eppo_core shall be unconcerned with network request format

pub(crate) struct UniversalFlagConfigWire {
/// When configuration was last updated.
pub created_at: Timestamp,
pub format: AssignmentFormat,
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: ideally, this field should be optional because there could exist configurations without it (remember that users may be storing and passing configurations out of band now)

Copy link
Member Author

Choose a reason for hiding this comment

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

#76

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.

3 participants