Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a813273
feat: fastly compute service to perform assignments (FF-3552)
leoromanovsky Nov 16, 2024
e985863
convert from reqwest blocking to non-blocking to conform to wasm target
leoromanovsky Nov 5, 2024
c8717ee
remove vscode settings
leoromanovsky Nov 16, 2024
5956e65
makefile for local development
leoromanovsky Nov 16, 2024
a3f37c7
split into multiple handlers
leoromanovsky Nov 17, 2024
48d47aa
its a thing of beauty
leoromanovsky Nov 17, 2024
56e5c96
coming along nicely
leoromanovsky Nov 17, 2024
3a4b644
good
leoromanovsky Nov 17, 2024
59cb251
local test kv-store!
leoromanovsky Nov 17, 2024
a159065
feat: add `get_subject_assignments` method to eppo_core to compute al…
leoromanovsky Nov 17, 2024
6e704ef
simplify unnecessary ownership transfer
leoromanovsky Nov 17, 2024
bccce04
e2e evaluation
leoromanovsky Nov 17, 2024
c338d31
remove space end of filename
leoromanovsky Nov 18, 2024
ff73c47
Revert "feat: add `get_subject_assignments` method to eppo_core to co…
leoromanovsky Nov 18, 2024
48d2ebc
tidy up error logging
leoromanovsky Nov 18, 2024
3b55f6d
Merge branch 'main' into lr/ff-3552/edge-function
leoromanovsky Nov 20, 2024
3219a03
edge function dep on 4.1.1
leoromanovsky Nov 20, 2024
d288696
generate token hash
leoromanovsky Nov 20, 2024
be2d5ac
fastly local
leoromanovsky Nov 20, 2024
9f99865
conform to desired API
leoromanovsky Nov 21, 2024
78fe3b5
add CORS support
leoromanovsky Nov 22, 2024
f156caa
Merge branch 'main' into lr/ff-3552/edge-function
leoromanovsky Nov 22, 2024
f2f27af
version from cargo
leoromanovsky Nov 23, 2024
f1bcf3d
use Datetime
leoromanovsky Nov 23, 2024
4ada237
String
leoromanovsky Nov 23, 2024
8101988
no copy
leoromanovsky Nov 23, 2024
50ed0ec
use VariationType
leoromanovsky Nov 23, 2024
38f71eb
move structs to core
leoromanovsky Nov 23, 2024
266de8a
extra logging
leoromanovsky Nov 23, 2024
c3c90f8
refactor FlagAssignment to model
leoromanovsky Nov 23, 2024
b9ca60a
use Str
leoromanovsky Nov 23, 2024
26300db
build responses in core
leoromanovsky Nov 23, 2024
26c4466
tidy
leoromanovsky Nov 23, 2024
7b4eb91
add format
leoromanovsky Nov 23, 2024
95219d4
str
leoromanovsky Nov 23, 2024
81d1f55
format
leoromanovsky Nov 23, 2024
9622a21
one more format
leoromanovsky Nov 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
submodules: true
- run: npm ci
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose --all-targets
- run: cargo test --verbose
# Add WASM target
- run: rustup target add wasm32-wasi
# Build non-WASM targets
- run: cargo build --verbose --all-targets --workspace --exclude fastly-edge-assignments
# Build WASM target separately
- run: cargo build --verbose -p fastly-edge-assignments --target wasm32-wasi
# Run tests (excluding WASM package)
- run: cargo test --verbose --workspace --exclude fastly-edge-assignments
- run: cargo doc --verbose
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[workspace]
resolver = "2"
members = [
"eppo_core",
"rust-sdk",
"python-sdk",
"ruby-sdk/ext/eppo_client",
"eppo_core",
"rust-sdk",
"python-sdk",
"ruby-sdk/ext/eppo_client",
"fastly-edge-assignments",
]

[patch.crates-io]
Expand Down
49 changes: 34 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
# Make settings - @see https://tech.davis-hansson.com/p/make/
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

# Log levels
DEBUG := $(shell printf "\e[2D\e[35m")
INFO := $(shell printf "\e[2D\e[36m🔵 ")
OK := $(shell printf "\e[2D\e[32m🟢 ")
WARN := $(shell printf "\e[2D\e[33m🟡 ")
ERROR := $(shell printf "\e[2D\e[31m🔴 ")
END := $(shell printf "\e[0m")
WASM_TARGET=wasm32-wasi
FASTLY_PACKAGE=fastly-edge-assignments
BUILD_DIR=target/$(WASM_TARGET)/release
WASM_FILE=$(BUILD_DIR)/$(FASTLY_PACKAGE).wasm

.PHONY: default
default: help

