Skip to content

Commit

Permalink
feat dynamic_config: support Kill-switches
Browse files Browse the repository at this point in the history
Tests: протестировано тестьютом и в тестинге
commit_hash:1c7d271c30ba7d360077f2e14db7f7019983beb9
  • Loading branch information
antonaksenov committed Nov 7, 2024
1 parent 281530e commit 4ee4621
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 16 deletions.
17 changes: 12 additions & 5 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@
"core/functional_tests/basic_chaos/tests-dynconf-cache/conftest.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-dynconf-cache/conftest.py",
"core/functional_tests/basic_chaos/tests-dynconf-cache/test_starts.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-dynconf-cache/test_starts.py",
"core/functional_tests/basic_chaos/tests-nonchaos/conftest.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/conftest.py",
"core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/conftest.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/conftest.py",
"core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_cache_updates.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_cache_updates.py",
"core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_changelog.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_changelog.py",
"core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_fixtures.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_fixtures.py",
"core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_invalid_update.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/dynamic_configs/test_invalid_update.py",
"core/functional_tests/basic_chaos/tests-nonchaos/handlers/test_log_request_headers.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/handlers/test_log_request_headers.py",
"core/functional_tests/basic_chaos/tests-nonchaos/metrics/test_has_reopening_error_metric.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/metrics/test_has_reopening_error_metric.py",
"core/functional_tests/basic_chaos/tests-nonchaos/middlewares/test_testsuite_middleware.py":"taxi/uservices/userver/core/functional_tests/basic_chaos/tests-nonchaos/middlewares/test_testsuite_middleware.py",
Expand All @@ -491,6 +486,18 @@
"core/functional_tests/cache_update/tests/conftest.py":"taxi/uservices/userver/core/functional_tests/cache_update/tests/conftest.py",
"core/functional_tests/cache_update/tests/test_cache_alerts.py":"taxi/uservices/userver/core/functional_tests/cache_update/tests/test_cache_alerts.py",
"core/functional_tests/cache_update/tests/test_cache_update.py":"taxi/uservices/userver/core/functional_tests/cache_update/tests/test_cache_update.py",
"core/functional_tests/dynamic_configs/CMakeLists.txt":"taxi/uservices/userver/core/functional_tests/dynamic_configs/CMakeLists.txt",
"core/functional_tests/dynamic_configs/config_vars.yaml":"taxi/uservices/userver/core/functional_tests/dynamic_configs/config_vars.yaml",
"core/functional_tests/dynamic_configs/service.cpp":"taxi/uservices/userver/core/functional_tests/dynamic_configs/service.cpp",
"core/functional_tests/dynamic_configs/static_config.yaml":"taxi/uservices/userver/core/functional_tests/dynamic_configs/static_config.yaml",
"core/functional_tests/dynamic_configs/tests-kill-switches/conftest.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests-kill-switches/conftest.py",
"core/functional_tests/dynamic_configs/tests-kill-switches/test_disabled_kill_switch.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests-kill-switches/test_disabled_kill_switch.py",
"core/functional_tests/dynamic_configs/tests-kill-switches/test_enabled_kill_switch.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests-kill-switches/test_enabled_kill_switch.py",
"core/functional_tests/dynamic_configs/tests/conftest.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests/conftest.py",
"core/functional_tests/dynamic_configs/tests/test_cache_updates.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests/test_cache_updates.py",
"core/functional_tests/dynamic_configs/tests/test_changelog.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests/test_changelog.py",
"core/functional_tests/dynamic_configs/tests/test_fixtures.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests/test_fixtures.py",
"core/functional_tests/dynamic_configs/tests/test_invalid_update.py":"taxi/uservices/userver/core/functional_tests/dynamic_configs/tests/test_invalid_update.py",
"core/functional_tests/http2server/CMakeLists.txt":"taxi/uservices/userver/core/functional_tests/http2server/CMakeLists.txt",
"core/functional_tests/http2server/service.cpp":"taxi/uservices/userver/core/functional_tests/http2server/service.cpp",
"core/functional_tests/http2server/static_config.yaml":"taxi/uservices/userver/core/functional_tests/http2server/static_config.yaml",
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 @@ -5,6 +5,9 @@ add_custom_target(${PROJECT_NAME})
add_subdirectory(basic_chaos)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-basic-chaos)

