-
Notifications
You must be signed in to change notification settings - Fork 325
feat etcd: Init etcd client #837
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
Open
eskedesu
wants to merge
44
commits into
userver-framework:develop
Choose a base branch
from
eskedesu:init_etcd_client
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
145a211
init etcd client
eskedesu b184754
minor fixes
eskedesu bf56139
iteration
eskedesu 3c1e377
rename client
eskedesu fc3f6e7
iteration
eskedesu a1119f6
iteration
eskedesu 330ef41
iteration
eskedesu dfcee7d
iteration
eskedesu 327f1fc
iteration
eskedesu 54c585b
iteration
eskedesu 00b6bb8
iteration
eskedesu 497666d
iteration
eskedesu dc8b0f9
iteration
eskedesu 636ef6b
iteration
eskedesu 79818cc
remove connection timeout change
eskedesu c83160a
remove allowed url prefix
eskedesu 4207ee2
fix config plugin
eskedesu ae04fb6
format
eskedesu 9903913
fix doc
eskedesu 40ce833
Merge branch 'userver-framework:develop' into init_etcd_client
eskedesu 7c571f3
add tests
eskedesu 6e1993f
add tests
eskedesu 5ab0eab
add watch test
eskedesu ba964f7
delete file
eskedesu e9c866c
iteration
eskedesu fe9b745
format
eskedesu b8f4a82
iteration
eskedesu 2d02e27
iteration
eskedesu 2ff2c8a
iteration
eskedesu 83f325c
fix namespaces
eskedesu 6a7d901
Merge branch 'userver-framework:develop' into init_etcd_client
eskedesu 8d5c5d4
iteration
eskedesu 3f896d8
format
eskedesu a2f72a4
Add retries for watch
eskedesu 2d2ef4b
fix WatchListener
eskedesu 81b7f32
add chaotic
eskedesu 1870b81
iteration
eskedesu d664db7
fix convertion
eskedesu 645a253
fix convertion
eskedesu c2c8657
fix namespace
eskedesu 195dc37
fix namespaces for string64
eskedesu df6fc8c
add throws tag
eskedesu da9adcb
switch to BackgroundTaskStorage
eskedesu f4b316a
fix logs
eskedesu 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <userver/chaotic/io/userver/crypto/base64/string64.hpp> | ||
|
||
#include <userver/crypto/base64.hpp> | ||
|
||
USERVER_NAMESPACE_BEGIN | ||
|
||
namespace chaotic::convert { | ||
|
||
crypto::base64::String64 Convert(const std::string& str, chaotic::convert::To<crypto::base64::String64>) { | ||
return crypto::base64::String64(crypto::base64::Base64Decode(str)); | ||
} | ||
|
||
std::string Convert(const crypto::base64::String64& str64, chaotic::convert::To<std::string>) { | ||
return crypto::base64::Base64Encode(str64.GetUnderlying()); | ||
} | ||
|
||
} // namespace chaotic::convert | ||
|
||
USERVER_NAMESPACE_END |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
include_guard(GLOBAL) | ||
|
||
if(userver_etcd_FOUND) | ||
return() | ||
endif() | ||
|
||
find_package(userver REQUIRED COMPONENTS | ||
core | ||
) | ||
|
||
set(userver_etcd_FOUND TRUE) |
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,24 @@ | ||
project(userver-etcd CXX) | ||
|
||
file(GLOB_RECURSE SCHEMAS ${CMAKE_CURRENT_SOURCE_DIR}/schemas/*.yaml) | ||
userver_target_generate_chaotic(${PROJECT_NAME}-chgen | ||
GENERATE_SERIALIZERS | ||
LAYOUT | ||
"/components/schemas/([^/]*)/=etcd_schemas::{0}" | ||
OUTPUT_DIR | ||
${CMAKE_CURRENT_BINARY_DIR}/src | ||
SCHEMAS | ||
${SCHEMAS} | ||
RELATIVE_TO | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
userver_module(etcd | ||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" | ||
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp" | ||
LINK_LIBRARIES ${PROJECT_NAME}-chgen | ||
) | ||
|
||
if (USERVER_BUILD_TESTS) | ||
add_subdirectory(functional_tests) | ||
endif() |
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,6 @@ | ||
project(userver-etcd-tests CXX) | ||
|
||
add_custom_target(${PROJECT_NAME}) | ||
|
||
add_subdirectory(client) | ||
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-client) |
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,6 @@ | ||
project(userver-etcd-tests-client CXX) | ||
|
||
add_executable(${PROJECT_NAME} "etcd_service.cpp") | ||
target_link_libraries(${PROJECT_NAME} userver-core userver-etcd) | ||
|
||
userver_chaos_testsuite_add() |
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,92 @@ | ||
#include <userver/utest/using_namespace_userver.hpp> | ||
|
||
#include <fmt/format.h> | ||
|
||
#include <userver/clients/dns/component.hpp> | ||
#include <userver/clients/http/component.hpp> | ||
#include <userver/components/component_list.hpp> | ||
#include <userver/components/minimal_server_component_list.hpp> | ||
#include <userver/etcd/component.hpp> | ||
#include <userver/server/handlers/http_handler_base.hpp> | ||
#include <userver/server/handlers/ping.hpp> | ||
#include <userver/server/handlers/tests_control.hpp> | ||
#include <userver/testsuite/testsuite_support.hpp> | ||
#include <userver/utils/daemon_run.hpp> | ||
|
||
namespace { | ||
|
||
class HandlerV1Get final : public server::handlers::HttpHandlerBase { | ||
public: | ||
static constexpr std::string_view kName = "handler-v1-get"; | ||
|
||
HandlerV1Get(const components::ComponentConfig& config, const components::ComponentContext& component_context) | ||
: HttpHandlerBase(config, component_context), | ||
etcd_client_ptr_(component_context.FindComponent<etcd::Component>("etcd-client").GetClient()) {} | ||
|
||
std::string HandleRequestThrow(const server::http::HttpRequest& request, server::request::RequestContext&) | ||
const override { | ||
const auto maybe_value = etcd_client_ptr_->Get(request.GetArg("key")); | ||
return maybe_value.value_or("No value"); | ||
} | ||
|
||
private: | ||
etcd::ClientPtr etcd_client_ptr_; | ||
}; | ||
|
||
class HandlerV1Put final : public server::handlers::HttpHandlerBase { | ||
public: | ||
static constexpr std::string_view kName = "handler-v1-put"; | ||
|
||
HandlerV1Put(const components::ComponentConfig& config, const components::ComponentContext& component_context) | ||
: HttpHandlerBase(config, component_context), | ||
etcd_client_ptr_(component_context.FindComponent<etcd::Component>("etcd-client").GetClient()) {} | ||
|
||
std::string HandleRequestThrow(const server::http::HttpRequest& request, server::request::RequestContext&) | ||
const override { | ||
etcd_client_ptr_->Put(request.GetArg("key"), request.GetArg("value")); | ||
|
||
return std::string(); | ||
} | ||
|
||
private: | ||
etcd::ClientPtr etcd_client_ptr_; | ||
}; | ||
|
||
class HandlerV1Watch final : public server::handlers::HttpHandlerBase { | ||
public: | ||
static constexpr std::string_view kName = "handler-v1-watch"; | ||
|
||
HandlerV1Watch(const components::ComponentConfig& config, const components::ComponentContext& component_context) | ||
: HttpHandlerBase(config, component_context), | ||
etcd_client_ptr_(component_context.FindComponent<etcd::Component>("etcd-client").GetClient()) {} | ||
|
||
std::string HandleRequestThrow(const server::http::HttpRequest& request, server::request::RequestContext&) | ||
const override { | ||
const auto key = request.GetArg("key"); | ||
const auto maybe_original_value = etcd_client_ptr_->Get(key); | ||
auto watch_listener = etcd_client_ptr_->StartWatch(key); | ||
const auto watch_event = watch_listener.GetEvent(); | ||
const auto new_value = watch_event.value; | ||
return fmt::format("original value: {}, new value: {}", maybe_original_value.value_or("No value"), new_value); | ||
} | ||
|
||
private: | ||
etcd::ClientPtr etcd_client_ptr_; | ||
}; | ||
|
||
} // namespace | ||
|
||
int main(int argc, char* argv[]) { | ||
auto component_list = components::MinimalServerComponentList() | ||
.Append<server::handlers::Ping>() | ||
.Append<components::TestsuiteSupport>() | ||
.Append<components::HttpClient>() | ||
.Append<clients::dns::Component>() | ||
.Append<etcd::Component>() | ||
.Append<server::handlers::TestsControl>() | ||
.Append<HandlerV1Get>() | ||
.Append<HandlerV1Put>() | ||
.Append<HandlerV1Watch>(); | ||
|
||
return utils::DaemonMain(argc, argv, component_list); | ||
} |
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,76 @@ | ||
# yaml | ||
components_manager: | ||
task_processors: | ||
main-task-processor: | ||
worker_threads: 4 | ||
|
||
fs-task-processor: | ||
worker_threads: 1 | ||
|
||
default_task_processor: main-task-processor | ||
|
||
components: | ||
server: | ||
listener: | ||
port: 8080 | ||
task_processor: main-task-processor | ||
connection: | ||
http-version: '2' | ||
http2-session: | ||
max_concurrent_streams: 100 | ||
max_frame_size: 16384 | ||
initial_window_size: 65536 | ||
listener-monitor: | ||
port: 8081 | ||
task_processor: main-task-processor | ||
logging: | ||
fs-task-processor: fs-task-processor | ||
loggers: | ||
default: | ||
file_path: '@stderr' | ||
level: error | ||
overflow_behavior: discard | ||
|
||
http-client: | ||
fs-task-processor: fs-task-processor | ||
user-agent: $server-name | ||
user-agent#fallback: 'userver-based-service 1.0' | ||
dns-client: | ||
fs-task-processor: fs-task-processor | ||
testsuite-support: | ||
tests-control: | ||
path: /tests/{action} | ||
method: POST | ||
task_processor: main-task-processor | ||
testpoint-timeout: 10s | ||
testpoint-url: $mockserver/testpoint | ||
throttling_enabled: false | ||
|
||
handler-ping: | ||
path: /ping | ||
method: GET | ||
task_processor: main-task-processor | ||
throttling_enabled: false | ||
url_trailing_slash: strict-match | ||
|
||
etcd-client: | ||
endpoints: | ||
- http://localhost:2379 | ||
attempts: 2 | ||
request_timeout_ms: 500 | ||
watch_timeout_ms: 1000000 | ||
|
||
handler-v1-get: | ||
path: /v1/get | ||
method: POST | ||
task_processor: main-task-processor | ||
|
||
handler-v1-put: | ||
path: /v1/put | ||
method: PUT | ||
task_processor: main-task-processor | ||
|
||
handler-v1-watch: | ||
path: /v1/watch | ||
method: POST | ||
task_processor: main-task-processor |
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.
Uh oh!
There was an error while loading. Please reload this page.