Skip to content

Commit

Permalink
Add work-pool id/name to labels donated by worker to flow run
Browse files Browse the repository at this point in the history
  • Loading branch information
bunchesofdonald committed Dec 6, 2024
1 parent 5746a98 commit 020e772
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/prefect/workers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Pending,
exception_to_failed_state,
)
from prefect.types import KeyValueLabels
from prefect.utilities.dispatch import get_registry_for_type, register_base_type
from prefect.utilities.engine import propose_state
from prefect.utilities.services import critical_service_loop
Expand Down Expand Up @@ -1222,13 +1223,20 @@ async def _give_worker_labels_to_flow_run(self, flow_run_id: UUID):
Give this worker's identifying labels to the specified flow run.
"""
if self._cloud_client:
await self._cloud_client.update_flow_run_labels(
flow_run_id,
{
"prefect.worker.name": self.name,
"prefect.worker.type": self.type,
},
)
labels: KeyValueLabels = {
"prefect.worker.name": self.name,
"prefect.worker.type": self.type,
}

if self._work_pool:
labels.update(
{
"prefect.work-pool.name": self._work_pool.name,
"prefect.work-pool.id": str(self._work_pool.id),
}
)

await self._cloud_client.update_flow_run_labels(flow_run_id, labels)

async def __aenter__(self):
self._logger.debug("Entering worker context...")
Expand Down
7 changes: 6 additions & 1 deletion tests/workers/test_base_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,12 @@ def create_run_with_deployment(state):

CloudClientMock.update_flow_run_labels.assert_awaited_once_with(
flow_run.id,
{"prefect.worker.name": worker.name, "prefect.worker.type": worker.type},
{
"prefect.worker.name": worker.name,
"prefect.worker.type": worker.type,
"prefect.work-pool.name": work_pool.name,
"prefect.work-pool.id": str(work_pool.id),
},
)


Expand Down

0 comments on commit 020e772

Please sign in to comment.