## help - Print help message.
# Help target for easy documentation
.PHONY: help
help: Makefile
@echo "usage: make <target>"
@sed -n 's/^##//p' $<
help:
@echo "Available targets:"
@echo " all - Default target (build workspace)"
@echo " workspace-build - Build the entire workspace excluding the Fastly package"
@echo " workspace-test - Test the entire workspace excluding the Fastly package"
@echo " fastly-edge-assignments-build - Build only the Fastly package for WASM"
@echo " fastly-edge-assignments-test - Test only the Fastly package"
@echo " clean - Clean all build artifacts"

.PHONY: test
test: ${testDataDir}
npm test

# Build the entire workspace excluding the `fastly-edge-assignments` package
.PHONY: workspace-build
workspace-build:
cargo build --workspace --exclude $(FASTLY_PACKAGE)

# Run tests for the entire workspace excluding the `fastly-edge-assignments` package
.PHONY: workspace-test
workspace-test:
cargo test --workspace --exclude $(FASTLY_PACKAGE)

# 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.

rustup target add $(WASM_TARGET)
cargo build --release --target $(WASM_TARGET) --package $(FASTLY_PACKAGE)

# Test only the `fastly-edge-assignments` package
.PHONY: fastly-edge-assignments-test
fastly-edge-assignments-test:
cargo test --target $(WASM_TARGET) --package $(FASTLY_PACKAGE)
45 changes: 45 additions & 0 deletions eppo_core/src/ufc/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,51 @@ impl AssignmentValue {
_ => None,
}
}

/// Returns the type of the variation as a string.
///
/// # Returns
/// - A string representing the type of the variation ("STRING", "INTEGER", "NUMERIC", "BOOLEAN", or "JSON").
///
/// # Examples
/// ```
/// # use eppo_core::ufc::AssignmentValue;
/// let value = AssignmentValue::String("example".into());
/// assert_eq!(value.variation_type(), "STRING");
/// ```
pub fn variation_type(&self) -> &'static str {
match self {
AssignmentValue::String(_) => "STRING",
AssignmentValue::Integer(_) => "INTEGER",
AssignmentValue::Numeric(_) => "NUMERIC",
AssignmentValue::Boolean(_) => "BOOLEAN",
AssignmentValue::Json(_) => "JSON",
}
}

/// Returns the raw value of the variation.
///
/// # Returns
/// - A JSON Value containing the variation value.
///
/// # Examples
/// ```
/// # use eppo_core::ufc::AssignmentValue;
/// # use serde_json::json;
/// let value = AssignmentValue::String("example".into());
/// assert_eq!(value.variation_value(), json!("example"));
/// ```
pub fn variation_value(&self) -> serde_json::Value {
match self {
AssignmentValue::String(s) => serde_json::Value::String(s.to_string()),
AssignmentValue::Integer(i) => serde_json::Value::Number((*i).into()),
AssignmentValue::Numeric(n) => serde_json::Value::Number(
serde_json::Number::from_f64(*n).unwrap_or_else(|| serde_json::Number::from(0)),
),
AssignmentValue::Boolean(b) => serde_json::Value::Bool(*b),
AssignmentValue::Json(j) => j.as_ref().clone(),
}
}
}

#[cfg(feature = "pyo3")]
Expand Down
2 changes: 2 additions & 0 deletions fastly-edge-assignments/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasi"
2 changes: 2 additions & 0 deletions fastly-edge-assignments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pkg/
bin/
16 changes: 16 additions & 0 deletions fastly-edge-assignments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "fastly-edge-assignments"
version = "0.1.0"
edition = "2021"
# Remove this line if you want to be able to publish this crate as open source on crates.io.
# Otherwise, `publish = false` prevents an accidental `cargo publish` from revealing private source.
publish = false

[dependencies]
base64-url = "2.0.0"
chrono = "0.4.19"
eppo_core = { version = "=4.1.1", path = "../eppo_core" }
fastly = "0.11.0"
serde_json = "1.0.132"
serde = "1.0.192"
sha2 = "0.10.0"
3 changes: 3 additions & 0 deletions fastly-edge-assignments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Eppo Assignments on Fastly Compute@Edge

TODO: Add a description
17 changes: 17 additions & 0 deletions fastly-edge-assignments/fastly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file describes a Fastly Compute package. To learn more visit:
# https://www.fastly.com/documentation/reference/compute/fastly-toml

authors = ["[email protected]"]
name = "Eppo Assignments on Fastly Compute@Edge"
description = "Edge compute service for pre-computed Eppo flag assignments"
language = "rust"
manifest_version = 3

[scripts]
build = "cargo build --bin fastly-edge-assignments --release --target wasm32-wasi --color always"

[local_server]
[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.

3 changes: 3 additions & 0 deletions fastly-edge-assignments/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
targets = [ "wasm32-wasi" ]
Loading
Loading