From 2ca2eb1e8e1a6ffbf5ca2702b276a201b1d202ac Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Thu, 17 Oct 2024 13:55:00 -0500 Subject: [PATCH] Add 'paused' label to 'prefect_info_deployments' metric (#47) * Add 'paused' label to 'prefect_info_deployments' metric - Adds the 'paused' label to the 'prefect_info_deployments' metric - Also uses this value for the 'is_schedule_active' label, which is deprecated and always returns Null. - Updates the docker-compose testing setup to use Prefect 3 Related to PLA-224 * Negate the 'paused' value for 'is_schedule_active' 'is_schedule_active' is the opposite of 'paused', so if we're using the 'paused' value we need to negate it. * Fix null case * Fix logic for negating value If we get "null" back, we don't want to `not` that because we'll always get False instead of "null". This separates the logic and only negates the value if we don't get "null" back. --- compose.yml | 2 +- metrics/metrics.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compose.yml b/compose.yml index 646b659..236348c 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,6 @@ services: prefect: - image: prefecthq/prefect:2-latest + image: prefecthq/prefect:3-latest ports: - "4200:4200" environment: diff --git a/metrics/metrics.py b/metrics/metrics.py index 58ad7e9..596ca8b 100644 --- a/metrics/metrics.py +++ b/metrics/metrics.py @@ -102,6 +102,7 @@ def collect(self): "is_schedule_active", "deployment_name", "path", + "paused", "work_pool_name", "work_queue_name", "status", @@ -122,15 +123,25 @@ def collect(self): "null", ) + # The "is_schedule_active" field is deprecated, and always returns + # "null". For backward compatibility, we will populate the value of + # this label with the "paused" field. + is_schedule_active = deployment.get("paused", "null") + if is_schedule_active != "null": + # Negate the value we get from "paused" because "is_schedule_active" + # is the opposite of "paused". + is_schedule_active = not is_schedule_active + prefect_info_deployments.add_metric( [ str(deployment.get("created", "null")), str(deployment.get("flow_id", "null")), str(flow_name), str(deployment.get("id", "null")), - str(deployment.get("is_schedule_active", "null")), + str(is_schedule_active), str(deployment.get("name", "null")), str(deployment.get("path", "null")), + str(deployment.get("paused", "null")), str(deployment.get("work_pool_name", "null")), str(deployment.get("work_queue_name", "null")), str(deployment.get("status", "null")),