add_subdirectory(dynamic_configs)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-dynamic-configs)

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

Expand Down
8 changes: 0 additions & 8 deletions core/functional_tests/basic_chaos/tests-nonchaos/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import typing

import pytest

pytest_plugins = ['pytest_userver.plugins.core']


# For dynamic_configs/test_fixtures.py
@pytest.fixture(scope='session')
def dynamic_config_fallback_patch() -> typing.Dict[str, typing.Any]:
return {'HTTP_CLIENT_CONNECTION_POOL_SIZE': 777}


# redefinition fixture to change log_file path
@pytest.fixture(name='userver_config_logging', scope='session')
def _userver_config_logging(userver_config_logging, service_tmpdir):
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions core/functional_tests/dynamic_configs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project(userver-core-tests-dynamic-configs CXX)

add_executable(${PROJECT_NAME} "service.cpp")
target_link_libraries(${PROJECT_NAME} userver-core)

userver_chaos_testsuite_add()
17 changes: 17 additions & 0 deletions core/functional_tests/dynamic_configs/config_vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# yaml
server-name: test-dynamic-configs 1.0
service-name: test_dynamic_configs
logger-level: info

config-server-url: http://localhost:8083/
server-port: 8185
monitor-server-port: 8186

testsuite-enabled: false

userver-dumps-root: /var/cache/test_dynamic_configs/userver-dumps/
access-log-path: /var/log/test_dynamic_configs/access.log
access-tskv-log-path: /var/log/test_dynamic_configs/access_tskv.log
default-log-path: /var/log/test_dynamic_configs/server.log

config-cache: /var/cache/test_dynamic_configs/config_cache.json
53 changes: 53 additions & 0 deletions core/functional_tests/dynamic_configs/service.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <string>

#include <userver/utest/using_namespace_userver.hpp>

#include <userver/alerts/handler.hpp>
#include <userver/components/common_component_list.hpp>
#include <userver/components/common_server_component_list.hpp>
#include <userver/components/component.hpp>
#include <userver/components/component_base.hpp>
#include <userver/dynamic_config/source.hpp>
#include <userver/dynamic_config/storage/component.hpp>
#include <userver/server/handlers/ping.hpp>
#include <userver/testsuite/testpoint.hpp>
#include <userver/testsuite/testsuite_support.hpp>
#include <userver/utils/daemon_run.hpp>

namespace functional_tests {

inline const dynamic_config::Key kTestConfig{"TEST_CONFIG_KEY", std::string("static_default")};

class DynamicConfigForwarder final : public components::ComponentBase {
public:
static constexpr std::string_view kName = "dynamic-config-forwarder";

DynamicConfigForwarder(const components::ComponentConfig& config, const components::ComponentContext& context)
: components::ComponentBase(config, context),
config_subscription_(context.FindComponent<components::DynamicConfig>().GetSource().UpdateAndListen(
this,
kName,
&DynamicConfigForwarder::OnConfigUpdate
)){};

private:
void OnConfigUpdate(const dynamic_config::Snapshot& config) {
TESTPOINT("config-update", [config] {
return formats::json::ValueBuilder{config[kTestConfig]}.ExtractValue();
}());
}

concurrent::AsyncEventSubscriberScope config_subscription_;
};

} // namespace functional_tests

