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.
This commit is contained in:
vitor-aignosi
2026-02-11 10:11:28 -03:00
parent 33db5fcb69
commit c2864d3806

View File

@@ -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: def close(self) -> None:
""" """
Close the PI Web API client and shutdown monitoring services. Close the PI Web API client and shutdown monitoring services.