Commit eb3a357c authored by dmitry.mashoshin's avatar dmitry.mashoshin
Browse files

Merge branch 'kpn/4/param_for_web.TCPSite' into 'master'

feat: #4 add proxy param for web.TCPSite

See merge request !15
parents f7e26736 51ac989e
import asyncio
import signal
from typing import Any
from aiohttp import web
import prometheus_client
......@@ -24,7 +25,7 @@ async def metrics(request):
class AioAppWrapper:
def __init__(self, _app, _port, _loop, **kwargs):
def __init__(self, _app, _port: int, _loop, **kwargs: Any):
self.app = _app
self.port = _port
self.loop = _loop
......@@ -33,10 +34,12 @@ class AioAppWrapper:
async def initialize(self):
LOG.info(f'Initialize web app on port {self.port}')
tcp_params = {}
if isinstance(self.runner_kwargs.get('tcp_params'), dict):
tcp_params = self.runner_kwargs.get('tcp_params', {})
self.runner = web.AppRunner(self.app, **self.runner_kwargs)
await self.runner.setup()
site = web.TCPSite(self.runner, '0.0.0.0', self.port)
site = web.TCPSite(self.runner, '0.0.0.0', self.port, **tcp_params)
await site.start()
while True:
await asyncio.sleep(3600)
......@@ -68,6 +71,11 @@ class CoroutineWrapper:
class ApplicationWrapper:
"""Application wrapper for exporting metrics on prometheus
Args:
_loop (:obj:, optional): Event loop
"""
def __init__(self, _loop=None):
self.loop = _loop
self.apps = []
......@@ -78,7 +86,22 @@ class ApplicationWrapper:
self.add_web_app(init_mertics_app(), _port=9091)
def add_web_app(self, _app, _port, **kwargs):
def add_web_app(self, _app: web.Application, _port: int, **kwargs: Any) -> None:
"""Add Application for start list
Args:
_app (obj): Application
_port (int): Application PORT to listed
**kwargs: Arbitrary keyword arguments.
Returns:
None
Examples:
kwargs[tcp_params] - for setup TCPSite params
tcp_params={
'backlog': 256,
'reuse_address': True,
'reuse_port': True
}
"""
_app._set_loop(self.loop)
self.apps.append(
AioAppWrapper(_app, _port, self.loop, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment