Private/issue 1096 api latency logging#1965
Draft
ljluestc wants to merge 15 commits into
Draft
Conversation
Adds identical ChatGPT-style interface from kubernetes_rag, served at /chatgpt-ui/ with SSO and knowledge graph integration.
Describe MCP entry, REST API, execute_search_flow DAG construction, FlowEngine (topological sort, parallel groups), and retrieval runners. Made-with: Cursor
… label) (apecloud#1456) GitHub Mermaid treats unquoted { as diamond node start; use <collection_id> in quoted edge text and add a short note linking to OpenAPI path form. Made-with: Cursor
* docs: remove hosted live demo line from README Drop the "Try ApeRAG Live Demo" promotional line; README still documents self-hosted usage and MCP examples. Made-with: Cursor * docs: align zh README and integration examples with self-hosted URLs - Remove Chinese hosted-demo line from README-zh.md - Use localhost MCP URL in README & MCP API examples; Dify guide points to Quick Start + local web/API instead of a fixed public host Made-with: Cursor
Closes apecloud#1096 ## Log and Store API Latency - Add LatencyLoggingMiddleware (aperag/middleware/latency.py) that wraps every HTTP request, logs 'METHOD path status Nms' at INFO level, and sets an X-Response-Time response header. Health/docs paths are logged at DEBUG to reduce noise. - Add duration_ms column (BigInteger, nullable) to AuditLog so the pre-computed latency is stored alongside start_time/end_time. An index on duration_ms makes slow-request queries efficient. - audit_service.log_audit() now computes duration_ms = end_time - start_time before opening the DB session, emits a structured INFO log line ('audit METHOD path api_name status=N duration_ms=N'), and stores the value in the new column. - audit_decorator.audit() logs 'api METHOD path (api_name) status=200 duration_ms=N' immediately after each decorated endpoint returns, giving a per-endpoint latency line independently of the async DB write. - list_audit_logs sort_mapping now uses AuditLog.duration_ms (a real column) instead of the SQL expression end_time - start_time. Existing NULL rows are back-filled on the fly during listing. ## Refactor Long Operations Out of Session Context - Replace the 'async for session in get_async_session(): ... break' antipattern in audit_service with async with self._make_session(), which uses SQLAlchemy's AsyncSession context manager directly. - All expensive work (JSON serialisation, duration calculation, resource ID extraction) is now performed outside the session so DB connections are held only for the actual INSERT/SELECT. ## Migration aperag/migration/versions/20251001120000-add_duration_ms_to_audit_log.py adds the column and index; downgrade removes both.
… decorator - tests/unit/test_latency_middleware.py: 6 tests for LatencyLoggingMiddleware covering X-Response-Time header presence/format, body preservation, INFO vs DEBUG log level for normal vs skip paths, and log line content. - tests/unit/test_audit_service.py: 6 tests for AuditService verifying duration_ms computation, DB persistence, commit lifecycle, error swallowing, and list_audit_logs back-fill for legacy rows. - tests/unit/test_audit_decorator.py: 6 tests for the @Audit decorator covering start/end time recording, non-negative duration, status 200 on success, status 500 + re-raise on error, GET-request skip, and api_name defaulting to the function name. - Fix latency.py: initialise response=None before the try block and guard the X-Response-Time header assignment so the finally branch does not raise NameError when call_next raises before returning a Response.
Co-Authored-By: Oz <oz-agent@warp.dev>
…d 720px min height
- Add search_entities() and get_embedding_map() methods to GraphService
- Add workspace endpoints: GET /collections/{id}/graphs/embedding-map and entity-search
- Create aperag/domains/marketplace/api/routes.py with read-only marketplace
versions of embedding-map and entity-search (resolves to owner's user_id)
- Register new marketplace domain router in aperag/app.py
- Update OpenAPI specs with path entries for all four new endpoints
- Add make openapi-check target (redocly bundle structural validation)
- Create CollectionGraphHybrid component wrapping CollectionGraph with
marketplace data-source switching and 720px min-height layout
- Update marketplace /graph page to use CollectionGraphHybrid
- Change h-[calc(...)] to min-h-[calc(...)] on both workspace and marketplace
graph pages so shorter screens can scroll instead of compressing the canvas
Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates marketplace collection graph pages to use marketplace-safe graph APIs and improves graph page layout behavior on shorter screens.
What changed
/graphpage with the new graph-hybrid view.embedding-mapandentity-searchso published marketplace collections do not call workspace-only graph APIs.CollectionGraphHybridswitch between workspace and marketplace data sources.Why
Marketplace collection graph pages should not depend on workspace-only APIs. This change introduces marketplace-safe read-only graph endpoints and updates frontend routing/data-source behavior so graph rendering works correctly for published collections while preserving workspace behavior.
Validation
make openapi-checkuv run ruff check aperag/domains/marketplace/api/routes.pyyarn type-checkyarn lint(passes with pre-existing unrelated warnings)