Skip to content

Commit 68cd5d8

Browse files
Fixed review comments
1 parent 0a39c1e commit 68cd5d8

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/gprofiler/backend/models/metrics_models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ def validate_status(cls, v):
203203
return v
204204

205205

206+
class ProfilingHostStatusRequest(BaseModel):
207+
"""Model for profiling host status request parameters"""
208+
209+
service_name: Optional[str] = None
210+
exact_match: bool = False
211+
212+
206213
class ProfilingHostStatus(BaseModel):
207214
id: int
208215
service_name: str
@@ -212,4 +219,3 @@ class ProfilingHostStatus(BaseModel):
212219
command_type: str
213220
profiling_status: str
214221
heartbeat_timestamp: datetime
215-
profiling_link: Optional[str] = None # New field for contextual profiling link

src/gprofiler/backend/routers/metrics_routes.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
MetricNodesCoresSummary,
3737
MetricSummary,
3838
ProfilingHostStatus,
39+
ProfilingHostStatusRequest,
3940
ProfilingRequest,
4041
ProfilingResponse,
4142
SampleCount,
4243
)
4344
from backend.utils.filters_utils import get_rql_first_eq_key, get_rql_only_for_one_key
4445
from backend.utils.request_utils import flamegraph_base_request_params, get_metrics_response, get_query_response
4546
from botocore.exceptions import ClientError
46-
from fastapi import APIRouter, Depends, HTTPException, Query, Request
47+
from fastapi import APIRouter, Depends, HTTPException, Query
4748
from fastapi.responses import Response
4849
from gprofiler_dev import S3ProfileDal
4950
from gprofiler_dev.postgres.db_manager import DBManager
@@ -80,6 +81,13 @@ def get_time_interval_value(start_time: datetime, end_time: datetime, interval:
8081
return "24 hours"
8182

8283

84+
def profiling_host_status_params(
85+
service_name: Optional[str] = Query(None, description="Filter by service name"),
86+
exact_match: bool = Query(False, description="Use exact match for service name (default: false for partial matching)"),
87+
) -> ProfilingHostStatusRequest:
88+
return ProfilingHostStatusRequest(service_name=service_name, exact_match=exact_match)
89+
90+
8391
@router.get("/instance_type_count", response_model=List[InstanceTypeCount])
8492
def get_instance_type_count(fg_params: FGParamsBaseModel = Depends(flamegraph_base_request_params)):
8593
response = get_query_response(fg_params, lookup_for="instance_type_count")
@@ -636,25 +644,22 @@ def report_command_completion(completion: CommandCompletionRequest):
636644

637645
@router.get("/profiling/host_status", response_model=List[ProfilingHostStatus])
638646
def get_profiling_host_status(
639-
service_name: Optional[str] = Query(None, description="Filter by service name"),
640-
exact_match: bool = Query(False, description="Use exact match for service name (default: false for partial matching)"),
641-
request: Request = None
647+
profiling_params: ProfilingHostStatusRequest = Depends(profiling_host_status_params),
642648
):
643649
"""
644650
Get profiling host status with optional service name filtering.
645651
646652
Args:
647-
service_name: Optional service name to filter results (supports partial matching by default)
648-
exact_match: If true, use exact matching; if false, use partial case-insensitive matching
653+
profiling_params: ProfilingHostStatusRequest object containing service name and exact match flag
649654
650655
Returns:
651-
List of host statuses with dynamic profiling links
656+
List of host statuses
652657
"""
653658
db_manager = DBManager()
654659

655660
# Get hosts - filter by service_name if provided
656-
if service_name:
657-
hosts = db_manager.get_host_heartbeats_by_service(service_name, exact_match=exact_match)
661+
if profiling_params.service_name:
662+
hosts = db_manager.get_host_heartbeats_by_service(profiling_params.service_name, exact_match=profiling_params.exact_match)
658663
else:
659664
hosts = db_manager.get_all_host_heartbeats()
660665

@@ -674,10 +679,6 @@ def get_profiling_host_status(
674679
profiling_status = "stopped"
675680
command_type = "N/A"
676681

677-
# Generate dynamic profiling link with service filter
678-
base_url = str(request.base_url).rstrip('/') if request else ""
679-
profiling_link = f"{base_url}/profiling?service={host_service_name}&hostname={hostname}"
680-
681682
results.append(
682683
ProfilingHostStatus(
683684
id=host.get("id", 0),
@@ -688,7 +689,6 @@ def get_profiling_host_status(
688689
command_type=command_type,
689690
profiling_status=profiling_status,
690691
heartbeat_timestamp=host.get("heartbeat_timestamp"),
691-
profiling_link=profiling_link, # New field for contextual link
692692
)
693693
)
694694

0 commit comments

Comments
 (0)