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

fix: Increment version for changing flagValues #317

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

kinyoklion
Copy link
Member

@kinyoklion kinyoklion commented Nov 16, 2023

When using FileData you have the option of just providing values. The pre-typescript SDK was liberal with what it considered an update and it would emit updates as things changed.

Some improvements to prevent spurious update events were added in typscript and these interfered with the basic way the FileData implementation works.

This PR makes a couple updates:
1.) If the value of a "flagValue" changes, then we will increment the version associated with it.
2.) If the value of a "flagValue" does not change, then we will not increment the version.

This should mean when values change the version will change. Standard flag/segment JSON must update their versions manually.

This will add some performance overhead.

This addresses #310

Copy link

@kinyoklion kinyoklion marked this pull request as ready for review November 16, 2023 23:22
@kinyoklion
Copy link
Member Author

@fhawkes If you are setup for development could you give this a try and see if it solves your problems?

@kinyoklion kinyoklion requested a review from keelerm84 November 16, 2023 23:29
@kinyoklion
Copy link
Member Author

There are some additional mismatches in typing that should be addressed. In specifically the FileDataSourceFactory. The old implementation had access to the config directly and was able to access the featureStore. This typing remained, which means it isn't completely correct. We don't have an external type for an update only feature store abstraction, but we 100% should.

This would be a breaking change, so I am not incorporating it as part of this change. Generally speaking it isn't an interface people implement often unless they are attempting to implement a custom update processor, which is a leaky abstraction we have maintained for backward compatibility.

// If the data is different, then we want to increment the version.
if (
previousInstance &&
JSON.stringify(parsed.flagValues[key]) !== JSON.stringify(previousInstance?.variations?.[0])
Copy link
Member Author

@kinyoklion kinyoklion Nov 16, 2023

Choose a reason for hiding this comment

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

This isn't deterministic (it usually will be, but sometimes the JSON properties may serialize in different orders). So we may want to do something different here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't recommend using FileDataSource in production, so this may be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

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

The different ordering is a concern, and the best way to deep compare is to use lodash's isEqual function. I'm reluctant to introduce dependency on lodash/is-equal, so if FileDataSource is only used in dev, I think this is ok for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can do with this, and then change when we can. Most flags aren't structured as well.

return {
key,
on: true,
fallthrough: { variation: 0 },
variations: [value],
version: 1,
version: version ?? 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is null coalescing needed here? version is a number and should not be null or undefined.

Suggested change
version: version ?? 1,
version,

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting that linting doesn't catch this. It was leftover from an interim version. Thank you for noticing it.

Copy link
Contributor

@yusinto yusinto left a comment

Choose a reason for hiding this comment

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

One small comment.

@fhawkes
Copy link

fhawkes commented Nov 21, 2023

@fhawkes If you are setup for development could you give this a try and see if it solves your problems?

Hey @kinyoklion I was able to test these changes out and they do solve the issue for us! I'm now seeing flag changes get emitted as expected. Thanks!!

@kinyoklion kinyoklion requested a review from yusinto November 27, 2023 17:51
@fhawkes
Copy link

fhawkes commented Dec 2, 2023

Any movement on this one?

@kinyoklion
Copy link
Member Author

Hey @fhawkes,

No movement. I will see if I can get to it soon.

Thank you,
Ryan

@kinyoklion kinyoklion merged commit e8e07ef into main Dec 4, 2023
15 checks passed
@kinyoklion kinyoklion deleted the rlamb/sc-224098/file-data-source-versions branch December 4, 2023 21:15
@github-actions github-actions bot mentioned this pull request Dec 4, 2023
kinyoklion added a commit that referenced this pull request Dec 4, 2023
🤖 I have created a release *beep* *boop*
---


<details><summary>@launchdarkly/akamai-edgeworker-sdk-common:
1.0.4</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.0 to ^2.1.1
</details>

<details><summary>@launchdarkly/akamai-server-base-sdk: 2.0.4</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.3 to
^1.0.4
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.0 to ^2.1.1
</details>

<details><summary>@launchdarkly/akamai-server-edgekv-sdk:
1.0.12</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.3 to
^1.0.4
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.0 to ^2.1.1
</details>

<details><summary>@launchdarkly/cloudflare-server-sdk: 2.3.1</summary>

### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.0 to 2.1.1
</details>

<details><summary>js-server-sdk-common: 2.1.1</summary>

##
[2.1.1](js-server-sdk-common-v2.1.0...js-server-sdk-common-v2.1.1)
(2023-12-04)


### Bug Fixes

* Increment version for changing flagValues
([#317](#317))
([e8e07ef](e8e07ef))
</details>

<details><summary>@launchdarkly/js-server-sdk-common-edge:
2.1.1</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.1.0 to 2.1.1
</details>

<details><summary>@launchdarkly/node-server-sdk: 9.0.4</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.1.0 to 2.1.1
</details>

<details><summary>@launchdarkly/node-server-sdk-dynamodb:
6.0.4</summary>

### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.3 to 9.0.4
</details>

<details><summary>@launchdarkly/node-server-sdk-redis: 4.0.4</summary>

### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.3 to 9.0.4
</details>

<details><summary>@launchdarkly/vercel-server-sdk: 1.2.1</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.0 to 2.1.1
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ryan Lamb <[email protected]>
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.

3 participants