-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Implement polling data source. #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2eda0b7
feat: Implement polling data source.
kinyoklion 34e28ad
Add Etag support.
kinyoklion 837e081
Remove debug logging.
kinyoklion 8290107
Calculate polling delay.
kinyoklion c023ed8
Add close call.
kinyoklion bfc9fd0
Tidy
kinyoklion a762fc2
Remove outdated comment.
kinyoklion 5932087
Add a blank line.
kinyoklion e3c52c0
cin.get to block
kinyoklion 9290e1b
Move path and min interval to config.
kinyoklion 19d93b9
Add missing newline to end of file.
kinyoklion c298ac0
Change the server default polling interval.
kinyoklion 93e7ff8
Remove incorrect comment.
kinyoklion 40c58f6
Refactor streaming config.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,18 @@ | |
| #include "launchdarkly/client_side/data_source.hpp" | ||
| #include "launchdarkly/client_side/data_source_update_sink.hpp" | ||
| #include "launchdarkly/client_side/data_sources/detail/data_source_status_manager.hpp" | ||
| #include "launchdarkly/sse/client.hpp" | ||
| #include "logger.hpp" | ||
|
|
||
| namespace launchdarkly::client_side::data_sources::detail { | ||
|
|
||
| /** | ||
| * This class handles events source events, parses them, and then uses | ||
| * This class handles LaunchDarkly events, parses them, and then uses | ||
| * a IDataSourceUpdateSink to process the parsed events. | ||
| * | ||
| * This can be used for streaming or for polling. For polling only "put" events | ||
| * will be used. | ||
| */ | ||
| class StreamingDataHandler { | ||
| class DataSourceEventHandler { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used by both polling and streaming. |
||
| public: | ||
| /** | ||
| * Status indicating if the message was processed, or if there | ||
|
|
@@ -45,16 +47,18 @@ class StreamingDataHandler { | |
| uint64_t version; | ||
| }; | ||
|
|
||
| StreamingDataHandler(IDataSourceUpdateSink* handler, | ||
| Logger const& logger, | ||
| DataSourceStatusManager& status_manager); | ||
| DataSourceEventHandler(IDataSourceUpdateSink* handler, | ||
| Logger const& logger, | ||
| DataSourceStatusManager& status_manager); | ||
|
|
||
| /** | ||
| * Handle an SSE event. | ||
| * @param event The event to handle. | ||
| * Handles an event from the LaunchDarkly service. | ||
| * @param type The type of the event. "put"/"patch"/"delete". | ||
| * @param data The content of the evnet. | ||
| * @return A status indicating if the message could be handled. | ||
| */ | ||
| MessageStatus HandleMessage(launchdarkly::sse::Event const& event); | ||
| MessageStatus HandleMessage(std::string const& type, | ||
| std::string const& data); | ||
|
|
||
| private: | ||
| IDataSourceUpdateSink* handler_; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
libs/client-sdk/include/launchdarkly/client_side/data_sources/detail/polling_data_source.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
|
|
||
| #include <boost/asio/any_io_executor.hpp> | ||
|
|
||
| #include "config/client.hpp" | ||
| #include "config/detail/built/http_properties.hpp" | ||
| #include "data_source_status_manager.hpp" | ||
| #include "launchdarkly/client_side/data_source.hpp" | ||
| #include "launchdarkly/client_side/data_source_update_sink.hpp" | ||
| #include "launchdarkly/client_side/data_sources/detail/data_source_event_handler.hpp" | ||
| #include "logger.hpp" | ||
| #include "network/detail/asio_requester.hpp" | ||
|
|
||
| namespace launchdarkly::client_side::data_sources::detail { | ||
|
|
||
| class PollingDataSource : public IDataSource { | ||
| public: | ||
| PollingDataSource(Config const& config, | ||
| boost::asio::any_io_executor ioc, | ||
| Context const& context, | ||
| IDataSourceUpdateSink* handler, | ||
| DataSourceStatusManager& status_manager, | ||
| Logger const& logger); | ||
|
|
||
| void Start() override; | ||
| void Close() override; | ||
|
|
||
| private: | ||
| void DoPoll(); | ||
|
|
||
| std::string string_context_; | ||
| DataSourceStatusManager& status_manager_; | ||
| DataSourceEventHandler data_source_handler_; | ||
| std::string polling_endpoint_; | ||
|
|
||
| network::detail::AsioRequester requester_; | ||
| Logger const& logger_; | ||
| boost::asio::any_io_executor ioc_; | ||
| std::chrono::seconds polling_interval_; | ||
| network::detail::HttpRequest request_; | ||
| std::optional<std::string> etag_; | ||
|
|
||
| boost::asio::steady_timer timer_; | ||
| std::chrono::time_point<std::chrono::system_clock> last_poll_start_; | ||
|
|
||
| void StartPollingTimer(); | ||
| }; | ||
|
|
||
| } // namespace launchdarkly::client_side::data_sources::detail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,32 @@ | |
| #include <utility> | ||
|
|
||
| #include "events/detail/asio_event_processor.hpp" | ||
| #include "launchdarkly/client_side/data_sources/detail/polling_data_source.hpp" | ||
| #include "launchdarkly/client_side/data_sources/detail/streaming_data_source.hpp" | ||
|
|
||
| namespace launchdarkly::client_side { | ||
|
|
||
| using launchdarkly::client_side::data_sources::DataSourceStatus; | ||
|
|
||
| static std::unique_ptr<IDataSource> MakeDataSource( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we have file and test data sources we may need to scale this differently. |
||
| Config const& config, | ||
| Context const& context, | ||
| boost::asio::any_io_executor executor, | ||
| flag_manager::detail::FlagUpdater& flag_updater, | ||
| data_sources::detail::DataSourceStatusManager& status_manager, | ||
| Logger& logger) { | ||
| if (config.DataSourceConfig().method.which() == 0) { | ||
| // TODO: use initial reconnect delay. | ||
| return std::make_unique<launchdarkly::client_side::data_sources:: | ||
| detail::StreamingDataSource>( | ||
| config, executor, context, &flag_updater, status_manager, logger); | ||
| } else { | ||
| return std::make_unique< | ||
| launchdarkly::client_side::data_sources::detail::PollingDataSource>( | ||
| config, executor, context, &flag_updater, status_manager, logger); | ||
| } | ||
| } | ||
|
|
||
| Client::Client(Config config, Context context) | ||
| : logger_(config.Logger()), | ||
| context_(std::move(context)), | ||
|
|
@@ -21,19 +41,12 @@ Client::Client(Config config, Context context) | |
| config.SdkKey(), | ||
| logger_)), | ||
| flag_updater_(flag_manager_), | ||
| // TODO: Support polling. | ||
| data_source_(std::make_unique<launchdarkly::client_side::data_sources:: | ||
| detail::StreamingDataSource>( | ||
| config.SdkKey(), | ||
| ioc_.get_executor(), | ||
| context_, | ||
| config.ServiceEndpoints(), | ||
| config.HttpProperties(), | ||
| config.DataSourceConfig().use_report, | ||
| config.DataSourceConfig().with_reasons, | ||
| &flag_updater_, | ||
| status_manager_, | ||
| logger_)), | ||
| data_source_(MakeDataSource(config, | ||
| context_, | ||
| ioc_.get_executor(), | ||
| flag_updater_, | ||
| status_manager_, | ||
| logger_)), | ||
| initialized_(false) { | ||
| data_source_->Start(); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this use polling for now. So I could watch it poll.