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: delta rework #9133

Merged
merged 14 commits into from
Jan 22, 2025
Merged

feat: delta rework #9133

merged 14 commits into from
Jan 22, 2025

Conversation

sjaanus
Copy link
Contributor

@sjaanus sjaanus commented Jan 22, 2025

We are changing how the Delta API works, as discussed:

  1. We have removed the updated and removed arrays and now keep everything in the events array.
  2. We decided to keep the hydration cache separate from the events array internally. Since the hydration cache has a special structure and may contain not just one feature but potentially 1,000 features, it behaved differently, requiring a lot of special logic to handle it.
  3. Implemented nameprefix filtering, which we were missing before.

Things still to implement:

  1. Segment hydration and updates to it.

Copy link

vercel bot commented Jan 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 10:41am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 10:41am

Copy link
Contributor

@sjaanus, core features have been modified in this pull request. Please review carefully!

Copy link
Contributor

github-actions bot commented Jan 22, 2025

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

Some feedback we'll need to address before merging. I might just be missing context but let's discuss it before we go ahead.

Comment on lines +195 to +219
if (delta?.events[0].type === 'hydration') {
const hydrationEvent: DeltaHydrationEvent =
delta?.events[0];
const sortedNewToggles = hydrationEvent.features.sort(
(a, b) => a.name.localeCompare(b.name),
);

if (
!this.deepEqualIgnoreOrder(sortedToggles, sortedNewToggles)
) {
this.logger.warn(
`old features and new features are different. Old count ${
features.length
}, new count ${delta?.updated.length}, query ${JSON.stringify(query)},
if (
!this.deepEqualIgnoreOrder(
sortedToggles,
sortedNewToggles,
)
) {
this.logger.warn(
`old features and new features are different. Old count ${
features.length
}, new count ${hydrationEvent.features.length}, query ${JSON.stringify(query)},
diff ${JSON.stringify(
diff(sortedToggles, sortedNewToggles),
)}`,
);
}
} else {
this.logger.warn(
`Delta diff should have only hydration event, query ${JSON.stringify(query)}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct implementation of the diff checker? If we only compare on hydration event, how do we know that the deltas are producing the correct result?

Copy link
Contributor Author

@sjaanus sjaanus Jan 22, 2025

Choose a reason for hiding this comment

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

Well, every time you add new events to cache, they will instantly applied to hydration event.
We only take features from database at first, but after that we will start manipulation the hydration event every second by applying the deltas.

@@ -0,0 +1,63 @@
import type { ClientFeatureSchema } from '../../../openapi';
Copy link
Contributor

Choose a reason for hiding this comment

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

Love this file. Very clean.

(isDeltaFeatureUpdatedEvent(revision) &&
revision.feature.name.startsWith(namePrefix)) ||
(isDeltaFeatureRemovedEvent(revision) &&
revision.featureName.startsWith(namePrefix))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feature updated has complex object of feature, with all the description, strategies, constraints. Removed has just string value.

Comment on lines +60 to +62
return (
startsWithPrefix(revision) && (allProjects || isInProject(revision))
);
Copy link
Contributor

Choose a reason for hiding this comment

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

We always filter with namePrefix? What if nameprefix is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (requiredRevisionId >= this.currentRevisionId) {
return undefined;
}
if (requiredRevisionId === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be missing some context, but if this is the revisionId coming from the SDK, couldn't it possibly be undefined? Why a strict check on 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

LGTM

@sjaanus sjaanus merged commit 280710f into main Jan 22, 2025
12 checks passed
@sjaanus sjaanus deleted the delta-rework branch January 22, 2025 11:57
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.

2 participants