Skip to content

Commit

Permalink
[Model Monitoring] Add application metrics to V3IO tables and endpoin…
Browse files Browse the repository at this point in the history
…ts (#5585)
  • Loading branch information
jond01 committed May 19, 2024
1 parent f4eb37a commit ffda052
Show file tree
Hide file tree
Showing 16 changed files with 791 additions and 365 deletions.
1 change: 1 addition & 0 deletions mlrun/common/schemas/model_monitoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
)
from .grafana import (
GrafanaColumn,
GrafanaColumnType,
GrafanaDataPoint,
GrafanaNumberColumn,
GrafanaStringColumn,
Expand Down
14 changes: 9 additions & 5 deletions mlrun/common/schemas/model_monitoring/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import Optional, Union

from pydantic import BaseModel

import mlrun.common.types


class GrafanaColumnType(mlrun.common.types.StrEnum):
NUMBER = "number"
STRING = "string"


class GrafanaColumn(BaseModel):
text: str
type: str


class GrafanaNumberColumn(GrafanaColumn):
text: str
type: str = "number"
type: str = GrafanaColumnType.NUMBER


class GrafanaStringColumn(GrafanaColumn):
text: str
type: str = "string"
type: str = GrafanaColumnType.STRING


class GrafanaTable(BaseModel):
Expand Down
23 changes: 17 additions & 6 deletions mlrun/common/schemas/model_monitoring/model_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ class ModelEndpointList(BaseModel):

class ModelEndpointMonitoringMetricType(mlrun.common.types.StrEnum):
RESULT = "result"
METRIC = "metric"


class ModelEndpointMonitoringMetric(BaseModel):
Expand All @@ -322,7 +323,7 @@ def _compose_full_name(
_FQN_PATTERN = (
rf"^(?P<project>{_FQN_PART_PATTERN})\."
rf"(?P<app>{_FQN_PART_PATTERN})\."
rf"(?P<type>{_FQN_PART_PATTERN})\."
rf"(?P<type>{ModelEndpointMonitoringMetricType.RESULT}|{ModelEndpointMonitoringMetricType.METRIC})\."
rf"(?P<name>{_FQN_PART_PATTERN})$"
)
_FQN_REGEX = re.compile(_FQN_PATTERN)
Expand All @@ -337,27 +338,37 @@ def _parse_metric_fqn_to_monitoring_metric(fqn: str) -> ModelEndpointMonitoringM
)


class _MetricPoint(NamedTuple):
timestamp: datetime
value: float


class _ResultPoint(NamedTuple):
timestamp: datetime
value: float
status: ResultStatusApp


class _ModelEndpointMonitoringResultValuesBase(BaseModel):
class _ModelEndpointMonitoringMetricValuesBase(BaseModel):
full_name: str
type: ModelEndpointMonitoringMetricType
data: bool


class ModelEndpointMonitoringResultValues(_ModelEndpointMonitoringResultValuesBase):
full_name: str
type: ModelEndpointMonitoringMetricType
class ModelEndpointMonitoringMetricValues(_ModelEndpointMonitoringMetricValuesBase):
type: ModelEndpointMonitoringMetricType = ModelEndpointMonitoringMetricType.METRIC
values: list[_MetricPoint]
data: bool = True


class ModelEndpointMonitoringResultValues(_ModelEndpointMonitoringMetricValuesBase):
type: ModelEndpointMonitoringMetricType = ModelEndpointMonitoringMetricType.RESULT
result_kind: ResultKindApp
values: list[_ResultPoint]
data: bool = True


class ModelEndpointMonitoringResultNoData(_ModelEndpointMonitoringResultValuesBase):
class ModelEndpointMonitoringMetricNoData(_ModelEndpointMonitoringMetricValuesBase):
full_name: str
type: ModelEndpointMonitoringMetricType
data: bool = False
Expand Down
19 changes: 16 additions & 3 deletions mlrun/model_monitoring/db/stores/base/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import typing
from abc import ABC, abstractmethod

import mlrun.common.schemas.model_monitoring.constants as mm_constants
import mlrun.common.schemas.model_monitoring as mm_schemas


class StoreBase(ABC):
Expand Down Expand Up @@ -115,8 +115,8 @@ def list_model_endpoints(
def write_application_event(
self,
event: dict[str, typing.Any],
kind: mm_constants.WriterEventKind = mm_constants.WriterEventKind.RESULT,
):
kind: mm_schemas.WriterEventKind = mm_schemas.WriterEventKind.RESULT,
) -> None:
"""
Write a new event in the target table.
Expand Down Expand Up @@ -157,3 +157,16 @@ def update_last_analyzed(
"""
pass

@abstractmethod
def get_model_endpoint_metrics(
self, endpoint_id: str, type: mm_schemas.ModelEndpointMonitoringMetricType
) -> list[mm_schemas.ModelEndpointMonitoringMetric]:
"""
Get the model monitoring results and metrics of the requested model endpoint.
:param: endpoint_id: The model endpoint identifier.
:param: type: The type of the requested metrics ("result" or "metric").
:return: A list of the available metrics.
"""
Loading

0 comments on commit ffda052

Please sign in to comment.