mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Clean up all timing/debug logs
Remove all [MCP-TIMING] and [CTRL-TIMING] log lines, timing middleware, and related import time statements across 11 files.
This commit is contained in:
11 files changed
+1
-79
No files matched your search
@@ -45,7 +45,6 @@ async def get_user_from_token(
|
||||
|
||||
import time
|
||||
_t0 = time.time()
|
||||
log.info(f"[CTRL-TIMING] get_user_from_token ENTER bearer={bool(bearer_token)}")
|
||||
|
||||
if bearer_token:
|
||||
# bearer token is used first, then any token passed as a URL parameter
|
||||
@@ -61,7 +60,6 @@ async def get_user_from_token(
|
||||
# API Key authentication — format: gns3_<api_key_id>_<random_secret>
|
||||
# Direct lookup by UUID avoids O(n) scan of all keys.
|
||||
if token.startswith("gns3_"):
|
||||
log.info(f"[CTRL-TIMING] get_user_from_token API_KEY auth elapsed={time.time()-_t0:.3f}s")
|
||||
parts = token.split("_", 2)
|
||||
if len(parts) != 3:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid API key format")
|
||||
@@ -100,7 +98,6 @@ async def get_user_from_token(
|
||||
detail=f"Token has been revoked for '{token_data.username}'",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
log.info(f"[CTRL-TIMING] get_user_from_token DONE elapsed={time.time()-_t0:.3f}s user={user.username}")
|
||||
return user
|
||||
|
||||
|
||||
|
||||
@@ -30,10 +30,8 @@ async def get_db_session(request: HTTPConnection) -> AsyncSession:
|
||||
|
||||
import time
|
||||
_t0 = time.time()
|
||||
log.info(f"[CTRL-TIMING] get_db_session ENTER")
|
||||
async with AsyncSession(request.app.state._db_engine, expire_on_commit=False) as session:
|
||||
try:
|
||||
log.info(f"[CTRL-TIMING] get_db_session SESSION_READY elapsed={time.time()-_t0:.3f}s")
|
||||
yield session
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
@@ -609,12 +609,9 @@ async def create_node_from_template(
|
||||
|
||||
Required privilege: Node.Allocate
|
||||
"""
|
||||
import time as _time
|
||||
_t0 = _time.time()
|
||||
log.info(f"[CTRL-TIMING] create_node_from_template ENTER template_id={template_id}")
|
||||
|
||||
template = await TemplatesService(templates_repo).get_template(template_id)
|
||||
log.info(f"[CTRL-TIMING] get_template done elapsed={_time.time()-_t0:.3f}s")
|
||||
|
||||
controller = Controller.instance()
|
||||
project = controller.get_project(str(project_id))
|
||||
@@ -622,8 +619,6 @@ async def create_node_from_template(
|
||||
node = await project.add_node_from_template(
|
||||
template, x=template_usage.x, y=template_usage.y, compute_id=template_usage.compute_id
|
||||
)
|
||||
log.info(f"[CTRL-TIMING] add_node_from_template done elapsed={_time.time()-_t0:.3f}s")
|
||||
|
||||
result = node.asdict()
|
||||
log.info(f"[CTRL-TIMING] create_node_from_template DONE total={_time.time()-_t0:.3f}s")
|
||||
return result
|
||||
@@ -205,7 +205,6 @@ def _filter_node_response(node: dict, fields: list[str] = None) -> dict:
|
||||
def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
||||
import time
|
||||
_t0 = time.time()
|
||||
log.info(f"[MCP-TIMING] create_node_handler ENTER at T={_t0:.3f}")
|
||||
|
||||
project_id = params.get("project_id")
|
||||
if not project_id:
|
||||
@@ -219,7 +218,6 @@ def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
||||
if nodes is not None:
|
||||
if not isinstance(nodes, list) or not nodes:
|
||||
return {"error": "nodes must be a non-empty array"}
|
||||
log.info(f"[MCP-TIMING] batch mode: {len(nodes)} nodes, handler_setup={time.time()-_t0:.3f}s")
|
||||
default_tid = params.get("template_id")
|
||||
results = []
|
||||
conn = _get_connector(gns3_ctx)
|
||||
@@ -238,22 +236,17 @@ def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
||||
node_name = node_data.get("name")
|
||||
if node_name:
|
||||
body["name"] = node_name
|
||||
log.info(f"[MCP-TIMING] http_call START tid={tid} name={node_name} setup={time.time()-_t1:.3f}s")
|
||||
resp = conn.http_call("post", url, json_data=body).json()
|
||||
log.info(f"[MCP-TIMING] http_call END tid={tid} elapsed={time.time()-_t1:.3f}s")
|
||||
return {"template_id": tid, "status": "success", "node": _filter_node_response(resp, fields)}
|
||||
except Exception as e:
|
||||
log.error(f"[MCP-TIMING] http_call FAIL tid={tid} elapsed={time.time()-_t1:.3f}s error={e}")
|
||||
return {"template_id": tid, "status": "error", "error": str(e)}
|
||||
with ThreadPoolExecutor(max_workers=min(len(nodes), BATCH_MAX_WORKERS)) as pool:
|
||||
futures = {pool.submit(_create_one, n): n for n in nodes}
|
||||
for future in as_completed(futures):
|
||||
results.append(future.result())
|
||||
log.info(f"[MCP-TIMING] batch done: {len(results)} results, total={time.time()-_t0:.3f}s")
|
||||
return results
|
||||
|
||||
# Single mode
|
||||
log.info(f"[MCP-TIMING] single mode: handler_setup={time.time()-_t0:.3f}s")
|
||||
template_id = params.get("template_id")
|
||||
if not template_id:
|
||||
return {"error": "template_id is required"}
|
||||
@@ -268,9 +261,7 @@ def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
||||
data["name"] = node_name
|
||||
url = f"{conn.base_url}/projects/{project_id}/templates/{template_id}"
|
||||
_t2 = time.time()
|
||||
log.info(f"[MCP-TIMING] http_call START single template_id={template_id} setup={_t2-_t0:.3f}s")
|
||||
resp = conn.http_call("post", url, json_data=data).json()
|
||||
log.info(f"[MCP-TIMING] http_call END single elapsed={time.time()-_t2:.3f}s, total={time.time()-_t0:.3f}s")
|
||||
return _filter_node_response(resp, fields)
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ from gns3server.api.routes import mcp
|
||||
from gns3server.core import tasks
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -215,23 +214,7 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
|
||||
content={"message": str(exc)}
|
||||
)
|
||||
|
||||
@app.middleware("http")
|
||||
async def timing_middleware(request: Request, call_next):
|
||||
_t0 = time.time()
|
||||
response = await call_next(request)
|
||||
elapsed = time.time() - _t0
|
||||
if elapsed > 1.0:
|
||||
log.info(f"[CTRL-TIMING] request {request.method} {request.url.path} total={elapsed:.3f}s")
|
||||
return response
|
||||
|
||||
# FIXME: do not use this middleware since it creates issue when using StreamingResponse
|
||||
# see https://starlette-context.readthedocs.io/en/latest/middleware.html#why-are-there-two-middlewares-that-do-the-same-thing
|
||||
|
||||
# @app.middleware("http")
|
||||
# async def add_extra_headers(request: Request, call_next):
|
||||
# start_time = time.time()
|
||||
# response = await call_next(request)
|
||||
# process_time = time.time() - start_time
|
||||
# response.headers["X-Process-Time"] = str(process_time)
|
||||
# response.headers["X-GNS3-Server-Version"] = f"{__version__}"
|
||||
# return response
|
||||
Reference in new issue
Block a user