-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aiokitchen/feature/metrics
Add metrics to pool
- Loading branch information
Showing
28 changed files
with
596 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,10 @@ jobs: | |
|
||
matrix: | ||
toxenv: | ||
- py37 | ||
- py38 | ||
- py39 | ||
- py310 | ||
- py311 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
authors = ( | ||
("Vladislav Bakaev", "[email protected]"), | ||
("Dmitry Orlov", "[email protected]"), | ||
("Pavel Mosein", "[email protected]"), | ||
) | ||
|
||
authors_email = ", ".join(email for _, email in authors) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
from typing import Sequence | ||
|
||
import aiopg.sa | ||
from psycopg2.extensions import parse_dsn | ||
|
||
from hasql.aiopg import PoolManager as AioPgPoolManager | ||
from hasql.metrics import DriverMetrics | ||
from hasql.utils import Dsn | ||
|
||
|
||
class PoolManager(AioPgPoolManager): | ||
pools: Sequence[aiopg.sa.Engine] # type: ignore[assignment] | ||
|
||
async def _is_master(self, connection): | ||
read_only = await connection.scalar("SHOW transaction_read_only") | ||
return read_only == "off" | ||
|
||
async def _pool_factory(self, dsn: Dsn): | ||
async def _pool_factory(self, dsn: Dsn) -> aiopg.sa.Engine: | ||
return await aiopg.sa.create_engine( | ||
str(dsn), | ||
**self.pool_factory_kwargs, | ||
) | ||
|
||
def host(self, pool: aiopg.sa.Engine) -> str: # type: ignore[override] | ||
return parse_dsn(pool.dsn).get("host", "") | ||
|
||
def _driver_metrics(self) -> Sequence[DriverMetrics]: | ||
return [ | ||
DriverMetrics( | ||
max=p.maxsize, | ||
min=p.minsize, | ||
idle=p.freesize, | ||
used=p.size - p.freesize, | ||
host=parse_dsn(p.dsn).get("host", ""), | ||
) for p in self.pools | ||
] | ||
|
||
|
||
__all__ = ("PoolManager",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.