Merge pull request #37 from Aignosi/fix/SIENTIAPDE-1478
Enhance API: Add optional operation_type to get_core_labels
This commit is contained in:
@@ -71,6 +71,38 @@ class API(SientiaMonitoring):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_pi_web_api_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.
|
||||||
@@ -202,7 +234,7 @@ class API(SientiaMonitoring):
|
|||||||
prediction_tags = list[str](raw_prediction_tags.values())
|
prediction_tags = list[str](raw_prediction_tags.values())
|
||||||
confidence_tags = list(raw_confidence_tags.values())
|
confidence_tags = list(raw_confidence_tags.values())
|
||||||
|
|
||||||
core_labels = self.get_core_labels(metadata)
|
core_labels = self.get_pi_web_api_core_labels(metadata)
|
||||||
|
|
||||||
prediction_value = data.head(1)['prediction'].values[0]
|
prediction_value = data.head(1)['prediction'].values[0]
|
||||||
confidence_value = data.head(1)['prediction_confidence'].values[0]
|
confidence_value = data.head(1)['prediction_confidence'].values[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user