mlrun 1.7.0rc4__py3-none-any.whl → 1.7.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mlrun might be problematic. Click here for more details.
- mlrun/__init__.py +11 -1
- mlrun/__main__.py +39 -121
- mlrun/{datastore/helpers.py → alerts/__init__.py} +2 -5
- mlrun/alerts/alert.py +248 -0
- mlrun/api/schemas/__init__.py +4 -3
- mlrun/artifacts/__init__.py +8 -3
- mlrun/artifacts/base.py +39 -254
- mlrun/artifacts/dataset.py +9 -190
- mlrun/artifacts/manager.py +73 -46
- mlrun/artifacts/model.py +30 -158
- mlrun/artifacts/plots.py +23 -380
- mlrun/common/constants.py +73 -1
- mlrun/common/db/sql_session.py +3 -2
- mlrun/common/formatters/__init__.py +21 -0
- mlrun/common/formatters/artifact.py +46 -0
- mlrun/common/formatters/base.py +113 -0
- mlrun/common/formatters/feature_set.py +44 -0
- mlrun/common/formatters/function.py +46 -0
- mlrun/common/formatters/pipeline.py +53 -0
- mlrun/common/formatters/project.py +51 -0
- mlrun/common/formatters/run.py +29 -0
- mlrun/common/helpers.py +11 -1
- mlrun/{runtimes → common/runtimes}/constants.py +32 -4
- mlrun/common/schemas/__init__.py +31 -4
- mlrun/common/schemas/alert.py +202 -0
- mlrun/common/schemas/api_gateway.py +196 -0
- mlrun/common/schemas/artifact.py +28 -1
- mlrun/common/schemas/auth.py +13 -2
- mlrun/common/schemas/client_spec.py +2 -1
- mlrun/common/schemas/common.py +7 -4
- mlrun/common/schemas/constants.py +3 -0
- mlrun/common/schemas/feature_store.py +58 -28
- mlrun/common/schemas/frontend_spec.py +8 -0
- mlrun/common/schemas/function.py +11 -0
- mlrun/common/schemas/hub.py +7 -9
- mlrun/common/schemas/model_monitoring/__init__.py +21 -4
- mlrun/common/schemas/model_monitoring/constants.py +136 -42
- mlrun/common/schemas/model_monitoring/grafana.py +9 -5
- mlrun/common/schemas/model_monitoring/model_endpoints.py +89 -41
- mlrun/common/schemas/notification.py +69 -12
- mlrun/{runtimes/mpijob/v1alpha1.py → common/schemas/pagination.py} +10 -13
- mlrun/common/schemas/pipeline.py +7 -0
- mlrun/common/schemas/project.py +67 -16
- mlrun/common/schemas/runs.py +17 -0
- mlrun/common/schemas/schedule.py +1 -1
- mlrun/common/schemas/workflow.py +10 -2
- mlrun/common/types.py +14 -1
- mlrun/config.py +233 -58
- mlrun/data_types/data_types.py +11 -1
- mlrun/data_types/spark.py +5 -4
- mlrun/data_types/to_pandas.py +75 -34
- mlrun/datastore/__init__.py +8 -10
- mlrun/datastore/alibaba_oss.py +131 -0
- mlrun/datastore/azure_blob.py +131 -43
- mlrun/datastore/base.py +107 -47
- mlrun/datastore/datastore.py +17 -7
- mlrun/datastore/datastore_profile.py +91 -7
- mlrun/datastore/dbfs_store.py +3 -7
- mlrun/datastore/filestore.py +1 -3
- mlrun/datastore/google_cloud_storage.py +92 -32
- mlrun/datastore/hdfs.py +5 -0
- mlrun/datastore/inmem.py +6 -3
- mlrun/datastore/redis.py +3 -2
- mlrun/datastore/s3.py +30 -12
- mlrun/datastore/snowflake_utils.py +45 -0
- mlrun/datastore/sources.py +274 -59
- mlrun/datastore/spark_utils.py +30 -0
- mlrun/datastore/store_resources.py +9 -7
- mlrun/datastore/storeytargets.py +151 -0
- mlrun/datastore/targets.py +387 -119
- mlrun/datastore/utils.py +68 -5
- mlrun/datastore/v3io.py +28 -50
- mlrun/db/auth_utils.py +152 -0
- mlrun/db/base.py +245 -20
- mlrun/db/factory.py +1 -4
- mlrun/db/httpdb.py +909 -231
- mlrun/db/nopdb.py +279 -14
- mlrun/errors.py +35 -5
- mlrun/execution.py +111 -38
- mlrun/feature_store/__init__.py +0 -2
- mlrun/feature_store/api.py +46 -53
- mlrun/feature_store/common.py +6 -11
- mlrun/feature_store/feature_set.py +48 -23
- mlrun/feature_store/feature_vector.py +13 -2
- mlrun/feature_store/ingestion.py +7 -6
- mlrun/feature_store/retrieval/base.py +9 -4
- mlrun/feature_store/retrieval/dask_merger.py +2 -0
- mlrun/feature_store/retrieval/job.py +13 -4
- mlrun/feature_store/retrieval/local_merger.py +2 -0
- mlrun/feature_store/retrieval/spark_merger.py +24 -32
- mlrun/feature_store/steps.py +38 -19
- mlrun/features.py +6 -14
- mlrun/frameworks/_common/plan.py +3 -3
- mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +7 -12
- mlrun/frameworks/_ml_common/plan.py +1 -1
- mlrun/frameworks/auto_mlrun/auto_mlrun.py +2 -2
- mlrun/frameworks/lgbm/__init__.py +1 -1
- mlrun/frameworks/lgbm/callbacks/callback.py +2 -4
- mlrun/frameworks/lgbm/model_handler.py +1 -1
- mlrun/frameworks/parallel_coordinates.py +4 -4
- mlrun/frameworks/pytorch/__init__.py +2 -2
- mlrun/frameworks/sklearn/__init__.py +1 -1
- mlrun/frameworks/sklearn/mlrun_interface.py +13 -3
- mlrun/frameworks/tf_keras/__init__.py +5 -2
- mlrun/frameworks/tf_keras/callbacks/logging_callback.py +1 -1
- mlrun/frameworks/tf_keras/mlrun_interface.py +2 -2
- mlrun/frameworks/xgboost/__init__.py +1 -1
- mlrun/k8s_utils.py +57 -12
- mlrun/launcher/__init__.py +1 -1
- mlrun/launcher/base.py +6 -5
- mlrun/launcher/client.py +13 -11
- mlrun/launcher/factory.py +1 -1
- mlrun/launcher/local.py +15 -5
- mlrun/launcher/remote.py +10 -3
- mlrun/lists.py +6 -2
- mlrun/model.py +297 -48
- mlrun/model_monitoring/__init__.py +1 -1
- mlrun/model_monitoring/api.py +152 -357
- mlrun/model_monitoring/applications/__init__.py +10 -0
- mlrun/model_monitoring/applications/_application_steps.py +190 -0
- mlrun/model_monitoring/applications/base.py +108 -0
- mlrun/model_monitoring/applications/context.py +341 -0
- mlrun/model_monitoring/{evidently_application.py → applications/evidently_base.py} +27 -22
- mlrun/model_monitoring/applications/histogram_data_drift.py +227 -91
- mlrun/model_monitoring/applications/results.py +99 -0
- mlrun/model_monitoring/controller.py +130 -303
- mlrun/model_monitoring/{stores/models/sqlite.py → db/__init__.py} +5 -10
- mlrun/model_monitoring/db/stores/__init__.py +136 -0
- mlrun/model_monitoring/db/stores/base/__init__.py +15 -0
- mlrun/model_monitoring/db/stores/base/store.py +213 -0
- mlrun/model_monitoring/db/stores/sqldb/__init__.py +13 -0
- mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +71 -0
- mlrun/model_monitoring/db/stores/sqldb/models/base.py +190 -0
- mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +103 -0
- mlrun/model_monitoring/{stores/models/mysql.py → db/stores/sqldb/models/sqlite.py} +19 -13
- mlrun/model_monitoring/db/stores/sqldb/sql_store.py +659 -0
- mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +13 -0
- mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +726 -0
- mlrun/model_monitoring/db/tsdb/__init__.py +105 -0
- mlrun/model_monitoring/db/tsdb/base.py +448 -0
- mlrun/model_monitoring/db/tsdb/helpers.py +30 -0
- mlrun/model_monitoring/db/tsdb/tdengine/__init__.py +15 -0
- mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +298 -0
- mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +42 -0
- mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +522 -0
- mlrun/model_monitoring/db/tsdb/v3io/__init__.py +15 -0
- mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +158 -0
- mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +849 -0
- mlrun/model_monitoring/features_drift_table.py +34 -22
- mlrun/model_monitoring/helpers.py +177 -39
- mlrun/model_monitoring/model_endpoint.py +3 -2
- mlrun/model_monitoring/stream_processing.py +165 -398
- mlrun/model_monitoring/tracking_policy.py +7 -1
- mlrun/model_monitoring/writer.py +161 -125
- mlrun/package/packagers/default_packager.py +2 -2
- mlrun/package/packagers_manager.py +1 -0
- mlrun/package/utils/_formatter.py +2 -2
- mlrun/platforms/__init__.py +11 -10
- mlrun/platforms/iguazio.py +67 -228
- mlrun/projects/__init__.py +6 -1
- mlrun/projects/operations.py +47 -20
- mlrun/projects/pipelines.py +396 -249
- mlrun/projects/project.py +1176 -406
- mlrun/render.py +28 -22
- mlrun/run.py +208 -181
- mlrun/runtimes/__init__.py +76 -11
- mlrun/runtimes/base.py +54 -24
- mlrun/runtimes/daskjob.py +9 -2
- mlrun/runtimes/databricks_job/databricks_runtime.py +1 -0
- mlrun/runtimes/databricks_job/databricks_wrapper.py +1 -1
- mlrun/runtimes/funcdoc.py +1 -29
- mlrun/runtimes/kubejob.py +34 -128
- mlrun/runtimes/local.py +39 -10
- mlrun/runtimes/mpijob/__init__.py +0 -20
- mlrun/runtimes/mpijob/abstract.py +8 -8
- mlrun/runtimes/mpijob/v1.py +1 -1
- mlrun/runtimes/nuclio/__init__.py +1 -0
- mlrun/runtimes/nuclio/api_gateway.py +769 -0
- mlrun/runtimes/nuclio/application/__init__.py +15 -0
- mlrun/runtimes/nuclio/application/application.py +758 -0
- mlrun/runtimes/nuclio/application/reverse_proxy.go +95 -0
- mlrun/runtimes/nuclio/function.py +188 -68
- mlrun/runtimes/nuclio/serving.py +57 -60
- mlrun/runtimes/pod.py +191 -58
- mlrun/runtimes/remotesparkjob.py +11 -8
- mlrun/runtimes/sparkjob/spark3job.py +17 -18
- mlrun/runtimes/utils.py +40 -73
- mlrun/secrets.py +6 -2
- mlrun/serving/__init__.py +8 -1
- mlrun/serving/remote.py +2 -3
- mlrun/serving/routers.py +89 -64
- mlrun/serving/server.py +54 -26
- mlrun/serving/states.py +187 -56
- mlrun/serving/utils.py +19 -11
- mlrun/serving/v2_serving.py +136 -63
- mlrun/track/tracker.py +2 -1
- mlrun/track/trackers/mlflow_tracker.py +5 -0
- mlrun/utils/async_http.py +26 -6
- mlrun/utils/db.py +18 -0
- mlrun/utils/helpers.py +375 -105
- mlrun/utils/http.py +2 -2
- mlrun/utils/logger.py +75 -9
- mlrun/utils/notifications/notification/__init__.py +14 -10
- mlrun/utils/notifications/notification/base.py +48 -0
- mlrun/utils/notifications/notification/console.py +2 -0
- mlrun/utils/notifications/notification/git.py +24 -1
- mlrun/utils/notifications/notification/ipython.py +2 -0
- mlrun/utils/notifications/notification/slack.py +96 -21
- mlrun/utils/notifications/notification/webhook.py +63 -2
- mlrun/utils/notifications/notification_pusher.py +146 -16
- mlrun/utils/regex.py +9 -0
- mlrun/utils/retryer.py +3 -2
- mlrun/utils/v3io_clients.py +2 -3
- mlrun/utils/version/version.json +2 -2
- mlrun-1.7.2.dist-info/METADATA +390 -0
- mlrun-1.7.2.dist-info/RECORD +351 -0
- {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/WHEEL +1 -1
- mlrun/feature_store/retrieval/conversion.py +0 -271
- mlrun/kfpops.py +0 -868
- mlrun/model_monitoring/application.py +0 -310
- mlrun/model_monitoring/batch.py +0 -974
- mlrun/model_monitoring/controller_handler.py +0 -37
- mlrun/model_monitoring/prometheus.py +0 -216
- mlrun/model_monitoring/stores/__init__.py +0 -111
- mlrun/model_monitoring/stores/kv_model_endpoint_store.py +0 -574
- mlrun/model_monitoring/stores/model_endpoint_store.py +0 -145
- mlrun/model_monitoring/stores/models/__init__.py +0 -27
- mlrun/model_monitoring/stores/models/base.py +0 -84
- mlrun/model_monitoring/stores/sql_model_endpoint_store.py +0 -382
- mlrun/platforms/other.py +0 -305
- mlrun-1.7.0rc4.dist-info/METADATA +0 -269
- mlrun-1.7.0rc4.dist-info/RECORD +0 -321
- {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/LICENSE +0 -0
- {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/entry_points.txt +0 -0
- {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Copyright 2024 Iguazio
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import enum
|
|
16
|
+
import typing
|
|
17
|
+
|
|
18
|
+
import mlrun.common.schemas.secret
|
|
19
|
+
import mlrun.errors
|
|
20
|
+
|
|
21
|
+
from .base import TSDBConnector
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ObjectTSDBFactory(enum.Enum):
|
|
25
|
+
"""Enum class to handle the different TSDB connector type values for storing real time metrics"""
|
|
26
|
+
|
|
27
|
+
v3io_tsdb = "v3io-tsdb"
|
|
28
|
+
tdengine = "tdengine"
|
|
29
|
+
|
|
30
|
+
def to_tsdb_connector(self, project: str, **kwargs) -> TSDBConnector:
|
|
31
|
+
"""
|
|
32
|
+
Return a TSDBConnector object based on the provided enum value.
|
|
33
|
+
:param project: The name of the project.
|
|
34
|
+
:return: `TSDBConnector` object.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
if self == self.v3io_tsdb:
|
|
38
|
+
if mlrun.mlconf.is_ce_mode():
|
|
39
|
+
raise mlrun.errors.MLRunInvalidArgumentError(
|
|
40
|
+
f"{self.v3io_tsdb} is not supported in CE mode."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
from .v3io.v3io_connector import V3IOTSDBConnector
|
|
44
|
+
|
|
45
|
+
return V3IOTSDBConnector(project=project, **kwargs)
|
|
46
|
+
|
|
47
|
+
# Assuming TDEngine connector if connector type is not V3IO TSDB.
|
|
48
|
+
# Update these lines once there are more than two connector types.
|
|
49
|
+
|
|
50
|
+
from .tdengine.tdengine_connector import TDEngineConnector
|
|
51
|
+
|
|
52
|
+
return TDEngineConnector(project=project, **kwargs)
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _missing_(cls, value: typing.Any):
|
|
56
|
+
"""A lookup function to handle an invalid value.
|
|
57
|
+
:param value: Provided enum (invalid) value.
|
|
58
|
+
"""
|
|
59
|
+
valid_values = list(cls.__members__.keys())
|
|
60
|
+
raise mlrun.errors.MLRunInvalidMMStoreTypeError(
|
|
61
|
+
f"{value} is not a valid tsdb, please choose a valid value: %{valid_values}."
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_tsdb_connector(
|
|
66
|
+
project: str,
|
|
67
|
+
secret_provider: typing.Optional[typing.Callable[[str], str]] = None,
|
|
68
|
+
tsdb_connection_string: typing.Optional[str] = None,
|
|
69
|
+
**kwargs,
|
|
70
|
+
) -> TSDBConnector:
|
|
71
|
+
"""
|
|
72
|
+
Get TSDB connector object.
|
|
73
|
+
:param project: The name of the project.
|
|
74
|
+
:param secret_provider: An optional secret provider to get the connection string secret.
|
|
75
|
+
:param tsdb_connection_string: An optional explicit connection string to the TSDB.
|
|
76
|
+
|
|
77
|
+
:return: `TSDBConnector` object. The main goal of this object is to handle different operations on the
|
|
78
|
+
TSDB connector such as updating drift metrics or write application record result.
|
|
79
|
+
:raise: `MLRunInvalidMMStoreTypeError` if the user didn't provide TSDB connection
|
|
80
|
+
or the provided TSDB connection is invalid.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
tsdb_connection_string = (
|
|
84
|
+
tsdb_connection_string
|
|
85
|
+
or mlrun.model_monitoring.helpers.get_tsdb_connection_string(
|
|
86
|
+
secret_provider=secret_provider
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if tsdb_connection_string and tsdb_connection_string.startswith("taosws"):
|
|
91
|
+
tsdb_connector_type = mlrun.common.schemas.model_monitoring.TSDBTarget.TDEngine
|
|
92
|
+
kwargs["connection_string"] = tsdb_connection_string
|
|
93
|
+
elif tsdb_connection_string and tsdb_connection_string == "v3io":
|
|
94
|
+
tsdb_connector_type = mlrun.common.schemas.model_monitoring.TSDBTarget.V3IO_TSDB
|
|
95
|
+
else:
|
|
96
|
+
raise mlrun.errors.MLRunInvalidMMStoreTypeError(
|
|
97
|
+
"You must provide a valid tsdb store connection by using "
|
|
98
|
+
"set_model_monitoring_credentials API."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Get connector type value from ObjectTSDBFactory enum class
|
|
102
|
+
tsdb_connector_factory = ObjectTSDBFactory(tsdb_connector_type)
|
|
103
|
+
|
|
104
|
+
# Convert into TSDB connector object
|
|
105
|
+
return tsdb_connector_factory.to_tsdb_connector(project=project, **kwargs)
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
# Copyright 2024 Iguazio
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import typing
|
|
16
|
+
from abc import ABC, abstractmethod
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from typing import Union
|
|
19
|
+
|
|
20
|
+
import pandas as pd
|
|
21
|
+
import pydantic
|
|
22
|
+
|
|
23
|
+
import mlrun.common.schemas.model_monitoring as mm_schemas
|
|
24
|
+
import mlrun.model_monitoring.db.tsdb.helpers
|
|
25
|
+
import mlrun.model_monitoring.helpers
|
|
26
|
+
from mlrun.utils import logger
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TSDBConnector(ABC):
|
|
30
|
+
type: typing.ClassVar[str]
|
|
31
|
+
|
|
32
|
+
def __init__(self, project: str) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Initialize a new TSDB connector. The connector is used to interact with the TSDB and store monitoring data.
|
|
35
|
+
At the moment we have 3 different types of monitoring data:
|
|
36
|
+
- real time performance metrics: real time performance metrics that are being calculated by the model
|
|
37
|
+
monitoring stream pod.
|
|
38
|
+
Among these metrics are the base metrics (average latency and predictions over time), endpoint features
|
|
39
|
+
(data samples), and custom metrics (user-defined metrics).
|
|
40
|
+
- app_results: a detailed results that include status, kind, extra data, etc. These results are being calculated
|
|
41
|
+
through the monitoring applications and stored in the TSDB using the model monitoring writer.
|
|
42
|
+
- metrics: a basic key value that represents a numeric metric. Similar to the app_results, these metrics
|
|
43
|
+
are being calculated through the monitoring applications and stored in the TSDB using the model monitoring
|
|
44
|
+
writer.
|
|
45
|
+
|
|
46
|
+
:param project: the name of the project.
|
|
47
|
+
"""
|
|
48
|
+
self.project = project
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def apply_monitoring_stream_steps(self, graph) -> None:
|
|
52
|
+
"""
|
|
53
|
+
Apply TSDB steps on the provided monitoring graph. Throughout these steps, the graph stores live data of
|
|
54
|
+
different key metric dictionaries. This data is being used by the monitoring dashboards in
|
|
55
|
+
grafana.
|
|
56
|
+
There are 3 different key metric dictionaries that are being generated throughout these steps:
|
|
57
|
+
- base_metrics (average latency and predictions over time)
|
|
58
|
+
- endpoint_features (Prediction and feature names and values)
|
|
59
|
+
- custom_metrics (user-defined metrics)
|
|
60
|
+
"""
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
@abstractmethod
|
|
64
|
+
def handle_model_error(self, graph, **kwargs) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Adds a branch to the stream pod graph to handle events that
|
|
67
|
+
arrive with errors from the model server and saves them to the error TSDB table.
|
|
68
|
+
The first step that generates by this method should come after `ForwardError` step.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def write_application_event(
|
|
73
|
+
self,
|
|
74
|
+
event: dict,
|
|
75
|
+
kind: mm_schemas.WriterEventKind = mm_schemas.WriterEventKind.RESULT,
|
|
76
|
+
) -> None:
|
|
77
|
+
"""
|
|
78
|
+
Write a single application or metric to TSDB.
|
|
79
|
+
|
|
80
|
+
:raise mlrun.errors.MLRunRuntimeError: If an error occurred while writing the event.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def delete_tsdb_resources(self):
|
|
85
|
+
"""
|
|
86
|
+
Delete all project resources in the TSDB connector, such as model endpoints data and drift results.
|
|
87
|
+
"""
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def get_model_endpoint_real_time_metrics(
|
|
92
|
+
self,
|
|
93
|
+
endpoint_id: str,
|
|
94
|
+
metrics: list[str],
|
|
95
|
+
start: str,
|
|
96
|
+
end: str,
|
|
97
|
+
) -> dict[str, list[tuple[str, float]]]:
|
|
98
|
+
"""
|
|
99
|
+
Getting real time metrics from the TSDB. There are pre-defined metrics for model endpoints such as
|
|
100
|
+
`predictions_per_second` and `latency_avg_5m` but also custom metrics defined by the user. Note that these
|
|
101
|
+
metrics are being calculated by the model monitoring stream pod.
|
|
102
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
103
|
+
:param metrics: A list of real-time metrics to return for the model endpoint.
|
|
104
|
+
:param start: The start time of the metrics. Can be represented by a string containing an RFC 3339
|
|
105
|
+
time, a Unix timestamp in milliseconds, a relative time (`'now'` or
|
|
106
|
+
`'now-[0-9]+[mhd]'`, where `m` = minutes, `h` = hours, `'d'` = days, and `'s'`
|
|
107
|
+
= seconds), or 0 for the earliest time.
|
|
108
|
+
:param end: The end time of the metrics. Can be represented by a string containing an RFC 3339
|
|
109
|
+
time, a Unix timestamp in milliseconds, a relative time (`'now'` or
|
|
110
|
+
`'now-[0-9]+[mhd]'`, where `m` = minutes, `h` = hours, `'d'` = days, and `'s'`
|
|
111
|
+
= seconds), or 0 for the earliest time.
|
|
112
|
+
:return: A dictionary of metrics in which the key is a metric name and the value is a list of tuples that
|
|
113
|
+
includes timestamps and the values.
|
|
114
|
+
"""
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
@abstractmethod
|
|
118
|
+
def create_tables(self) -> None:
|
|
119
|
+
"""
|
|
120
|
+
Create the TSDB tables using the TSDB connector. At the moment we support 3 types of tables:
|
|
121
|
+
- app_results: a detailed result that includes status, kind, extra data, etc.
|
|
122
|
+
- metrics: a basic key value that represents a numeric metric.
|
|
123
|
+
- predictions: latency of each prediction.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@abstractmethod
|
|
127
|
+
def read_metrics_data(
|
|
128
|
+
self,
|
|
129
|
+
*,
|
|
130
|
+
endpoint_id: str,
|
|
131
|
+
start: datetime,
|
|
132
|
+
end: datetime,
|
|
133
|
+
metrics: list[mm_schemas.ModelEndpointMonitoringMetric],
|
|
134
|
+
type: typing.Literal["metrics", "results"],
|
|
135
|
+
) -> typing.Union[
|
|
136
|
+
list[
|
|
137
|
+
typing.Union[
|
|
138
|
+
mm_schemas.ModelEndpointMonitoringResultValues,
|
|
139
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
140
|
+
],
|
|
141
|
+
],
|
|
142
|
+
list[
|
|
143
|
+
typing.Union[
|
|
144
|
+
mm_schemas.ModelEndpointMonitoringMetricValues,
|
|
145
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
146
|
+
],
|
|
147
|
+
],
|
|
148
|
+
]:
|
|
149
|
+
"""
|
|
150
|
+
Read metrics OR results from the TSDB and return as a list.
|
|
151
|
+
|
|
152
|
+
:param endpoint_id: The model endpoint identifier.
|
|
153
|
+
:param start: The start time of the query.
|
|
154
|
+
:param end: The end time of the query.
|
|
155
|
+
:param metrics: The list of metrics to get the values for.
|
|
156
|
+
:param type: "metrics" or "results" - the type of each item in metrics.
|
|
157
|
+
:return: A list of result values or a list of metric values.
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
@abstractmethod
|
|
161
|
+
def read_predictions(
|
|
162
|
+
self,
|
|
163
|
+
*,
|
|
164
|
+
endpoint_id: str,
|
|
165
|
+
start: datetime,
|
|
166
|
+
end: datetime,
|
|
167
|
+
aggregation_window: typing.Optional[str] = None,
|
|
168
|
+
agg_funcs: typing.Optional[list[str]] = None,
|
|
169
|
+
limit: typing.Optional[int] = None,
|
|
170
|
+
) -> typing.Union[
|
|
171
|
+
mm_schemas.ModelEndpointMonitoringMetricValues,
|
|
172
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
173
|
+
]:
|
|
174
|
+
"""
|
|
175
|
+
Read the "invocations" metric for the provided model endpoint in the given time range,
|
|
176
|
+
and return the metric values if any, otherwise signify with the "no data" object.
|
|
177
|
+
|
|
178
|
+
:param endpoint_id: The model endpoint identifier.
|
|
179
|
+
:param start: The start time of the query.
|
|
180
|
+
:param end: The end time of the query.
|
|
181
|
+
:param aggregation_window: On what time window length should the invocations be aggregated. If provided,
|
|
182
|
+
the `agg_funcs` must be provided as well. Provided as a string in the format of '1m',
|
|
183
|
+
'1h', etc.
|
|
184
|
+
:param agg_funcs: List of aggregation functions to apply on the invocations. If provided, the
|
|
185
|
+
`aggregation_window` must be provided as well. Provided as a list of strings in
|
|
186
|
+
the format of ['sum', 'avg', 'count', ...]
|
|
187
|
+
:param limit: The maximum number of records to return.
|
|
188
|
+
|
|
189
|
+
:raise mlrun.errors.MLRunInvalidArgumentError: If only one of `aggregation_window` and `agg_funcs` is provided.
|
|
190
|
+
:return: Metric values object or no data object.
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
@abstractmethod
|
|
194
|
+
def get_last_request(
|
|
195
|
+
self,
|
|
196
|
+
endpoint_ids: Union[str, list[str]],
|
|
197
|
+
start: Union[datetime, str] = "0",
|
|
198
|
+
end: Union[datetime, str] = "now",
|
|
199
|
+
) -> pd.DataFrame:
|
|
200
|
+
"""
|
|
201
|
+
Fetches data from the predictions TSDB table and returns the most recent request
|
|
202
|
+
timestamp for each specified endpoint.
|
|
203
|
+
|
|
204
|
+
:param endpoint_ids: A list of model endpoint identifiers.
|
|
205
|
+
:param start: The start time for the query.
|
|
206
|
+
:param end: The end time for the query.
|
|
207
|
+
|
|
208
|
+
:return: A pd.DataFrame containing the columns [endpoint_id, last_request, last_latency].
|
|
209
|
+
If an endpoint has not been invoked within the specified time range, it will not appear in the result.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
@abstractmethod
|
|
213
|
+
def get_drift_status(
|
|
214
|
+
self,
|
|
215
|
+
endpoint_ids: Union[str, list[str]],
|
|
216
|
+
start: Union[datetime, str] = "now-24h",
|
|
217
|
+
end: Union[datetime, str] = "now",
|
|
218
|
+
) -> pd.DataFrame:
|
|
219
|
+
"""
|
|
220
|
+
Fetches data from the app-results TSDB table and returns the highest status among all
|
|
221
|
+
the result in the provided time range, which by default is the last 24 hours, for each specified endpoint.
|
|
222
|
+
|
|
223
|
+
:param endpoint_ids: A list of model endpoint identifiers.
|
|
224
|
+
:param start: The start time for the query.
|
|
225
|
+
:param end: The end time for the query.
|
|
226
|
+
|
|
227
|
+
:return: A pd.DataFrame containing the columns [result_status, endpoint_id].
|
|
228
|
+
If an endpoint has not been monitored within the specified time range (last 24 hours),
|
|
229
|
+
it will not appear in the result.
|
|
230
|
+
"""
|
|
231
|
+
|
|
232
|
+
@abstractmethod
|
|
233
|
+
def get_metrics_metadata(
|
|
234
|
+
self,
|
|
235
|
+
endpoint_id: str,
|
|
236
|
+
start: Union[datetime, str] = "0",
|
|
237
|
+
end: Union[datetime, str] = "now",
|
|
238
|
+
) -> pd.DataFrame:
|
|
239
|
+
"""
|
|
240
|
+
Fetches distinct metrics metadata from the metrics TSDB table for a specified model endpoint.
|
|
241
|
+
|
|
242
|
+
:param endpoint_id: The model endpoint identifier.
|
|
243
|
+
:param start: The start time of the query.
|
|
244
|
+
:param end: The end time of the query.
|
|
245
|
+
|
|
246
|
+
:return: A pd.DataFrame containing all distinct metrics for the specified endpoint within the given time range.
|
|
247
|
+
Containing the columns [application_name, metric_name, endpoint_id]
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
@abstractmethod
|
|
251
|
+
def get_results_metadata(
|
|
252
|
+
self,
|
|
253
|
+
endpoint_id: str,
|
|
254
|
+
start: Union[datetime, str] = "0",
|
|
255
|
+
end: Union[datetime, str] = "now",
|
|
256
|
+
) -> pd.DataFrame:
|
|
257
|
+
"""
|
|
258
|
+
Fetches distinct results metadata from the app-results TSDB table for a specified model endpoint.
|
|
259
|
+
|
|
260
|
+
:param endpoint_id: The model endpoint identifier.
|
|
261
|
+
:param start: The start time of the query.
|
|
262
|
+
:param end: The end time of the query.
|
|
263
|
+
|
|
264
|
+
:return: A pd.DataFrame containing all distinct results for the specified endpoint within the given time range.
|
|
265
|
+
Containing the columns [application_name, result_name, result_kind, endpoint_id]
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
@abstractmethod
|
|
269
|
+
def get_error_count(
|
|
270
|
+
self,
|
|
271
|
+
endpoint_ids: Union[str, list[str]],
|
|
272
|
+
start: Union[datetime, str] = "0",
|
|
273
|
+
end: Union[datetime, str] = "now",
|
|
274
|
+
) -> pd.DataFrame:
|
|
275
|
+
"""
|
|
276
|
+
Fetches data from the error TSDB table and returns the error count for each specified endpoint.
|
|
277
|
+
|
|
278
|
+
:param endpoint_ids: A list of model endpoint identifiers.
|
|
279
|
+
:param start: The start time for the query.
|
|
280
|
+
:param end: The end time for the query.
|
|
281
|
+
|
|
282
|
+
:return: A pd.DataFrame containing the columns [error_count, endpoint_id].
|
|
283
|
+
If an endpoint have not raised error within the specified time range, it will not appear in the result.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
@abstractmethod
|
|
287
|
+
def get_avg_latency(
|
|
288
|
+
self,
|
|
289
|
+
endpoint_ids: Union[str, list[str]],
|
|
290
|
+
start: Union[datetime, str] = "0",
|
|
291
|
+
end: Union[datetime, str] = "now",
|
|
292
|
+
) -> pd.DataFrame:
|
|
293
|
+
"""
|
|
294
|
+
Fetches data from the predictions TSDB table and returns the average latency for each specified endpoint
|
|
295
|
+
|
|
296
|
+
:param endpoint_ids: A list of model endpoint identifiers.
|
|
297
|
+
:param start: The start time for the query.
|
|
298
|
+
:param end: The end time for the query.
|
|
299
|
+
|
|
300
|
+
:return: A pd.DataFrame containing the columns [avg_latency, endpoint_id].
|
|
301
|
+
If an endpoint has not been invoked within the specified time range, it will not appear in the result.
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
@staticmethod
|
|
305
|
+
def df_to_metrics_values(
|
|
306
|
+
*,
|
|
307
|
+
df: pd.DataFrame,
|
|
308
|
+
metrics: list[mm_schemas.ModelEndpointMonitoringMetric],
|
|
309
|
+
project: str,
|
|
310
|
+
) -> list[
|
|
311
|
+
typing.Union[
|
|
312
|
+
mm_schemas.ModelEndpointMonitoringMetricValues,
|
|
313
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
314
|
+
]
|
|
315
|
+
]:
|
|
316
|
+
"""
|
|
317
|
+
Parse a time-indexed DataFrame of metrics from the TSDB into a list of
|
|
318
|
+
metrics values per distinct results.
|
|
319
|
+
When a metric is not found in the DataFrame, it is represented in a no-data object.
|
|
320
|
+
"""
|
|
321
|
+
metrics_without_data = {metric.full_name: metric for metric in metrics}
|
|
322
|
+
|
|
323
|
+
metrics_values: list[
|
|
324
|
+
typing.Union[
|
|
325
|
+
mm_schemas.ModelEndpointMonitoringMetricValues,
|
|
326
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
327
|
+
]
|
|
328
|
+
] = []
|
|
329
|
+
if not df.empty:
|
|
330
|
+
grouped = df.groupby(
|
|
331
|
+
[
|
|
332
|
+
mm_schemas.WriterEvent.APPLICATION_NAME,
|
|
333
|
+
mm_schemas.MetricData.METRIC_NAME,
|
|
334
|
+
],
|
|
335
|
+
observed=False,
|
|
336
|
+
)
|
|
337
|
+
else:
|
|
338
|
+
logger.debug("No metrics", missing_metrics=metrics_without_data.keys())
|
|
339
|
+
grouped = []
|
|
340
|
+
for (app_name, name), sub_df in grouped:
|
|
341
|
+
full_name = mlrun.model_monitoring.helpers._compose_full_name(
|
|
342
|
+
project=project,
|
|
343
|
+
app=app_name,
|
|
344
|
+
name=name,
|
|
345
|
+
type=mm_schemas.ModelEndpointMonitoringMetricType.METRIC,
|
|
346
|
+
)
|
|
347
|
+
metrics_values.append(
|
|
348
|
+
mm_schemas.ModelEndpointMonitoringMetricValues(
|
|
349
|
+
full_name=full_name,
|
|
350
|
+
values=list(
|
|
351
|
+
zip(
|
|
352
|
+
sub_df.index,
|
|
353
|
+
sub_df[mm_schemas.MetricData.METRIC_VALUE],
|
|
354
|
+
)
|
|
355
|
+
), # pyright: ignore[reportArgumentType]
|
|
356
|
+
)
|
|
357
|
+
)
|
|
358
|
+
del metrics_without_data[full_name]
|
|
359
|
+
|
|
360
|
+
for metric in metrics_without_data.values():
|
|
361
|
+
metrics_values.append(
|
|
362
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData(
|
|
363
|
+
full_name=metric.full_name,
|
|
364
|
+
type=mm_schemas.ModelEndpointMonitoringMetricType.METRIC,
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
return metrics_values
|
|
369
|
+
|
|
370
|
+
@staticmethod
|
|
371
|
+
def df_to_results_values(
|
|
372
|
+
*,
|
|
373
|
+
df: pd.DataFrame,
|
|
374
|
+
metrics: list[mm_schemas.ModelEndpointMonitoringMetric],
|
|
375
|
+
project: str,
|
|
376
|
+
) -> list[
|
|
377
|
+
typing.Union[
|
|
378
|
+
mm_schemas.ModelEndpointMonitoringResultValues,
|
|
379
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
380
|
+
]
|
|
381
|
+
]:
|
|
382
|
+
"""
|
|
383
|
+
Parse a time-indexed DataFrame of results from the TSDB into a list of
|
|
384
|
+
results values per distinct results.
|
|
385
|
+
When a result is not found in the DataFrame, it is represented in no-data object.
|
|
386
|
+
"""
|
|
387
|
+
metrics_without_data = {metric.full_name: metric for metric in metrics}
|
|
388
|
+
|
|
389
|
+
metrics_values: list[
|
|
390
|
+
typing.Union[
|
|
391
|
+
mm_schemas.ModelEndpointMonitoringResultValues,
|
|
392
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData,
|
|
393
|
+
]
|
|
394
|
+
] = []
|
|
395
|
+
if not df.empty:
|
|
396
|
+
grouped = df.groupby(
|
|
397
|
+
[
|
|
398
|
+
mm_schemas.WriterEvent.APPLICATION_NAME,
|
|
399
|
+
mm_schemas.ResultData.RESULT_NAME,
|
|
400
|
+
],
|
|
401
|
+
observed=False,
|
|
402
|
+
)
|
|
403
|
+
else:
|
|
404
|
+
grouped = []
|
|
405
|
+
logger.debug("No results", missing_results=metrics_without_data.keys())
|
|
406
|
+
for (app_name, name), sub_df in grouped:
|
|
407
|
+
result_kind = mlrun.model_monitoring.db.tsdb.helpers._get_result_kind(
|
|
408
|
+
sub_df
|
|
409
|
+
)
|
|
410
|
+
full_name = mlrun.model_monitoring.helpers._compose_full_name(
|
|
411
|
+
project=project, app=app_name, name=name
|
|
412
|
+
)
|
|
413
|
+
try:
|
|
414
|
+
metrics_values.append(
|
|
415
|
+
mm_schemas.ModelEndpointMonitoringResultValues(
|
|
416
|
+
full_name=full_name,
|
|
417
|
+
result_kind=result_kind,
|
|
418
|
+
values=list(
|
|
419
|
+
zip(
|
|
420
|
+
sub_df.index,
|
|
421
|
+
sub_df[mm_schemas.ResultData.RESULT_VALUE],
|
|
422
|
+
sub_df[mm_schemas.ResultData.RESULT_STATUS],
|
|
423
|
+
)
|
|
424
|
+
), # pyright: ignore[reportArgumentType]
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
except pydantic.ValidationError:
|
|
428
|
+
logger.exception(
|
|
429
|
+
"Failed to convert data-frame into `ModelEndpointMonitoringResultValues`",
|
|
430
|
+
full_name=full_name,
|
|
431
|
+
sub_df_json=sub_df.to_json(),
|
|
432
|
+
)
|
|
433
|
+
raise
|
|
434
|
+
del metrics_without_data[full_name]
|
|
435
|
+
|
|
436
|
+
for metric in metrics_without_data.values():
|
|
437
|
+
if metric.full_name == mlrun.model_monitoring.helpers.get_invocations_fqn(
|
|
438
|
+
project
|
|
439
|
+
):
|
|
440
|
+
continue
|
|
441
|
+
metrics_values.append(
|
|
442
|
+
mm_schemas.ModelEndpointMonitoringMetricNoData(
|
|
443
|
+
full_name=metric.full_name,
|
|
444
|
+
type=mm_schemas.ModelEndpointMonitoringMetricType.RESULT,
|
|
445
|
+
)
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
return metrics_values
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright 2024 Iguazio
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
import pandas as pd
|
|
15
|
+
|
|
16
|
+
import mlrun.common.schemas.model_monitoring as mm_schemas
|
|
17
|
+
from mlrun.utils import logger
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _get_result_kind(result_df: pd.DataFrame) -> mm_schemas.ResultKindApp:
|
|
21
|
+
kind_series = result_df[mm_schemas.ResultData.RESULT_KIND]
|
|
22
|
+
unique_kinds = kind_series.unique()
|
|
23
|
+
if len(unique_kinds) > 1:
|
|
24
|
+
logger.warning(
|
|
25
|
+
"The result has more than one kind",
|
|
26
|
+
kinds=list(unique_kinds),
|
|
27
|
+
application_name=result_df[mm_schemas.WriterEvent.APPLICATION_NAME],
|
|
28
|
+
result_name=result_df[mm_schemas.ResultData.RESULT_NAME],
|
|
29
|
+
)
|
|
30
|
+
return unique_kinds[0]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2024 Iguazio
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .tdengine_connector import TDEngineConnector
|