int main(int argc, const char* const argv[]) {
const auto component_list = components::ComponentList()
.AppendComponentList(components::CommonComponentList())
.AppendComponentList(components::CommonServerComponentList())
.Append<functional_tests::DynamicConfigForwarder>()
.Append<server::handlers::Ping>()
.Append<alerts::Handler>();
return utils::DaemonMain(argc, argv, component_list);
}
156 changes: 156 additions & 0 deletions core/functional_tests/dynamic_configs/static_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
components_manager:
components:
congestion-control:
fake-mode: $testsuite-enabled
load-enabled: true
dump-configurator:
dump-root: $userver-dumps-root
handler-implicit-http-options:
as_fallback: implicit-http-options
method: OPTIONS
task_processor: main-task-processor
throttling_enabled: false
dynamic-config-forwarder:
handler-inspect-requests:
path: /service/inspect-requests
method: GET
task_processor: monitor-task-processor
handler-jemalloc:
path: /service/jemalloc/prof/{command}
method: POST
task_processor: monitor-task-processor
handler-log-level:
path: /service/log-level/{level}
method: GET,PUT
task_processor: monitor-task-processor
handler-on-log-rotate:
path: /service/on-log-rotate/
method: POST
task_processor: monitor-task-processor
handler-dynamic-debug-log:
path: /service/log/dynamic-debug
method: GET,PUT,DELETE
task_processor: monitor-task-processor
handler-dns-client-control:
path: /service/dnsclient/{command}
method: POST
task_processor: monitor-task-processor
handler-server-monitor:
path: /service/monitor
method: GET
task_processor: monitor-task-processor

handler-ping:
path: /ping
method: GET
task_processor: main-task-processor # !!!
throttling_enabled: false
url_trailing_slash: strict-match

handler-fired-alerts:
path: /service/fired-alerts
method: GET
task_processor: main-task-processor

http-client:
fs-task-processor: fs-task-processor
user-agent: $server-name
user-agent#fallback: 'userver-based-service 1.0'

http-client-statistics:
fs-task-processor: fs-task-processor
pool-statistics-disable: true
thread-name-prefix: stats
user-agent: $server-name
dns-client:
fs-task-processor: fs-task-processor
logging:
fs-task-processor: fs-task-processor
loggers:
access:
file_path: $access-log-path
file_path#fallback: /var/log/company-name/service-name/access.log
overflow_behavior: discard
format: raw
access-tskv:
file_path: $access-tskv-log-path
file_path#fallback: /var/log/company-name/service-name/access_tskv.log
overflow_behavior: discard
format: raw
default:
file_path: $default-log-path
file_path#fallback: /var/log/company-name/service-name/server.log
level: $logger-level
level#fallback: info
overflow_behavior: discard
logging-configurator:
limited-logging-enable: true
limited-logging-interval: 1s
server:
listener:
port: $server-port
port#fallback: 8085
connection:
in_buffer_size: 32768
requests_queue_size_threshold: 100
task_processor: main-task-processor
listener-monitor:
port: $monitor-server-port
port#fallback: 8086
connection:
in_buffer_size: 32768
requests_queue_size_threshold: 100
task_processor: monitor-task-processor
logger_access: ''
logger_access_tskv: ''
max_response_size_in_flight: 1000000000
server-name: $server-name

system-statistics-collector:
fs-task-processor: fs-task-processor

dynamic-config:
updates-enabled: true
fs-cache-path: $config-cache
fs-task-processor: fs-task-processor
dynamic-config-client:
config-url: $config-server-url
http-retries: 5
http-timeout: 20s
service-name: $service-name
dynamic-config-client-updater:
config-settings: false
first-update-fail-ok: true
full-update-interval: 1m
update-interval: 5s

tests-control:
load-enabled: $testsuite-enabled
path: /tests/{action}
method: POST
task_processor: main-task-processor
testpoint-timeout: 10s
testpoint-url: $mockserver/testpoint
throttling_enabled: false
testsuite-support:





default_task_processor: main-task-processor

task_processors:
fs-task-processor:
worker_threads: $fs_worker_threads
worker_threads#fallback: 2
main-task-processor:
worker_threads: $main_worker_threads
worker_threads#fallback: 6
monitor-task-processor:
thread_name: mon-worker
worker_threads: $monitor_worker_threads
worker_threads#fallback: 1
event_thread_pool:
threads: $event_threads
threads#fallback: 2
Loading

0 comments on commit 4ee4621

Please sign in to comment.