forked from userver-framework/userver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat core: implement generic tracing logic
Ref: userver-framework#366 Tests: протестировано локально и в CI
- Loading branch information
Showing
44 changed files
with
1,158 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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-core-tests-tracing CXX) | ||
|
||
add_executable(${PROJECT_NAME} "echo_no_body.cpp") | ||
target_link_libraries(${PROJECT_NAME} userver-core) | ||
|
||
userver_chaos_testsuite_add() |
76 changes: 76 additions & 0 deletions
76
core/functional_tests/tracing/dynamic_config_fallback.json
This file contains 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 @@ | ||
{ | ||
"BAGGAGE_SETTINGS": { | ||
"allowed_keys": [] | ||
}, | ||
"HTTP_CLIENT_CONNECTION_POOL_SIZE": 1000, | ||
"HTTP_CLIENT_CONNECT_THROTTLE": { | ||
"max-size": 100, | ||
"token-update-interval-ms": 0 | ||
}, | ||
"USERVER_BAGGAGE_ENABLED": false, | ||
"USERVER_CACHES": {}, | ||
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false, | ||
"USERVER_CHECK_AUTH_IN_HANDLERS": true, | ||
"USERVER_DEADLINE_PROPAGATION_ENABLED": true, | ||
"USERVER_DUMPS": {}, | ||
"USERVER_FILES_CONTENT_TYPE_MAP": { | ||
".css": "text/css", | ||
".gif": "image/gif", | ||
".htm": "text/html", | ||
".html": "text/html", | ||
".jpeg": "image/jpeg", | ||
".js": "application/javascript", | ||
".json": "application/json", | ||
".md": "text/markdown", | ||
".png": "image/png", | ||
".svg": "image/svg+xml", | ||
"__default__": "text/plain" | ||
}, | ||
"USERVER_HANDLER_STREAM_API_ENABLED": false, | ||
"USERVER_HTTP_PROXY": "", | ||
"USERVER_LOG_DYNAMIC_DEBUG": { | ||
"force-disabled": [], | ||
"force-enabled": [] | ||
}, | ||
"USERVER_LOG_REQUEST": true, | ||
"USERVER_LOG_REQUEST_HEADERS": false, | ||
"USERVER_LRU_CACHES": {}, | ||
"USERVER_NO_LOG_SPANS": { | ||
"names": [], | ||
"prefixes": [] | ||
}, | ||
"USERVER_RPS_CCONTROL": { | ||
"down-level": 1, | ||
"down-rate-percent": 2, | ||
"min-limit": 10, | ||
"no-limit-seconds": 1000, | ||
"overload-off-seconds": 3, | ||
"overload-on-seconds": 3, | ||
"up-level": 2, | ||
"up-rate-percent": 2 | ||
}, | ||
"USERVER_RPS_CCONTROL_ACTIVATED_FACTOR_METRIC": 5, | ||
"USERVER_RPS_CCONTROL_CUSTOM_STATUS": {}, | ||
"USERVER_RPS_CCONTROL_ENABLED": false, | ||
"USERVER_TASK_PROCESSOR_PROFILER_DEBUG": { | ||
"fs-task-processor": { | ||
"enabled": false, | ||
"execution-slice-threshold-us": 1000000 | ||
}, | ||
"main-task-processor": { | ||
"enabled": false, | ||
"execution-slice-threshold-us": 2000 | ||
} | ||
}, | ||
"USERVER_TASK_PROCESSOR_QOS": { | ||
"default-service": { | ||
"default-task-processor": { | ||
"wait_queue_overload": { | ||
"action": "ignore", | ||
"length_limit": 5000, | ||
"time_limit_us": 3000 | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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,64 @@ | ||
#include <userver/utils/assert.hpp> | ||
|
||
#include <userver/clients/dns/component.hpp> | ||
#include <userver/clients/http/component.hpp> | ||
#include <userver/components/component.hpp> | ||
#include <userver/components/minimal_server_component_list.hpp> | ||
#include <userver/http/url.hpp> | ||
#include <userver/server/handlers/http_handler_base.hpp> | ||
#include <userver/server/handlers/tests_control.hpp> | ||
#include <userver/testsuite/testsuite_support.hpp> | ||
#include <userver/utils/daemon_run.hpp> | ||
#include <userver/yaml_config/merge_schemas.hpp> | ||
|
||
#include <userver/utest/using_namespace_userver.hpp> | ||
|
||
class EchoNoBody final : public server::handlers::HttpHandlerBase { | ||
public: | ||
static constexpr std::string_view kName = "handler-echo-no-body"; | ||
|
||
EchoNoBody(const components::ComponentConfig& config, | ||
const components::ComponentContext& context) | ||
: HttpHandlerBase(config, context), | ||
echo_url_{config["echo-url"].As<std::string>()}, | ||
http_client_( | ||
context.FindComponent<components::HttpClient>().GetHttpClient()) {} | ||
|
||
std::string HandleRequestThrow( | ||
const server::http::HttpRequest&, | ||
server::request::RequestContext&) const override { | ||
auto response = http_client_.CreateRequest() | ||
.get(echo_url_) | ||
.retry(2) | ||
.timeout(std::chrono::seconds{5}) | ||
.perform(); | ||
response->raise_for_status(); | ||
return {}; | ||
} | ||
|
||
static yaml_config::Schema GetStaticConfigSchema() { | ||
return yaml_config::MergeSchemas<server::handlers::HttpHandlerBase>(R"( | ||
type: object | ||
description: HTTP echo without body component | ||
additionalProperties: false | ||
properties: | ||
echo-url: | ||
type: string | ||
description: some other microservice listens on this URL | ||
)"); | ||
} | ||
|
||
private: | ||
const std::string echo_url_; | ||
clients::http::Client& http_client_; | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
const auto component_list = components::MinimalServerComponentList() | ||
.Append<EchoNoBody>() | ||
.Append<components::TestsuiteSupport>() | ||
.Append<server::handlers::TestsControl>() | ||
.Append<clients::dns::Component>() | ||
.Append<components::HttpClient>(); | ||
return utils::DaemonMain(argc, argv, component_list); | ||
} |
This file contains 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,60 @@ | ||
components_manager: | ||
components: | ||
handler-echo-no-body: | ||
echo-url: 'mockserver/v1/translations' # Some other microservice listens on this URL | ||
path: /echo-no-body | ||
method: GET | ||
task_processor: main-task-processor | ||
|
||
http-client: | ||
fs-task-processor: fs-task-processor | ||
|
||
dns-client: | ||
fs-task-processor: fs-task-processor | ||
|
||
testsuite-support: | ||
tests-control: | ||
# Some options from server::handlers::HttpHandlerBase | ||
path: /tests/{action} | ||
method: POST | ||
task_processor: main-task-processor | ||
|
||
server: | ||
listener: | ||
port: 8089 | ||
task_processor: main-task-processor | ||
logging: | ||
fs-task-processor: fs-task-processor | ||
loggers: | ||
default: | ||
file_path: '@stderr' | ||
level: debug | ||
overflow_behavior: discard | ||
|
||
tracer: | ||
service-name: http-trcin-test | ||
|
||
tracing-manager-locator: | ||
incomming-format: ['taxi', 'yandex', 'b3-alternative', 'opentelemetry'] | ||
new-requests-format: ['taxi', 'yandex', 'b3-alternative', 'opentelemetry'] | ||
|
||
dynamic-config: # Dynamic config storage options, do nothing | ||
fs-cache-path: '' | ||
dynamic-config-fallbacks: # Load options from file and push them into the dynamic config storage. | ||
fallback-path: /etc/http_caching/dynamic_config_fallback.json | ||
|
||
coro_pool: | ||
initial_size: 500 # Preallocate 500 coroutines at startup. | ||
max_size: 1000 # Do not keep more than 1000 preallocated coroutines. | ||
|
||
task_processors: # Task processor is an executor for coroutine tasks | ||
|
||
main-task-processor: # Make a task processor for CPU-bound coroutine tasks. | ||
worker_threads: 4 # Process tasks in 4 threads. | ||
thread_name: main-worker # OS will show the threads of this task processor with 'main-worker' prefix. | ||
|
||
fs-task-processor: # Make a separate task processor for filesystem bound tasks. | ||
thread_name: fs-worker | ||
worker_threads: 4 | ||
|
||
default_task_processor: main-task-processor |
This file contains 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,22 @@ | ||
import pytest | ||
|
||
|
||
pytest_plugins = ['pytest_userver.plugins.core'] | ||
|
||
USERVER_CONFIG_HOOKS = ['userver_config_echo_url'] | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def userver_config_echo_url(mockserver_info): | ||
def do_patch(config_yaml, config_vars): | ||
components = config_yaml['components_manager']['components'] | ||
components['handler-echo-no-body']['echo-url'] = mockserver_info.url( | ||
'/test-service/echo-no-body', | ||
) | ||
|
||
return do_patch | ||
|
||
|
||
@pytest.fixture | ||
def taxi_test_service(service_client): | ||
return service_client |
Oops, something went wrong.