Skip to content

Commit

Permalink
[fix] Signature and log level
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Mar 28, 2024
1 parent 0fab4aa commit 170c0bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fixbackend/inventory/inventory_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def overall_score(accounts: Dict[str, AccountSummary]) -> int:
except InventoryException as ex:
# in case no account is collected yet -> no graph, this is expected.
if not isinstance(ex, NoSuchGraph):
log.warning(f"Inventory not available yet: {ex}. Returning empty summary.")
log.info(f"Inventory not available yet: {ex}. Returning empty summary.")
empty = CheckSummary(
available_checks=0,
failed_checks=0,
Expand Down
21 changes: 17 additions & 4 deletions fixbackend/sqlalechemy_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime, timezone
from typing import Optional, Any, Type
from typing import Optional, Any, Type, Dict

import cattrs
import sqlalchemy as sa
from fixcloudutils.asyncio.timed import perf_now
from fixcloudutils.types import JsonElement
from prometheus_client import Histogram, Gauge
from pydantic import BaseModel
from sqlalchemy import Connection, event
from sqlalchemy import Connection, event, ClauseElement
from sqlalchemy.ext.asyncio import AsyncEngine
from fastapi_users_db_sqlalchemy import GUID as FastApiUsersGUID # type: ignore

Expand Down Expand Up @@ -93,12 +93,25 @@ class EngineMetrics:
DbConnections = Gauge("db_connections", "Number of active DB connections")

@classmethod
def before_execute(cls, connection: Connection, clause: Any, multiparams: Any, params: Any) -> None: # noqa
def before_execute(
cls,
connection: Connection,
clauseelement: ClauseElement,
multiparams: Any,
params: Any,
execution_options: Dict[Any, Any],
) -> None:
connection.info.setdefault(cls.query_start_time, []).append(perf_now())

@classmethod
def after_execute(
cls, connection: Connection, clause: Any, multiparams: Any, params: Any, result: Any # noqa
cls,
connection: Connection,
clauseelement: ClauseElement,
multiparams: Any,
params: Any,
execution_options: Dict[Any, Any],
result: Any,
) -> None:
start_time = connection.info[cls.query_start_time].pop()
cls.DbStatementDuration.observe(perf_now() - start_time)
Expand Down

0 comments on commit 170c0bc

Please sign in to comment.