-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: improve IDataSynchronizer's interface to expose IDestination #306
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
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ | |
| #include <boost/json.hpp> | ||
|
|
||
| namespace launchdarkly::server_side::data_systems { | ||
|
|
||
| static char const* const kErrorParsingPut = "Could not parse polling payload"; | ||
| static char const* const kErrorPutInvalid = | ||
| "Polling payload contained invalid data"; | ||
|
|
@@ -44,22 +43,20 @@ std::string const& PollingDataSource::Identity() const { | |
| } | ||
|
|
||
| PollingDataSource::PollingDataSource( | ||
| boost::asio::any_io_executor const& ioc, | ||
|
Contributor
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. These changes follow from re-arranging the constructor args. |
||
| Logger const& logger, | ||
| data_components::DataSourceStatusManager& status_manager, | ||
| config::built::ServiceEndpoints const& endpoints, | ||
| config::built::BackgroundSyncConfig::PollingConfig const& | ||
| data_source_config, | ||
| config::built::HttpProperties const& http_properties, | ||
| boost::asio::any_io_executor const& ioc, | ||
| data_interfaces::IDestination& handler, | ||
| data_components::DataSourceStatusManager& status_manager, | ||
| Logger const& logger) | ||
| : ioc_(ioc), | ||
| logger_(logger), | ||
| config::built::HttpProperties const& http_properties) | ||
| : logger_(logger), | ||
| status_manager_(status_manager), | ||
| update_sink_(handler), | ||
| requester_(ioc), | ||
| timer_(ioc), | ||
| polling_interval_(data_source_config.poll_interval), | ||
| request_(MakeRequest(data_source_config, endpoints, http_properties)) { | ||
| request_(MakeRequest(data_source_config, endpoints, http_properties)), | ||
| timer_(ioc), | ||
| sink_(nullptr) { | ||
| if (polling_interval_ < data_source_config.min_polling_interval) { | ||
| LD_LOG(logger_, LogLevel::kWarn) | ||
| << "Polling interval too frequent, defaulting to " | ||
|
|
@@ -72,10 +69,6 @@ PollingDataSource::PollingDataSource( | |
| } | ||
| } | ||
|
|
||
| void PollingDataSource::Init( | ||
| std::optional<data_model::SDKDataSet> initial_data) { | ||
| // TODO: implement | ||
| } | ||
| void PollingDataSource::DoPoll() { | ||
| last_poll_start_ = std::chrono::system_clock::now(); | ||
|
|
||
|
|
@@ -136,7 +129,7 @@ void PollingDataSource::HandlePollResult(network::HttpResult const& res) { | |
| tl::expected<data_model::SDKDataSet, JsonError>>(parsed); | ||
|
|
||
| if (poll_result.has_value()) { | ||
| update_sink_.Init(std::move(*poll_result)); | ||
| sink_->Init(std::move(*poll_result)); | ||
| status_manager_.SetState( | ||
| DataSourceStatus::DataSourceState::kValid); | ||
| return; | ||
|
|
@@ -211,7 +204,13 @@ void PollingDataSource::StartPollingTimer() { | |
| }); | ||
| } | ||
|
|
||
| void PollingDataSource::StartAsync() { | ||
| void PollingDataSource::StartAsync( | ||
| data_interfaces::IDestination* dest, | ||
| data_model::SDKDataSet const* bootstrap_data) { | ||
| boost::ignore_unused(bootstrap_data); | ||
|
|
||
| sink_ = dest; | ||
|
|
||
| status_manager_.SetState(DataSourceStatus::DataSourceState::kInitializing); | ||
| if (!request_.Valid()) { | ||
| LD_LOG(logger_, LogLevel::kError) << kCouldNotParseEndpoint; | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ namespace launchdarkly::server_side::data_systems { | |
| static char const* const kCouldNotParseEndpoint = | ||
| "Could not parse streaming endpoint URL"; | ||
|
|
||
| static char const* DataSourceErrorToString(launchdarkly::sse::Error error) { | ||
| static char const* DataSourceErrorToString(sse::Error const error) { | ||
| switch (error) { | ||
| case sse::Error::NoContent: | ||
| return "server responded 204 (No Content), will not attempt to " | ||
|
|
@@ -34,28 +34,26 @@ std::string const& StreamingDataSource::Identity() const { | |
| } | ||
|
|
||
| StreamingDataSource::StreamingDataSource( | ||
|
Contributor
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. Follows from re-arranging constructor args. |
||
| config::built::ServiceEndpoints const& endpoints, | ||
| config::built::BackgroundSyncConfig::StreamingConfig const& | ||
| data_source_config, | ||
| config::built::HttpProperties http_properties, | ||
| boost::asio::any_io_executor ioc, | ||
| data_interfaces::IDestination& handler, | ||
| boost::asio::any_io_executor io, | ||
| Logger const& logger, | ||
| data_components::DataSourceStatusManager& status_manager, | ||
| Logger const& logger) | ||
| : exec_(std::move(ioc)), | ||
| config::built::ServiceEndpoints const& endpoints, | ||
| config::built::BackgroundSyncConfig::StreamingConfig const& streaming, | ||
| config::built::HttpProperties const& http_properties) | ||
| : io_(std::move(io)), | ||
| logger_(logger), | ||
| status_manager_(status_manager), | ||
| data_source_handler_(handler, logger, status_manager_), | ||
| http_config_(std::move(http_properties)), | ||
| streaming_config_(data_source_config), | ||
| http_config_(http_properties), | ||
| streaming_config_(streaming), | ||
| streaming_endpoint_(endpoints.StreamingBaseUrl()) {} | ||
|
|
||
| void StreamingDataSource::Init( | ||
| std::optional<data_model::SDKDataSet> initial_data) { | ||
| // TODO: implement | ||
| } | ||
| void StreamingDataSource::StartAsync( | ||
| data_interfaces::IDestination* dest, | ||
| data_model::SDKDataSet const* bootstrap_data) { | ||
| boost::ignore_unused(bootstrap_data); | ||
|
|
||
| event_handler_.emplace(*dest, logger_, status_manager_); | ||
|
|
||
| void StreamingDataSource::StartAsync() { | ||
| status_manager_.SetState(DataSourceStatus::DataSourceState::kInitializing); | ||
|
|
||
| auto updated_url = network::AppendUrl(streaming_endpoint_, | ||
|
|
@@ -85,7 +83,7 @@ void StreamingDataSource::StartAsync() { | |
|
|
||
| boost::urls::url url = uri_components.value(); | ||
|
|
||
| auto client_builder = launchdarkly::sse::Builder(exec_, url.buffer()); | ||
| auto client_builder = launchdarkly::sse::Builder(io_, url.buffer()); | ||
|
|
||
| client_builder.method(boost::beast::http::verb::get); | ||
|
|
||
|
|
@@ -101,16 +99,15 @@ void StreamingDataSource::StartAsync() { | |
| client_builder.initial_reconnect_delay( | ||
| streaming_config_.initial_reconnect_delay); | ||
|
|
||
| for (auto const& header : http_config_.BaseHeaders()) { | ||
| client_builder.header(header.first, header.second); | ||
| for (auto const& [key, value] : http_config_.BaseHeaders()) { | ||
| client_builder.header(key, value); | ||
| } | ||
|
|
||
| auto weak_self = weak_from_this(); | ||
|
|
||
| client_builder.receiver([weak_self](launchdarkly::sse::Event const& event) { | ||
| if (auto self = weak_self.lock()) { | ||
| self->data_source_handler_.HandleMessage(event.type(), | ||
| event.data()); | ||
| self->event_handler_->HandleMessage(event.type(), event.data()); | ||
| // TODO: Use the result of handle message to restart the | ||
| // event source if we got bad data. sc-204387 | ||
| } | ||
|
|
@@ -153,7 +150,7 @@ void StreamingDataSource::ShutdownAsync(std::function<void()> completion) { | |
| return client_->async_shutdown(std::move(completion)); | ||
| } | ||
| if (completion) { | ||
| boost::asio::post(exec_, completion); | ||
| boost::asio::post(io_, completion); | ||
| } | ||
| } | ||
| } // namespace launchdarkly::server_side::data_systems | ||
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.
Re-arranged the constructor arguments to follow our C++ standards.