Refactor: Migrate dynamic profiling endpoints to dedicated router #42
+611
−558
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.
Refactor: Separate Dynamic Profiling Endpoints from Metrics Router
Summary
This PR refactors the API routing structure by moving dynamic profiling endpoints from
metrics_routes.pyinto a dedicateddynamicprofiling.pyrouter. The change maintains complete backward compatibility by registering the new router under both/dynamicprofiling(new) and/metrics(legacy) prefixes until we make changes on agent side.Motivation
Problem:
metrics_routes.pySolution:
dynamicprofiling.pyrouterChanges
Files Modified
1. NEW:
src/gprofiler/backend/routers/dynamicprofiling.pyComplete router with 4 endpoints migrated from metrics_routes:
/profile_request/heartbeat/command_completion/profiling/host_statusIncludes:
profiling_host_status_params,_create_slack_blocks)2. MODIFIED:
src/gprofiler/backend/routers/metrics_routes.pyRemoved:
Retained:
/instance_type_count,/samples,/graph,/function_cpu/graph/nodes_and_cores,/summary,/nodes_cores/summary/cpu_trend,/html_metadataResult: 794 → 236 lines (70% reduction)
3. MODIFIED:
src/gprofiler/backend/routers/__init__.pyAdded:
API Changes
Endpoint Migration Table
POST /api/metrics/profile_requestPOST /api/dynamicprofiling/profile_requestPOST /api/metrics/heartbeatPOST /api/dynamicprofiling/heartbeatPOST /api/metrics/command_completionPOST /api/dynamicprofiling/command_completionGET /api/metrics/profiling/host_statusGET /api/dynamicprofiling/profiling/host_statusBackward Compatibility
✅ Zero Breaking Changes
FastAPI allows registering the same router under multiple prefixes:
/api/metrics/*and/api/dynamicprofiling/*call the same functionMetrics Endpoints
✅ Unchanged and Unaffected
All metrics endpoints remain at
/api/metrics/*:/api/metrics/samples/api/metrics/graph/api/metrics/cpu_trendBenefits
Code Quality
API Design
/dynamicprofilingclearly indicates purpose)Backward Compatibility
Testing
Environment
Test Results
8 endpoints tested (4 types × 2 paths):
/metrics/profile_request/dynamicprofiling/profile_request/metrics/heartbeat/dynamicprofiling/heartbeat/metrics/command_completion/dynamicprofiling/command_completion/metrics/profiling/host_status/dynamicprofiling/profiling/host_status?service_name=testAdditional Validation:
Example Test Commands
Migration Path
Phase 1 (This PR)
/metrics/*/dynamicprofiling/*Phase 2 (Future)
/metrics/profile_request, etc.Phase 3 (Future, after agent migration)
/dynamicprofiling/*remainsDeveloper Impact
For Agent Developers
Current agents: No changes required. Code continues to work.
New agents: Can use cleaner API.
For Backend Developers
Where to add new features:
metrics_routes.pydynamicprofiling.pyClear separation makes it obvious where code belongs.
Rollback Plan
If issues arise:
Option 1: Git Revert
Option 2: Manual Rollback (< 10 minutes)
dynamicprofiling.pytometrics_routes.pydynamicprofiling.py__init__.pyTechnical Details
Implementation
No Code Duplication:
Performance:
Security:
File Statistics
Documentation
/api/v1/docs(shows both paths)/api/v1/openapi.jsonheartbeat_doc/README_HEARTBEAT.md