Skip to content

Commit 9b78d01

Browse files
committed
Include 'received_command_ids' and 'executed_command_ids' into heartbeat request body and backend logic
1 parent badb8ce commit 9b78d01

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

scripts/setup/postgres/gprofiler_recreate.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ CREATE TABLE HostHeartbeats (
256256
ip_address inet NOT NULL,
257257
service_name text NOT NULL,
258258
last_command_id uuid NULL,
259+
received_command_ids uuid[] NULL,
260+
executed_command_ids uuid[] NULL,
259261
status HostStatus NOT NULL DEFAULT 'active',
260262
heartbeat_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
261263
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

src/gprofiler-dev/gprofiler_dev/postgres/db_manager.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,8 @@ def upsert_host_heartbeat(
855855
ip_address: str,
856856
service_name: str,
857857
last_command_id: Optional[str] = None,
858+
received_command_ids: Optional[List[str]] = None,
859+
executed_command_ids: Optional[List[str]] = None,
858860
status: str = "active",
859861
heartbeat_timestamp: Optional[datetime] = None,
860862
) -> bool:
@@ -865,16 +867,21 @@ def upsert_host_heartbeat(
865867
query = """
866868
INSERT INTO HostHeartbeats (
867869
hostname, ip_address, service_name, last_command_id,
870+
received_command_ids, executed_command_ids,
868871
status, heartbeat_timestamp, created_at, updated_at
869872
) VALUES (
870873
%(hostname)s, %(ip_address)s::inet, %(service_name)s,
871-
%(last_command_id)s::uuid, %(status)s::HostStatus,
874+
%(last_command_id)s::uuid, %(received_command_ids)s::uuid[],
875+
%(executed_command_ids)s::uuid[],
876+
%(status)s::HostStatus,
872877
%(heartbeat_timestamp)s, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
873878
)
874879
ON CONFLICT (hostname, service_name)
875880
DO UPDATE SET
876881
ip_address = EXCLUDED.ip_address,
877882
last_command_id = EXCLUDED.last_command_id,
883+
received_command_ids = EXCLUDED.received_command_ids,
884+
executed_command_ids = EXCLUDED.executed_command_ids,
878885
status = EXCLUDED.status,
879886
heartbeat_timestamp = EXCLUDED.heartbeat_timestamp,
880887
updated_at = CURRENT_TIMESTAMP
@@ -885,6 +892,8 @@ def upsert_host_heartbeat(
885892
"ip_address": ip_address,
886893
"service_name": service_name,
887894
"last_command_id": last_command_id,
895+
"received_command_ids": received_command_ids,
896+
"executed_command_ids": executed_command_ids,
888897
"status": status,
889898
"heartbeat_timestamp": heartbeat_timestamp,
890899
}
@@ -897,6 +906,7 @@ def get_host_heartbeat(self, hostname: str) -> Optional[Dict]:
897906
query = """
898907
SELECT
899908
hostname, ip_address, service_name, last_command_id,
909+
received_command_ids, executed_command_ids,
900910
status, heartbeat_timestamp, created_at, updated_at
901911
FROM HostHeartbeats
902912
WHERE hostname = %(hostname)s
@@ -911,6 +921,7 @@ def get_active_hosts(self, service_name: Optional[str] = None) -> List[Dict]:
911921
query = """
912922
SELECT
913923
hostname, ip_address, service_name, last_command_id,
924+
received_command_ids, executed_command_ids,
914925
status, heartbeat_timestamp
915926
FROM HostHeartbeats
916927
WHERE status = 'active'
@@ -995,6 +1006,7 @@ def get_all_host_heartbeats(self, limit: Optional[int] = None, offset: Optional[
9951006
query = """
9961007
SELECT
9971008
ID, hostname, ip_address, service_name, last_command_id,
1009+
received_command_ids, executed_command_ids,
9981010
status, heartbeat_timestamp, created_at, updated_at
9991011
FROM HostHeartbeats
10001012
ORDER BY heartbeat_timestamp DESC
@@ -1024,6 +1036,7 @@ def get_host_heartbeats_by_service(self, service_name: str, limit: Optional[int]
10241036
query = f"""
10251037
SELECT
10261038
ID, hostname, ip_address, service_name, last_command_id,
1039+
received_command_ids, executed_command_ids,
10271040
status, heartbeat_timestamp, created_at, updated_at
10281041
FROM HostHeartbeats
10291042
{where_clause}
@@ -1042,6 +1055,7 @@ def get_host_heartbeats_by_status(self, status: str, limit: Optional[int] = None
10421055
query = """
10431056
SELECT
10441057
ID, hostname, ip_address, service_name, last_command_id,
1058+
received_command_ids, executed_command_ids,
10451059
status, heartbeat_timestamp, created_at, updated_at
10461060
FROM HostHeartbeats
10471061
WHERE status = %(status)s

src/gprofiler/backend/models/metrics_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ class HeartbeatRequest(BaseModel):
225225
hostname: str
226226
service_name: str
227227
last_command_id: Optional[str] = None
228+
received_command_ids: Optional[List[str]] = None
229+
executed_command_ids: Optional[List[str]] = None
228230
status: str = "active" # active, idle, error
229231
timestamp: Optional[datetime] = None
230232

src/gprofiler/backend/routers/metrics_routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ def receive_heartbeat(heartbeat: HeartbeatRequest):
702702
ip_address=heartbeat.ip_address,
703703
service_name=heartbeat.service_name,
704704
last_command_id=heartbeat.last_command_id,
705+
received_command_ids=heartbeat.received_command_ids,
706+
executed_command_ids=heartbeat.executed_command_ids,
705707
status=heartbeat.status,
706708
heartbeat_timestamp=heartbeat.timestamp,
707709
)

0 commit comments

Comments
 (0)