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: support streaming in node JS SDK #452

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

markphelps
Copy link
Contributor

@markphelps markphelps commented Oct 17, 2024

Re: #430

This pull request introduces significant enhancements to the FliptEvaluationClient in the flipt-client-node package, including support for both polling and streaming fetch modes, and refactors to improve code readability and maintainability. The most important changes include modifications to the client initialization, the addition of streaming support, and updates to the testing suite to accommodate these new features.

Enhancements to FliptEvaluationClient:

  • Client Initialization:

    • Added support for namespace and fetchMode parameters in the client constructor and initialization method. (flipt-client-node/src/index.ts) [1] [2]
    • Updated the fetcher function to accept a URL and options, including an abort signal. (flipt-client-node/src/index.ts) [1] [2]
  • Streaming Support:

    • Introduced methods for starting and stopping streaming updates, including handling of streaming responses and abort signals. (flipt-client-node/src/index.ts) [1] [2]
    • Added new interfaces StreamChunk and StreamResult to handle streaming data. (flipt-client-node/src/internal/models.ts)

Updates to Testing Suite:

  • Refactoring Tests:
    • Moved client initialization inside a runTests function to support both polling and streaming fetch modes. (flipt-client-node/__tests__/evaluation.test.ts) [1] [2] [3]
    • Adjusted test teardown to ensure the client is properly closed, including awaiting the close operation. (flipt-client-node/__tests__/evaluation.test.ts)

Additional Changes:

  • Interface Updates:
    • Modified IFetcherOptions to include an optional signal property for aborting requests. (flipt-client-node/src/models.ts)
    • Added fetchMode to ClientOptions to specify whether to use polling or streaming. (flipt-client-node/src/models.ts) [1] [2]

These changes improve the flexibility and robustness of the FliptEvaluationClient, allowing it to better handle different use cases and environments.

@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.09%. Comparing base (40022f7) to head (ae201eb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #452   +/-   ##
=======================================
  Coverage   84.09%   84.09%           
=======================================
  Files           8        8           
  Lines        3936     3936           
=======================================
  Hits         3310     3310           
  Misses        626      626           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
@markphelps markphelps marked this pull request as ready for review October 17, 2024 18:16
@markphelps markphelps requested a review from a team as a code owner October 17, 2024 18:16
@markphelps markphelps requested a review from erka October 17, 2024 20:22
Copy link
Collaborator

@erka erka left a comment

Choose a reason for hiding this comment

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

nice!

One thing that worry me is the error handling in startStreamingUpdates. Let's say there is an network error for a minute for any reason and then a recover. What will happen to the Flipt client and how user could recover from it?

@markphelps
Copy link
Contributor Author

nice!

One thing that worry me is the error handling in startStreamingUpdates. Let's say there is an network error for a minute for any reason and then a recover. What will happen to the Flipt client and how user could recover from it?

yeah good point. we should likely add some reconnect/retry logic for both streaming and polling. it would be great to be smarter about error handling in general, like if its a 401 or 404 error because of bad auth token or invalid URL then it should exit quickly with error. but if its a transient networking error then we should try to reconnect. will look into how we can support this

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