From c2864d3806799aafe16316a274ae9773715a3573 Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Wed, 11 Feb 2026 10:11:28 -0300 Subject: [PATCH] SIENTIAPDE-1478 Enhance API class with optional operation_type in get_core_labels method - Added a new method get_core_labels to the API class that generates core labels for metrics. - Introduced an optional operation_type parameter to control the inclusion of the operation_type key in the returned labels. - Maintained compatibility with the base implementation while providing flexibility for metrics without the operation_type label. --- laborious/activities/api.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/laborious/activities/api.py b/laborious/activities/api.py index 1ad3059..eb31b73 100644 --- a/laborious/activities/api.py +++ b/laborious/activities/api.py @@ -71,6 +71,38 @@ class API(SientiaMonitoring): }, ) + def get_core_labels( + self, + metadata: dict[str, Any], + operation_type: str | None = None, + ) -> dict[str, Any]: + """ + Generate core labels for metrics, optionally including operation_type. + + This override keeps compatibility with the base implementation while adding + a convenience overload behavior: + - When operation_type is provided, it behaves exactly like the base class, + returning labels that include the operation_type key. + - When operation_type is omitted (None), it removes the operation_type key + from the resulting labels. This is useful for metrics, such as the PI Web + API metrics, that are defined without the operation_type label. + + Args: + - metadata (dict[str, Any]): Workflow execution metadata used to derive labels + - operation_type (str | None): Optional operation type label. If None, the + operation_type key will be removed from the returned labels. + + Return: + dict[str, Any]: Core labels dictionary, with operation_type only when provided + """ + base_labels = super().get_core_labels( + metadata=metadata, + operation_type=operation_type or '-', + ) + if operation_type is None: + base_labels.pop('operation_type', None) + return base_labels + def close(self) -> None: """ Close the PI Web API client and shutdown monitoring services.