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

Support v0.4.0 spec #11

Merged
merged 3 commits into from
Apr 18, 2023
Merged

Support v0.4.0 spec #11

merged 3 commits into from
Apr 18, 2023

Conversation

dsantosmerino
Copy link
Contributor

Support v0.4.0 spec, based on this growthbook/growthbook#959 and the related docs to build your own SDK https://docs.growthbook.io/lib/build-your-own. These docs and the language agnostic cases.json file are really useful to maintain the SDKs up to date, congrats 👏

While I attempted to only modify the required classes and methods to match the new specification, I believe there is room for improving the SDK. Specifically, I suggest:

  • Adopting a more idiomatic Ruby and using a more standard style. Rubocop can help with this.
  • Removing unnecessary code. Classes like User, Experiment, ExperimentResult, and some methods seem to no longer be required and can be cleaned up.
  • Test the SDK with different Ruby versions.

@@ -3270,7 +3270,7 @@
"hashVersion": 2,
"variations": [0, 1],
"weights": [0.5, 0.5],
"coverage": [0.99]
"coverage": 0.99
Copy link
Contributor Author

@dsantosmerino dsantosmerino Apr 10, 2023

Choose a reason for hiding this comment

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

Is this a legit fix or should the SDK be ready to receive an array here? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Coverage should be a float. There was an error in the initial cases.json file where it was specified as an array of floats.

@tinahollygb
Copy link
Contributor

Thanks for these changes. Taking a look now.

FYI the spec has been updated to 0.4.1 since your PR has been submitted, which fixes the coverage issue you raised, as well as other issues like invalid hash version handling and decryption:

return (FNV.new.fnv1a_32(value + seed) % 1000) / 1000.0 if version == 1
return (FNV.new.fnv1a_32(FNV.new.fnv1a_32(seed + value).to_s) % 10000) / 10000.0 if version == 2

-1
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the updated 0.4.1 tests, this method should return nil. We are doing a less than check which returns truthy for -1 when it shouldn't, and this was fixed in 0.4.1.

@@ -148,5 +151,9 @@ def self.get_query_string_override(id, url, numVariations)

n
end

def self.in_range(n, range)
Copy link
Contributor

Choose a reason for hiding this comment

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

My thoughts are this may be better as def self.in_range?(n, range)

'name' => @name,
'phase' => @phase,
'tracks' => @tracks
}.compact
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍 Is this tested in new or existing test cases so we can make sure it still returns the same output?

Copy link
Contributor

@tinahollygb tinahollygb left a comment

Choose a reason for hiding this comment

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

Thanks for this! 🚀

I left some minor feedback but nothing blocking. I will merge this for now and you are welcome to do 0.4.1 or we can do it, just let us know if you'd like to do it.

With changes to 0.4.1 it adds support for decrypting encrypted features, which would address this new open ticket: #12

@tinahollygb tinahollygb merged commit b166fe4 into growthbook:main Apr 18, 2023
@dsantosmerino
Copy link
Contributor Author

Hey @tinahollygb!

you are welcome to do 0.4.1 or we can do it, just let us know if you'd like to do it.

I don't think I'll have time in the next couple of weeks. Hope you can do it meanwhile 😸

Also, are you planning to publish a new release including the recent changes?

Something less urgent or important, are you interested in any of these possible improvements in the future?

  • Adopting a more idiomatic Ruby and using a more standard style. Rubocop can help with this.
  • Removing unnecessary code. Classes like User, Experiment, ExperimentResult, and some methods seem to no longer be required and can be cleaned up.
  • Test the SDK with different Ruby versions.

@tinahollygb
Copy link
Contributor

Thanks @dsantosmerino, we can take care of the 0.4.1 changes.

Also, are you planning to publish a new release including the recent changes?

I will discuss with the rest of the team when the next publish is appropriate, but I know we have a bug fix in 0.4.1 that impacts the new hashing, so I'm hesitant to publish a new version before that gets out, though it's unlikely that bug would impact anyone so maybe it's ok to still publish, I'll check with others. This was fixed last week in the JS SDK if I'm not mistaken, so you may not be aware of it (we now return null instead of -1 when an invalid hash version is provided). We also have plans to add decrypting of encrypted payloads, which is required to support version 0.4.1 of the test case file. I will chat with the team to figure out when the right time is to publish a new release, i.e. if we should do it at 0.4.1 support or if 0.4.0 is ok.

Something less urgent or important, are you interested in any of these possible improvements in the future?

Yes, very interested! I even got started on it yesterday. You can review the PR if you like: #14

Adopting a more idiomatic Ruby and using a more standard style. Rubocop can help with this.
Test the SDK with different Ruby versions.

The PR covers adding Rubocop and CI processes that include testing on 2.5 and 3.2.2. I did not add jruby or some of the other ones but feel free to review and offer suggestions if you think we should cover more. I have personally never used jruby, and I have not heard of some of the others that the Github Action supports. Let me know if you have any other thoughts. I do know for sure that we cannot support 2.4 due to syntax. In that PR, there are failing builds that can be seen when checking coverage for lower versions.

As for the unused classes, I'm going to address that now in this PR as it was suggested to remove those. I'll have to chat with another teammate to see what can be deleted as many of these are still used.

In the meantime, if you have some bandwidth, please review the changes in the PR that addresses the improvement suggestions: #14

Thanks!

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.

2 participants