diff --git a/frontik/dependencies/__init__.py b/frontik/dependencies/__init__.py index f44901d15..02f5599d8 100644 --- a/frontik/dependencies/__init__.py +++ b/frontik/dependencies/__init__.py @@ -1,8 +1,26 @@ import contextvars -from typing import Any +from typing import Annotated, Any + +import http_client +from fastapi import Depends + +from frontik.app_integrations import statsd clients: contextvars.ContextVar = contextvars.ContextVar('clients') -def get_app_config() -> Any: +async def _get_app_config() -> Any: return clients.get().get('app_config') + + +async def _get_http_client() -> http_client.HttpClient: + return clients.get().get('http_client') + + +async def _get_statsd_client() -> statsd.StatsDClient: + return clients.get().get('statsd_client') + + +StatsDClient = Annotated[statsd.StatsDClient, Depends(_get_statsd_client)] +AppConfig = Annotated[Any, Depends(_get_app_config)] +HttpClient = Annotated[http_client.HttpClient, Depends(_get_http_client)] diff --git a/frontik/dependencies/http_client.py b/frontik/dependencies/http_client.py deleted file mode 100644 index adfc313a6..000000000 --- a/frontik/dependencies/http_client.py +++ /dev/null @@ -1,29 +0,0 @@ -from http_client import HttpClient -from http_client.request_response import RequestResult - -from frontik.dependencies import clients - - -async def get_url(*args, **kwargs) -> RequestResult: - _http_client: HttpClient = clients.get().get('http_client') - return await _http_client.get_url(*args, **kwargs) - - -async def head_url(*args, **kwargs) -> RequestResult: - _http_client: HttpClient = clients.get().get('http_client') - return await _http_client.head_url(*args, **kwargs) - - -async def post_url(*args, **kwargs) -> RequestResult: - _http_client: HttpClient = clients.get().get('http_client') - return await _http_client.post_url(*args, **kwargs) - - -async def put_url(*args, **kwargs) -> RequestResult: - _http_client: HttpClient = clients.get().get('http_client') - return await _http_client.put_url(*args, **kwargs) - - -async def delete_url(*args, **kwargs) -> RequestResult: - _http_client: HttpClient = clients.get().get('http_client') - return await _http_client.delete_url(*args, **kwargs) diff --git a/frontik/dependencies/statsd_client.py b/frontik/dependencies/statsd_client.py deleted file mode 100644 index 304eca716..000000000 --- a/frontik/dependencies/statsd_client.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import Any - -from frontik.app_integrations.statsd import StatsDClient -from frontik.dependencies import clients - - -def count(aspect: str, delta: int, **kwargs: Any) -> None: - _statsd_client: StatsDClient = clients.get().get('statsd_client') - return _statsd_client.count(aspect, delta, **kwargs) - - -def gauge(aspect: str, value: float, **kwargs: Any) -> None: - _statsd_client: StatsDClient = clients.get().get('statsd_client') - return _statsd_client.gauge(aspect, value, **kwargs) - - -def time(aspect: str, value: float, **kwargs: Any) -> None: - _statsd_client: StatsDClient = clients.get().get('statsd_client') - return _statsd_client.time(aspect, value, **kwargs) diff --git a/tests/projects/balancer_app/pages/different_datacenter.py b/tests/projects/balancer_app/pages/different_datacenter.py index 0e61af68e..5daa2e9d4 100644 --- a/tests/projects/balancer_app/pages/different_datacenter.py +++ b/tests/projects/balancer_app/pages/different_datacenter.py @@ -3,13 +3,13 @@ from http_client.request_response import NoAvailableServerException from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server @router.get('/different_datacenter') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: free_server = get_server(request, 'free') free_server.datacenter = 'dc1' normal_server = get_server(request, 'normal') diff --git a/tests/projects/balancer_app/pages/no_available_backend.py b/tests/projects/balancer_app/pages/no_available_backend.py index b3c141d6e..746a4b3b9 100644 --- a/tests/projects/balancer_app/pages/no_available_backend.py +++ b/tests/projects/balancer_app/pages/no_available_backend.py @@ -2,13 +2,13 @@ from http_client.balancing import Upstream from http_client.request_response import NoAvailableServerException -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app.pages import check_all_requests_done @router.get('/no_available_backend') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() no_available_backend = 'no_available_backend' upstreams[no_available_backend] = Upstream(no_available_backend, {}, []) diff --git a/tests/projects/balancer_app/pages/no_retry_error.py b/tests/projects/balancer_app/pages/no_retry_error.py index ca8d64f27..1b3f6aaf6 100644 --- a/tests/projects/balancer_app/pages/no_retry_error.py +++ b/tests/projects/balancer_app/pages/no_retry_error.py @@ -1,14 +1,14 @@ from fastapi import Request from http_client.balancing import Upstream -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done @router.get('/no_retry_error') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() no_retry_error = 'no_retry_error' upstreams[no_retry_error] = Upstream(no_retry_error, {}, [get_server(request, 'broken')]) diff --git a/tests/projects/balancer_app/pages/no_retry_timeout.py b/tests/projects/balancer_app/pages/no_retry_timeout.py index 497e83d89..85eb767d7 100644 --- a/tests/projects/balancer_app/pages/no_retry_timeout.py +++ b/tests/projects/balancer_app/pages/no_retry_timeout.py @@ -3,14 +3,14 @@ from fastapi import Request from http_client.balancing import Upstream -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done @router.get('/no_retry_timeout') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() no_retry_timeout = 'no_retry_timeout' upstreams[no_retry_timeout] = Upstream(no_retry_timeout, {}, [get_server(request, 'broken')]) diff --git a/tests/projects/balancer_app/pages/profile_with_retry.py b/tests/projects/balancer_app/pages/profile_with_retry.py index b257b003d..3eee1b13d 100644 --- a/tests/projects/balancer_app/pages/profile_with_retry.py +++ b/tests/projects/balancer_app/pages/profile_with_retry.py @@ -2,13 +2,13 @@ from http_client.balancing import Upstream, UpstreamConfig from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server @router.get('/profile_with_retry') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: servers = [get_server(request, 'broken'), get_server(request, 'normal')] profile_with_retry = 'profile_with_retry' upstream_config = { diff --git a/tests/projects/balancer_app/pages/profile_without_retry.py b/tests/projects/balancer_app/pages/profile_without_retry.py index be9e84250..1248269ee 100644 --- a/tests/projects/balancer_app/pages/profile_without_retry.py +++ b/tests/projects/balancer_app/pages/profile_without_retry.py @@ -1,13 +1,13 @@ from fastapi import Request from http_client.balancing import Upstream, UpstreamConfig -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server @router.get('/profile_without_retry') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: servers = [get_server(request, 'broken'), get_server(request, 'normal')] profile_without_retry = 'profile_without_retry' upstream_config = { diff --git a/tests/projects/balancer_app/pages/requests_count.py b/tests/projects/balancer_app/pages/requests_count.py index dd8b8986f..108ee951f 100644 --- a/tests/projects/balancer_app/pages/requests_count.py +++ b/tests/projects/balancer_app/pages/requests_count.py @@ -4,14 +4,14 @@ from http_client.balancing import Upstream from http_client.request_response import RequestResult -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done, check_all_servers_occupied @router.get('/requests_count') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() requests_count_async = 'requests_count_async' upstreams[requests_count_async] = Upstream(requests_count_async, {}, [get_server(request, 'normal')]) diff --git a/tests/projects/balancer_app/pages/retry_connect.py b/tests/projects/balancer_app/pages/retry_connect.py index 953068604..153fbc560 100644 --- a/tests/projects/balancer_app/pages/retry_connect.py +++ b/tests/projects/balancer_app/pages/retry_connect.py @@ -2,7 +2,7 @@ from http_client.balancing import Upstream from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from frontik.util import gather_list from tests.projects.balancer_app import get_server @@ -10,7 +10,7 @@ @router.get('/retry_connect') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() retry_connect = 'retry_connect' upstreams[retry_connect] = Upstream( diff --git a/tests/projects/balancer_app/pages/retry_connect_timeout.py b/tests/projects/balancer_app/pages/retry_connect_timeout.py index ccd488b04..f8a8f365a 100644 --- a/tests/projects/balancer_app/pages/retry_connect_timeout.py +++ b/tests/projects/balancer_app/pages/retry_connect_timeout.py @@ -2,7 +2,7 @@ from http_client.balancing import Upstream from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from frontik.util import gather_list from tests.projects.balancer_app import get_server @@ -10,7 +10,7 @@ @router.get('/retry_connect_timeout') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: retry_connect_timeout = 'retry_connect_timeout' upstreams = request.app.service_discovery.get_upstreams_unsafe() upstreams[retry_connect_timeout] = Upstream(retry_connect_timeout, {}, [get_server(request, 'normal')]) diff --git a/tests/projects/balancer_app/pages/retry_count_limit.py b/tests/projects/balancer_app/pages/retry_count_limit.py index 321d00ef8..ba0c05a83 100644 --- a/tests/projects/balancer_app/pages/retry_count_limit.py +++ b/tests/projects/balancer_app/pages/retry_count_limit.py @@ -1,14 +1,14 @@ from fastapi import Request from http_client.balancing import Upstream, UpstreamConfig -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests import find_free_port from tests.projects.balancer_app import get_server_with_port @router.get('/retry_count_limit') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: retry_count_limit = 'retry_count_limit' upstream = Upstream( retry_count_limit, diff --git a/tests/projects/balancer_app/pages/retry_error.py b/tests/projects/balancer_app/pages/retry_error.py index 656f1dfc1..0909242f3 100644 --- a/tests/projects/balancer_app/pages/retry_error.py +++ b/tests/projects/balancer_app/pages/retry_error.py @@ -2,7 +2,7 @@ from http_client.balancing import Upstream from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from frontik.util import gather_list from tests.projects.balancer_app import get_server @@ -10,7 +10,7 @@ @router.get('/retry_error') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() retry_error = 'retry_error' upstreams[retry_error] = Upstream(retry_error, {}, [get_server(request, 'broken'), get_server(request, 'normal')]) diff --git a/tests/projects/balancer_app/pages/retry_non_idempotent_503.py b/tests/projects/balancer_app/pages/retry_non_idempotent_503.py index 7a6a73dae..b6a7b2de0 100644 --- a/tests/projects/balancer_app/pages/retry_non_idempotent_503.py +++ b/tests/projects/balancer_app/pages/retry_non_idempotent_503.py @@ -2,7 +2,7 @@ from http_client.balancing import Upstream, UpstreamConfig from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from frontik.util import gather_list from tests.projects.balancer_app import get_server @@ -10,7 +10,7 @@ @router.get('/retry_non_idempotent_503') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstream_config = {Upstream.DEFAULT_PROFILE: UpstreamConfig(retry_policy={503: {'idempotent': 'true'}})} upstreams = request.app.service_discovery.get_upstreams_unsafe() retry_non_idempotent = 'retry_non_idempotent_503' diff --git a/tests/projects/balancer_app/pages/retry_on_timeout.py b/tests/projects/balancer_app/pages/retry_on_timeout.py index f7e94f09e..4910495e0 100644 --- a/tests/projects/balancer_app/pages/retry_on_timeout.py +++ b/tests/projects/balancer_app/pages/retry_on_timeout.py @@ -2,14 +2,14 @@ from http_client.balancing import Upstream from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done @router.get('/retry_on_timeout') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() retry_on_timeout = 'retry_on_timeout' upstreams[retry_on_timeout] = Upstream( diff --git a/tests/projects/balancer_app/pages/slow_start.py b/tests/projects/balancer_app/pages/slow_start.py index 5ae3240ca..a7c6426b7 100644 --- a/tests/projects/balancer_app/pages/slow_start.py +++ b/tests/projects/balancer_app/pages/slow_start.py @@ -3,14 +3,14 @@ from fastapi import Request from http_client.balancing import Server, Upstream, UpstreamConfig -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done, check_all_servers_were_occupied @router.get('/slow_start') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: server = get_server(request, 'normal') server.weight = 5 diff --git a/tests/projects/balancer_app/pages/speculative_no_retry.py b/tests/projects/balancer_app/pages/speculative_no_retry.py index abbe8601d..46852fc47 100644 --- a/tests/projects/balancer_app/pages/speculative_no_retry.py +++ b/tests/projects/balancer_app/pages/speculative_no_retry.py @@ -1,13 +1,13 @@ from fastapi import Request from http_client.balancing import Upstream -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server @router.get('/speculative_no_retry') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() speculative_no_retry = 'speculative_no_retry' upstreams[speculative_no_retry] = Upstream( diff --git a/tests/projects/balancer_app/pages/speculative_retry.py b/tests/projects/balancer_app/pages/speculative_retry.py index 84a3baab5..f55900e14 100644 --- a/tests/projects/balancer_app/pages/speculative_retry.py +++ b/tests/projects/balancer_app/pages/speculative_retry.py @@ -2,13 +2,13 @@ from http_client.balancing import Upstream from tornado.web import HTTPError -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router from tests.projects.balancer_app import get_server @router.get('/speculative_retry') -async def get_page(request: Request) -> str: +async def get_page(request: Request, http_client: HttpClient) -> str: upstreams = request.app.service_discovery.get_upstreams_unsafe() speculative_retry = 'speculative_retry' upstreams[speculative_retry] = Upstream( diff --git a/tests/projects/test_app/pages/http_client/proxy_code.py b/tests/projects/test_app/pages/http_client/proxy_code.py index 6b6ead10c..6b1ef96c4 100644 --- a/tests/projects/test_app/pages/http_client/proxy_code.py +++ b/tests/projects/test_app/pages/http_client/proxy_code.py @@ -1,10 +1,10 @@ from fastapi import Response -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.routing import router @router.get('/http_client/proxy_code') -async def get_page(port: str): +async def get_page(port: str, http_client: HttpClient): result = await http_client.get_url('http://127.0.0.1:' + port, '') return Response(str(result.status_code)) diff --git a/tests/test_debug.py b/tests/test_debug.py index 0f3a1fdbc..ecf0ede35 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -13,7 +13,7 @@ from frontik import media_types from frontik.app import FrontikApplication -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.options import options from frontik.routing import router from frontik.testing import FrontikTestBase @@ -23,7 +23,7 @@ @router.get('/debug') -async def get_debug_page(request: Request, no_recursion: str = 'false') -> None: +async def get_debug_page(request: Request, http_client: HttpClient, no_recursion: str = 'false') -> None: logger.debug('debug: starting debug page') def _exception_trace() -> None: diff --git a/tests/test_frontik_testing.py b/tests/test_frontik_testing.py index fb21f5eb9..497377127 100644 --- a/tests/test_frontik_testing.py +++ b/tests/test_frontik_testing.py @@ -4,7 +4,7 @@ from fastapi import Request, Response from frontik.app import FrontikApplication -from frontik.dependencies import get_app_config, http_client +from frontik.dependencies import AppConfig, HttpClient from frontik.routing import router from frontik.testing import FrontikTestBase from frontik.util import gather_list @@ -12,10 +12,9 @@ @router.get('/sum_values') -async def sum_values_page() -> int: - config = get_app_config() +async def sum_values_page(app_config: AppConfig, http_client: HttpClient) -> int: result = 0 - service_host = config.serviceHost + service_host = app_config.serviceHost res1, res2 = await gather_list( http_client.get_url(service_host, '/val1/1'), http_client.get_url(service_host, '/val2/2') @@ -27,13 +26,12 @@ async def sum_values_page() -> int: @router.get('/config') -async def check_config_page() -> Response: - config = get_app_config() - return Response(config.config_param) +async def check_config_page(app_config: AppConfig) -> Response: + return Response(app_config.config_param) @router.post('/json_stub') -async def post_page(request: Request) -> Any: +async def post_page(request: Request, http_client: HttpClient) -> Any: result = await http_client.delete_url('http://backend', request.url.path, fail_fast=True) return result.data diff --git a/tests/test_http_client.py b/tests/test_http_client.py index 516913ab0..ddad6829f 100644 --- a/tests/test_http_client.py +++ b/tests/test_http_client.py @@ -10,7 +10,7 @@ from frontik import media_types from frontik.app import FrontikApplication -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.loggers import JSON_FORMATTER from frontik.routing import router from frontik.testing import FrontikTestBase @@ -18,7 +18,7 @@ @router.get('/http_client/custom_headers') -async def custom_headers_get_page(request: Request): +async def custom_headers_get_page(request: Request, http_client: HttpClient): result = await http_client.post_url(request.headers.get('host'), request.url.path) return result.data @@ -29,7 +29,7 @@ async def custom_headers_post_page(request: Request): @router.get('/http_client/fibonacci') -async def fibonacci_page(n: int, request: Request): +async def fibonacci_page(n: int, request: Request, http_client: HttpClient): if n < 2: return Response('1', headers={'Content-Type': media_types.TEXT_PLAIN}) @@ -45,7 +45,7 @@ async def fibonacci_page(n: int, request: Request): @router.get('/http_client/raise_error') -async def unicode_page(request: Request): +async def unicode_page(request: Request, http_client: HttpClient): try: await http_client.post_url(request.headers.get('host'), '/a-вот') except UnicodeEncodeError: @@ -72,7 +72,7 @@ async def unicode_page(request: Request): @router.get('/http_client/post_url') -async def post_url_get_page(request: Request): +async def post_url_get_page(request: Request, http_client: HttpClient): result = await http_client.post_url(request.headers.get('host'), request.url.path, data=FIELDS, files=FILES) if not result.failed: return result.data @@ -114,7 +114,7 @@ async def post_url_post_page(request: Request): @router.get('/http_client/parse_response') -async def parse_response_get_page(request: Request): +async def parse_response_get_page(request: Request, http_client: HttpClient): res = {} result = await http_client.post_url(request.headers.get('host'), request.url.path, parse_on_error=True) res.update(result.data) @@ -144,7 +144,7 @@ async def parse_response_delete_page(): @router.get('/http_client/parse_error') -async def parse_error_get_page(request: Request): +async def parse_error_get_page(request: Request, http_client: HttpClient): el_result = await http_client.post_url(request.headers.get('host'), request.url.path + '?mode=xml') element = el_result.data if element is not None: @@ -166,7 +166,7 @@ async def parse_error_post_page(mode: str): @router.get('/http_client/post_simple') -async def post_simple_get_page(request: Request): +async def post_simple_get_page(request: Request, http_client: HttpClient): result = await http_client.post_url(request.headers.get('host'), request.url.path) return Response(result.data) @@ -177,7 +177,7 @@ async def post_simple_post_page(): @router.get('/http_client/long_page_request') -async def long_request_page(request: Request): +async def long_request_page(request: Request, http_client: HttpClient): result = await http_client.post_url(request.headers.get('host'), request.url.path, request_timeout=0.5) return {'error_received': result.failed} @@ -258,7 +258,7 @@ async def long_page() -> None: @router.get('/long_request') -async def long_request(request: Request) -> None: +async def long_request(request: Request, http_client: HttpClient) -> None: await http_client.get_url(request.headers.get('host'), '/long_page') diff --git a/tests/test_kafka_integration.py b/tests/test_kafka_integration.py index 384c526fe..dd21cc29f 100644 --- a/tests/test_kafka_integration.py +++ b/tests/test_kafka_integration.py @@ -6,7 +6,7 @@ from fastapi.responses import JSONResponse from frontik.app import FrontikApplication -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.options import options from frontik.routing import router from frontik.testing import FrontikTestBase @@ -38,7 +38,7 @@ async def init(self): @router.get('/kafka') -async def get_page(request: Request) -> JSONResponse: +async def get_page(request: Request, http_client: HttpClient) -> JSONResponse: rid = request.scope['tornado_request'].request_id request.app.http_client_factory.request_engine_builder.kafka_producer.enable_for_request_id(rid) diff --git a/tests/test_statsd_integration.py b/tests/test_statsd_integration.py index 2c940b997..028bb3a66 100644 --- a/tests/test_statsd_integration.py +++ b/tests/test_statsd_integration.py @@ -4,14 +4,14 @@ from tornado.escape import to_unicode from frontik.app import FrontikApplication -from frontik.dependencies import statsd_client +from frontik.dependencies import StatsDClient from frontik.options import options from frontik.routing import router from frontik.testing import FrontikTestBase @router.get('/statsd') -async def get_page() -> None: +async def get_page(statsd_client: StatsDClient) -> None: statsd_client.count('count_metric', 10, tag1='tag1', tag2='tag2') statsd_client.gauge('gauge_metric', 100, tag='tag3') statsd_client.time('time_metric', 1000, tag='tag4') diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py index c56b50723..ef58f6675 100644 --- a/tests/test_telemetry.py +++ b/tests/test_telemetry.py @@ -10,7 +10,7 @@ from frontik import request_context from frontik.app import FrontikApplication from frontik.app_integrations.telemetry import FrontikIdGenerator, get_netloc, make_otel_provider -from frontik.dependencies import http_client +from frontik.dependencies import HttpClient from frontik.options import options from frontik.routing import router from frontik.testing import FrontikTestBase @@ -67,7 +67,7 @@ def test_get_netloc(self) -> None: @router.get('/page_a') -async def get_page_a(request: Request) -> None: +async def get_page_a(request: Request, http_client: HttpClient) -> None: await http_client.get_url(request.headers.get('host'), '/page_b')