Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HH-240125' into EXP-103425
Browse files Browse the repository at this point in the history
  • Loading branch information
HH ReleaseBot committed Dec 2, 2024
2 parents 44ccd2e + b201096 commit a8075e7
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 110 deletions.
22 changes: 20 additions & 2 deletions frontik/dependencies/__init__.py
Original file line number Diff line number Diff line change
@@ -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)]
29 changes: 0 additions & 29 deletions frontik/dependencies/http_client.py

This file was deleted.

19 changes: 0 additions & 19 deletions frontik/dependencies/statsd_client.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/different_datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/no_available_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}, [])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/no_retry_error.py
Original file line number Diff line number Diff line change
@@ -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')])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/no_retry_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/profile_with_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/profile_without_retry.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/requests_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
from tests.projects.balancer_app.pages import check_all_servers_were_occupied


@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(
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_connect_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
from tests.projects.balancer_app.pages import check_all_servers_were_occupied


@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')])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_count_limit.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
from tests.projects.balancer_app.pages import check_all_servers_were_occupied


@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')])
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_non_idempotent_503.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
from tests.projects.balancer_app.pages import check_all_requests_done


@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'
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/retry_on_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/slow_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/speculative_no_retry.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/balancer_app/pages/speculative_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/test_app/pages/http_client/proxy_code.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 2 additions & 2 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading

0 comments on commit a8075e7

Please sign in to comment.