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: dependent features #520

Merged
merged 11 commits into from
Sep 21, 2023
Merged

feat: dependent features #520

merged 11 commits into from
Sep 21, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Sep 19, 2023

About the changes

Dependent features implementation based on spec: Unleash/client-specification#63

Extra checks that may also be covered by other SDKs (listing them since this is our reference implementation):

  • metrics are not called on dependent features
  • impression events are called on dependent features for easier debugging
  • warning events for missing dependencies are reported once

Important files

Discussion points

@kwasniew kwasniew marked this pull request as draft September 19, 2023 14:20
@github-actions
Copy link

github-actions bot commented Sep 19, 2023

Coverage Status

coverage: 91.564% (+0.3%) from 91.252% when pulling 1b899f9 on dependent-features into 56f52f4 on main.

src/client.ts Show resolved Hide resolved
src/client.ts Outdated
@@ -55,8 +55,37 @@ export default class UnleashClient extends EventEmitter {
}
}

isParentDependencySatisfied(feature: FeatureInterface | undefined, context: Context) {
if (!feature?.name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can feature not have name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is what the existing type was telling me so I'm respecting it here

Copy link
Member

Choose a reason for hiding this comment

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

Feature's should have a name, but at least in this SDK we allow people to define their own bootstrapper so it's possible people put goop in there. This one is probably mostly legacy but respecting the existing types seems very sane to me

src/client.ts Outdated
return parent.variants.includes(this.getVariant(parent.feature, context).name);
}

return parent.enabled !== false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it more readable, and not do negate operator, but instead ===

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by default enabled is not provided so it's undefined. enabled: false is a special case for kill-switches in parent flag.This code is explicit about explicit enabled false and everything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reorganized the conditions a bit but the !== false has to stay as it is

src/client.ts Outdated
return feature.dependencies.every(parent => {
const parentFeature = this.repository.getToggle(parent.feature);

if (parentFeature?.dependencies?.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it more readable, Does this mean length exists or length === 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.

nope, it should also cater for undefined dependencies. Setting === 0 breaks the spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

move it to precondition check though

src/client.ts Outdated Show resolved Hide resolved
src/client.ts Outdated
@@ -55,8 +55,32 @@ export default class UnleashClient extends EventEmitter {
}
}

isParentDependencySatisfied(feature: FeatureInterface | undefined, context: Context) {
if (!feature?.name || !feature.dependencies?.length) {
Copy link
Member

Choose a reason for hiding this comment

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

What's with the name check here? Name should always be a non empty string, do I have the dumb or is the same as

if (!feature?.dependencies?.length) {
return true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still passes the spec. not sure why I did the name check but it's not in the type anymore. I'm hallucinating :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

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.

Glancing over the metrics code, it looks correct but I think it's worth having one or two tests to check that the parent doesn't get metric counts (I'm guessing, don't know if that's what you want). Especially if this is going to be the reference implementation so others know what to do, since the spec doesn't handle that

@kwasniew
Copy link
Contributor Author

@sighphyre addressed all your points :)

sighphyre
sighphyre previously approved these changes Sep 20, 2023
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.

Nice! LGTM

ivarconr
ivarconr previously approved these changes Sep 21, 2023
@kwasniew kwasniew merged commit 9d2c451 into main Sep 21, 2023
5 checks passed
@kwasniew kwasniew deleted the dependent-features branch September 21, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants