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

Dependent features #274

Merged
merged 15 commits into from
Oct 24, 2023
Merged

Dependent features #274

merged 15 commits into from
Oct 24, 2023

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Oct 5, 2023

Description

Related to Unleash/unleash#2255

Introducing concept of "dependency" on a feature toggle. Feature toggle, in order to be enabled an return a variant, can require the specified state of another feature toggle. There will be a dependencies property on each feature.

{
 ...
 "dependencies": {
   "feature": "string-featureId",
   "enabled: true, // boolean, state that is expected defaults to `true`
   "variants": ["variant1", "variant2"] // optional, variants allowed for feature to be enabled
 }
}

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • Unit tests
  • Spec Tests
  • Integration tests / Manual Tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@coveralls
Copy link

coveralls commented Oct 5, 2023

Coverage Status

coverage: 96.885% (+0.007%) from 96.878% when pulling aa55c07 on feat/feature-dependencies into b1d5b70 on main.

@Tymek Tymek marked this pull request as ready for review October 6, 2023 12:21
Copy link
Contributor

@kwasniew kwasniew 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 to me however I'm not a Python dev so would appreciate some Pythonista eyes on it :) I'd also add a test showing that we don't record a metrics for the parent feature.

dependency_feature = self.features[dependency_name]

if not dependency_feature:
LOGGER.warning("Feature dependency not found. %s", dependency_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

in Node we have a mechanism to only log this message once. I'm assuming we don't do the same thing in Python SDK

Copy link
Member

Choose a reason for hiding this comment

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

Not a thing in the Python SDK at the moment, unfortunately. Not against adding it, but that should probably be a different PR

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.

Overall LGTM, I've left some thoughts, which are optional but should be considered, so I'm going to mark this as changes requested so this doesn't get accidentally merged

@sighphyre
Copy link
Member

Looks good to me however I'm not a Python dev so would appreciate some Pythonista eyes on it :) I'd also add a test showing that we don't record a metrics for the parent feature.

Agree with @kwasniew on the test, please!

@@ -75,20 +82,20 @@ def _count_variant(self, variant_name: str) -> None:
"""
self.variant_counts[variant_name] = self.variant_counts.get(variant_name, 0) + 1

def is_enabled(self, context: dict = None) -> bool:
def is_enabled(self, context: dict = None, skip_stats: bool = False) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a more elegant way to do it? Without passing skip_stats around.

Copy link
Member

Choose a reason for hiding this comment

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

Can't think of a way without rearchitecting this a little. It should be possible to move the count metrics methods to public ones and only call those in the is_enabled in the UnleashClient but... I'm not sure that's worth it. This is all internal at the moment and when Yggdrasil arrives here this will go away anyway.

I'm okay with this as it stands. I think we can do better but I also don't think it's worth it to do so. I think this is a reasonable tradeoff

@Tymek Tymek requested a review from sighphyre October 24, 2023 09:28
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.

Thumbs up

@Tymek Tymek merged commit 5133699 into main Oct 24, 2023
34 checks passed
@Tymek Tymek deleted the feat/feature-dependencies branch October 24, 2023 11:32
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.

4 participants