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

feat: implement delta cache in edge #736

Merged
merged 15 commits into from
Feb 17, 2025
Merged

feat: implement delta cache in edge #736

merged 15 commits into from
Feb 17, 2025

Conversation

sjaanus
Copy link
Collaborator

@sjaanus sjaanus commented Feb 14, 2025

Edge needs to start keeping all the deltas in cache. This is a cache where these deltas are kept. Tried to keep it consistant with delta cache inside Unleash https://github.com/Unleash/unleash/blob/4a72580b2477c91883680fd03adc8e31ef85f48f/src/lib/features/client-feature-toggles/delta/delta-cache.ts#L7.

Copy link

github-actions bot commented Feb 14, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
cargo/unleash-types 0.15.8 UnknownUnknown
cargo/unleash-types >= 0.15.8, < 0.16.0 UnknownUnknown

Scanned Files

  • Cargo.lock
  • server/Cargo.toml

@chriswk
Copy link
Member

chriswk commented Feb 14, 2025

This is looking good, we're going to need to change the logic for how Edge returns ETags in order to bring the experience for SDKs inline with what they see from Unleash. That can be done in a separate PR though, so won't let that block this.

For ETags:

  • We had a PR open one year ago that we never merged. Might be time to look at it again.
  • Currently Edge still hashes the content it returns to return an ETag.
  • Probably we can reuse the etag we get from upstream, and not have to do the hashing for at least delta and features endpoints.
  • For frontend, it still makes sense to do the hash.

Copy link
Member

@chriswk chriswk left a comment

Choose a reason for hiding this comment

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

Looks good (and rusty) to me.
Happy to spar next week on making sure the ETag treatment gets updated to be closer to what Unleash does.

}

fn add_base_event_from_hydration(&mut self, hydration_event: DeltaHydrationEvent) {
if let Some(last_feature) = hydration_event.features.last().cloned() {
Copy link
Member

Choose a reason for hiding this comment

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

This if let Some makes it looks like you always expect there to be a last feature and that that's a system constraint. If that's the case, an unwrap or expect would be more appropriate here

} else {
self.hydration_event.features.push(feature);
}
self.hydration_event.event_id = event_id;
Copy link
Member

@sighphyre sighphyre Feb 14, 2025

Choose a reason for hiding this comment

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

I think having this repeated event setting line in in 4 out of the 5 enum cases is a little fragile to future updates. You also went to all that trouble of creating a get_event_id method, so can I suggest we do this rather

  1. Remove the calls to self.hydration_event.event_id = event_id in the match arms
  2. Add a
        if !matches!(event, DeltaEvent::Hydration { .. }) {
            self.hydration_event.event_id = event.get_event_id();
        }

At the top of the method

@sjaanus sjaanus requested a review from sighphyre February 17, 2025 09:49
Copy link
Member

@sighphyre sighphyre left a comment

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
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants