-
Notifications
You must be signed in to change notification settings - Fork 345
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
42
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
42 commits
Select commit
Hold shift + click to select a range
7b19158
init etcd client
eskedesu 0de1248
minor fixes
eskedesu 5436c1e
iteration
eskedesu eb2bc58
rename client
eskedesu 4ff1170
iteration
eskedesu 83b37a5
iteration
eskedesu bb38f45
iteration
eskedesu 1fe00a2
iteration
eskedesu 1479ef2
iteration
eskedesu 99aacab
iteration
eskedesu 2b41803
iteration
eskedesu 0c95754
iteration
eskedesu 627a9f9
iteration
eskedesu 2c59b2f
iteration
eskedesu 2e5d7f5
remove connection timeout change
eskedesu 6445363
remove allowed url prefix
eskedesu 733ad26
fix config plugin
eskedesu 063030b
format
eskedesu 333cbd4
fix doc
eskedesu 5377ffb
add tests
eskedesu 710ae63
add tests
eskedesu 95ff228
add watch test
eskedesu dc75cd5
delete file
eskedesu 5240f6d
iteration
eskedesu b8d928e
format
eskedesu 3f3c400
iteration
eskedesu 35b4ca7
iteration
eskedesu e44ad3f
iteration
eskedesu c9b0675
fix namespaces
eskedesu 31e5baf
iteration
eskedesu 2719aff
format
eskedesu 0b7928f
Add retries for watch
eskedesu 95a1928
fix WatchListener
eskedesu 62acc29
add chaotic
eskedesu 968930c
iteration
eskedesu 0738894
fix convertion
eskedesu 77662ef
fix convertion
eskedesu cca6434
fix namespace
eskedesu bc49574
fix namespaces for string64
eskedesu 298d7d3
add throws tag
eskedesu 38446b4
switch to BackgroundTaskStorage
eskedesu cb883c0
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.