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

Feature Flag evaluation not working as expected #52

Open
hect1c opened this issue May 17, 2023 · 3 comments
Open

Feature Flag evaluation not working as expected #52

hect1c opened this issue May 17, 2023 · 3 comments

Comments

@hect1c
Copy link

hect1c commented May 17, 2023

Hey,

I'm testing out Happykit Feature flags and ran into an issue or possibly I have a misunderstanding of how the feature flag evaluation works.

I have the following rules setup.

image

In my getServerSideProps I have the following code

    const { initialFlagState } = await getFlags({
      context,
      user: {
        // key: 'manager',
        key: '',
      },
    })

    console.log('initialFlagState', initialFlagState)

When I alternate between both key with manager and empty string it seems my feature flag key is always true. I'm assuming this is because my default when active is true is using variant 1 of true. But it says under Variant 1 option the following

This flag is currently active. It will respect individual user targeting and evaluate all rules. If none of these match, it will fall back to the value you configure here.

My understanding is that because of rule number 2 I set on the user where Key is not equal to the string I'm expecting then it will return variant 2 or false. Again this isn't working so not sure if I misunderstood how this should work, or I am doing something wrong.

Happy to create a reproduction if that helps but should be easy to replicate I think.

@dferber90
Copy link
Contributor

dferber90 commented May 18, 2023

Hey, thanks for the super detailed report!

HappyKit currently accepts three forms of inputs:

  • visitorKey: this is an automatically created key per visitor of your page. it's generated per device and might chance if cookies are lost
  • user: this identifies a specific user that exists in your application. you can provide a user and would typically supply your user's id as the user key. a user always needs to have at least a key. happykit supports a specific set of known attributes for users.
  • traits: this is any key-value pair you want to provide

You might be running into trouble as happykit doesn't expect an empty user key

  • Could you try using a trait instead? That would be recommended here
  • Could you try using a non-empty user key? Just for debugging purposes

@hect1c
Copy link
Author

hect1c commented May 18, 2023

Hey thanks for the reply.

So I have tried with traits and same issue it always resolves to true.

    const { initialFlagState } = await getFlags({
      context,
      traits: [{
        // key: 'manager', // this should be true
        key: 'test', // this should be false
      }],
    })

    console.log('initialFlagState', initialFlagState)

screenshot of the rules
image

screenshot of the initialFlagState output
Screenshot 2023-05-18 at 11 37 04 am

@dferber90
Copy link
Contributor

dferber90 commented May 18, 2023

Looks like the error is here:

    traits: [{
        // key: 'manager', // this should be true
        key: 'test', // this should be false
      }],

traits expects an object, but you are providing an array. Could you try with this?

    traits: {
        // key: 'manager', // this should be true
        key: 'test', // this should be false
      },

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

No branches or pull requests

2 participants