mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +02:00
Add detailed timing logs to MCP node creation and HTTP client
Logs with [MCP-TIMING] prefix at: - create_node_handler entry, setup, http_call start/end, total - http_call entry, auth, response - _authenticate_v3 entry, done, fail
This commit is contained in:
2 files changed
+30
No files matched your search
@@ -49,6 +49,7 @@ Upstream: https://github.com/davidban77/gns3fy
|
||||
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
from collections.abc import Callable
|
||||
from dataclasses import field
|
||||
from functools import wraps
|
||||
@@ -75,6 +76,8 @@ F = TypeVar("F", bound=Callable[..., Any])
|
||||
|
||||
config = ConfigDict(validate_assignment=True, extra="ignore")
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
NODE_TYPES = [
|
||||
"cloud",
|
||||
"nat",
|
||||
@@ -211,6 +214,9 @@ class Gns3Connector:
|
||||
Performs v3 API authentication using username and password to get JWT token.
|
||||
Skips authentication if a JWT token is already provided.
|
||||
"""
|
||||
import time
|
||||
_t0 = time.time()
|
||||
log.info(f"[MCP-TIMING] _authenticate_v3 ENTER has_token={bool(self.access_token)}")
|
||||
# If token is already provided, skip authentication
|
||||
if self.access_token:
|
||||
return
|
||||
@@ -249,7 +255,9 @@ class Gns3Connector:
|
||||
f"{response.text}"
|
||||
)
|
||||
except Exception as e:
|
||||
log.error(f"[MCP-TIMING] _authenticate_v3 FAIL elapsed={time.time()-_t0:.3f}s error={e}")
|
||||
raise HTTPError(f"v3 API authentication error: {str(e)}") from e
|
||||
log.info(f"[MCP-TIMING] _authenticate_v3 DONE elapsed={time.time()-_t0:.3f}s")
|
||||
|
||||
def _is_token_expired(self) -> bool:
|
||||
"""
|
||||
@@ -291,6 +299,10 @@ class Gns3Connector:
|
||||
"""
|
||||
Executes HTTP operations and handles GNS3-specific error logic.
|
||||
"""
|
||||
import time
|
||||
_t0 = time.time()
|
||||
log.info(f"[MCP-TIMING] http_call ENTER {method.upper()} {url.split('/v3')[1] if '/v3' in url else url}")
|
||||
|
||||
# Handle JWT authentication
|
||||
if (
|
||||
self.auth_type == "jwt"
|
||||
@@ -299,6 +311,7 @@ class Gns3Connector:
|
||||
and self.cred
|
||||
):
|
||||
self._authenticate_v3()
|
||||
log.info(f"[MCP-TIMING] http_call auth done elapsed={time.time()-_t0:.3f}s")
|
||||
|
||||
# Get request function (e.g., session.get, session.post)
|
||||
caller = getattr(self.session, method.lower())
|
||||
@@ -320,9 +333,12 @@ class Gns3Connector:
|
||||
|
||||
self.api_calls += 1
|
||||
|
||||
log.info(f"[MCP-TIMING] http_call RESPONSE elapsed={time.time()-_t0:.3f}s status={_response.status_code}")
|
||||
|
||||
try:
|
||||
_response.raise_for_status()
|
||||
except HTTPError as e:
|
||||
log.error(f"[MCP-TIMING] http_call ERROR elapsed={time.time()-_t0:.3f}s {e}")
|
||||
# Throw enhanced error
|
||||
raise self._extract_gns3_error(e) from e
|
||||
|
||||
|
||||
Reference in new issue
Block a user