Skip to content

Commit

Permalink
feat core: implement generic tracing logic
Browse files Browse the repository at this point in the history
Ref: userver-framework#366

Tests: протестировано локально и в CI
  • Loading branch information
apolukhin committed Oct 5, 2023
1 parent 4588215 commit 2136a38
Show file tree
Hide file tree
Showing 44 changed files with 1,158 additions and 73 deletions.
13 changes: 11 additions & 2 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@
"core/functional_tests/metrics/tests/static/metrics_values.txt":"taxi/uservices/userver/core/functional_tests/metrics/tests/static/metrics_values.txt",
"core/functional_tests/metrics/tests/test_metrics.py":"taxi/uservices/userver/core/functional_tests/metrics/tests/test_metrics.py",
"core/functional_tests/service.yaml":"taxi/uservices/userver/core/functional_tests/service.yaml",
"core/functional_tests/tracing/CMakeLists.txt":"taxi/uservices/userver/core/functional_tests/tracing/CMakeLists.txt",
"core/functional_tests/tracing/dynamic_config_fallback.json":"taxi/uservices/userver/core/functional_tests/tracing/dynamic_config_fallback.json",
"core/functional_tests/tracing/echo_no_body.cpp":"taxi/uservices/userver/core/functional_tests/tracing/echo_no_body.cpp",
"core/functional_tests/tracing/static_config.yaml":"taxi/uservices/userver/core/functional_tests/tracing/static_config.yaml",
"core/functional_tests/tracing/tests/conftest.py":"taxi/uservices/userver/core/functional_tests/tracing/tests/conftest.py",
"core/functional_tests/tracing/tests/test_trace_headers_propagation.py":"taxi/uservices/userver/core/functional_tests/tracing/tests/test_trace_headers_propagation.py",
"core/functional_tests/uctl/CMakeLists.txt":"taxi/uservices/userver/core/functional_tests/uctl/CMakeLists.txt",
"core/functional_tests/uctl/config_vars.yaml":"taxi/uservices/userver/core/functional_tests/uctl/config_vars.yaml",
"core/functional_tests/uctl/dynamic_config_fallback.json":"taxi/uservices/userver/core/functional_tests/uctl/dynamic_config_fallback.json",
Expand Down Expand Up @@ -527,7 +533,6 @@
"core/include/userver/tracing/manager.hpp":"taxi/uservices/userver/core/include/userver/tracing/manager.hpp",
"core/include/userver/tracing/manager_component.hpp":"taxi/uservices/userver/core/include/userver/tracing/manager_component.hpp",
"core/include/userver/tracing/noop.hpp":"taxi/uservices/userver/core/include/userver/tracing/noop.hpp",
"core/include/userver/tracing/opentracing.hpp":"taxi/uservices/userver/core/include/userver/tracing/opentracing.hpp",
"core/include/userver/tracing/scope_time.hpp":"taxi/uservices/userver/core/include/userver/tracing/scope_time.hpp",
"core/include/userver/tracing/set_throttle_reason.hpp":"taxi/uservices/userver/core/include/userver/tracing/set_throttle_reason.hpp",
"core/include/userver/tracing/span.hpp":"taxi/uservices/userver/core/include/userver/tracing/span.hpp",
Expand Down Expand Up @@ -1235,7 +1240,8 @@
"core/src/tracing/no_log_spans.cpp":"taxi/uservices/userver/core/src/tracing/no_log_spans.cpp",
"core/src/tracing/no_log_spans.hpp":"taxi/uservices/userver/core/src/tracing/no_log_spans.hpp",
"core/src/tracing/noop.cpp":"taxi/uservices/userver/core/src/tracing/noop.cpp",
"core/src/tracing/opentracing.cpp":"taxi/uservices/userver/core/src/tracing/opentracing.cpp",
"core/src/tracing/opentracing_logger.cpp":"taxi/uservices/userver/core/src/tracing/opentracing_logger.cpp",
"core/src/tracing/opentracing_logger.hpp":"taxi/uservices/userver/core/src/tracing/opentracing_logger.hpp",
"core/src/tracing/scope_time.cpp":"taxi/uservices/userver/core/src/tracing/scope_time.cpp",
"core/src/tracing/scope_time_test.cpp":"taxi/uservices/userver/core/src/tracing/scope_time_test.cpp",
"core/src/tracing/set_throttle_reason.cpp":"taxi/uservices/userver/core/src/tracing/set_throttle_reason.cpp",
Expand Down Expand Up @@ -3127,6 +3133,7 @@
"universal/include/userver/logging/log_helper_fwd.hpp":"taxi/uservices/userver/universal/include/userver/logging/log_helper_fwd.hpp",
"universal/include/userver/logging/null_logger.hpp":"taxi/uservices/userver/universal/include/userver/logging/null_logger.hpp",
"universal/include/userver/logging/stacktrace_cache.hpp":"taxi/uservices/userver/universal/include/userver/logging/stacktrace_cache.hpp",
"universal/include/userver/tracing/opentelemetry.hpp":"taxi/uservices/userver/universal/include/userver/tracing/opentelemetry.hpp",
"universal/include/userver/utest/assert_macros.hpp":"taxi/uservices/userver/universal/include/userver/utest/assert_macros.hpp",
"universal/include/userver/utest/death_tests.hpp":"taxi/uservices/userver/universal/include/userver/utest/death_tests.hpp",
"universal/include/userver/utest/impl/assert_macros.hpp":"taxi/uservices/userver/universal/include/userver/utest/impl/assert_macros.hpp",
Expand Down Expand Up @@ -3373,6 +3380,8 @@
"universal/src/logging/rate_limit.cpp":"taxi/uservices/userver/universal/src/logging/rate_limit.cpp",
"universal/src/logging/rate_limit.hpp":"taxi/uservices/userver/universal/src/logging/rate_limit.hpp",
"universal/src/logging/stacktrace_cache.cpp":"taxi/uservices/userver/universal/src/logging/stacktrace_cache.cpp",
"universal/src/tracing/opentelemetry.cpp":"taxi/uservices/userver/universal/src/tracing/opentelemetry.cpp",
"universal/src/tracing/opentelemetry_test.cpp":"taxi/uservices/userver/universal/src/tracing/opentelemetry_test.cpp",
"universal/src/utest/assert_macros.cpp":"taxi/uservices/userver/universal/src/utest/assert_macros.cpp",
"universal/src/utest/assert_macros_test.cpp":"taxi/uservices/userver/universal/src/utest/assert_macros_test.cpp",
"universal/src/utils/algo_test.cpp":"taxi/uservices/userver/universal/src/utils/algo_test.cpp",
Expand Down
3 changes: 3 additions & 0 deletions core/functional_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-basic-chaos)
add_subdirectory(metrics)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-metrics)

add_subdirectory(tracing)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-tracing)

add_subdirectory(uctl)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-uctl)

Expand Down
6 changes: 6 additions & 0 deletions core/functional_tests/tracing/CMakeLists.txt
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 core/functional_tests/tracing/dynamic_config_fallback.json
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
}
}
}
}
}
64 changes: 64 additions & 0 deletions core/functional_tests/tracing/echo_no_body.cpp
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);
}
60 changes: 60 additions & 0 deletions core/functional_tests/tracing/static_config.yaml
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
22 changes: 22 additions & 0 deletions core/functional_tests/tracing/tests/conftest.py
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
Loading

0 comments on commit 2136a38

Please sign in to comment.