mlrun 1.7.0rc5__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 -2
- 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 +21 -4
- mlrun/common/schemas/alert.py +202 -0
- mlrun/common/schemas/api_gateway.py +113 -2
- mlrun/common/schemas/artifact.py +28 -1
- mlrun/common/schemas/auth.py +11 -0
- 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 +224 -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 +374 -102
- mlrun/datastore/utils.py +68 -5
- mlrun/datastore/v3io.py +28 -50
- mlrun/db/auth_utils.py +152 -0
- mlrun/db/base.py +231 -22
- mlrun/db/factory.py +1 -4
- mlrun/db/httpdb.py +864 -228
- mlrun/db/nopdb.py +268 -16
- 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 +1125 -414
- mlrun/render.py +28 -22
- mlrun/run.py +207 -180
- mlrun/runtimes/__init__.py +76 -11
- mlrun/runtimes/base.py +40 -14
- 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/api_gateway.py +646 -177
- 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.0rc5.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.0rc5.dist-info/METADATA +0 -269
- mlrun-1.7.0rc5.dist-info/RECORD +0 -323
- {mlrun-1.7.0rc5.dist-info → mlrun-1.7.2.dist-info}/LICENSE +0 -0
- {mlrun-1.7.0rc5.dist-info → mlrun-1.7.2.dist-info}/entry_points.txt +0 -0
- {mlrun-1.7.0rc5.dist-info → mlrun-1.7.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
import warnings
|
|
18
|
+
|
|
19
|
+
import mlrun.common.schemas.secret
|
|
20
|
+
import mlrun.errors
|
|
21
|
+
|
|
22
|
+
from .base import StoreBase
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ObjectStoreFactory(enum.Enum):
|
|
26
|
+
"""Enum class to handle the different store type values for saving model monitoring records."""
|
|
27
|
+
|
|
28
|
+
v3io_nosql = "v3io-nosql"
|
|
29
|
+
SQL = "sql"
|
|
30
|
+
|
|
31
|
+
def to_object_store(
|
|
32
|
+
self,
|
|
33
|
+
project: str,
|
|
34
|
+
**kwargs,
|
|
35
|
+
) -> StoreBase:
|
|
36
|
+
"""
|
|
37
|
+
Return a StoreBase object based on the provided enum value.
|
|
38
|
+
|
|
39
|
+
:param project: The name of the project.
|
|
40
|
+
|
|
41
|
+
:return: `StoreBase` object.
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
if self == self.v3io_nosql:
|
|
46
|
+
from mlrun.model_monitoring.db.stores.v3io_kv.kv_store import KVStoreBase
|
|
47
|
+
|
|
48
|
+
return KVStoreBase(project=project)
|
|
49
|
+
|
|
50
|
+
# Assuming SQL store target if store type is not KV.
|
|
51
|
+
# Update these lines once there are more than two store target types.
|
|
52
|
+
|
|
53
|
+
from mlrun.model_monitoring.db.stores.sqldb.sql_store import SQLStoreBase
|
|
54
|
+
|
|
55
|
+
return SQLStoreBase(
|
|
56
|
+
project=project,
|
|
57
|
+
**kwargs,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def _missing_(cls, value: typing.Any):
|
|
62
|
+
"""A lookup function to handle an invalid value.
|
|
63
|
+
:param value: Provided enum (invalid) value.
|
|
64
|
+
"""
|
|
65
|
+
valid_values = list(cls.__members__.keys())
|
|
66
|
+
raise mlrun.errors.MLRunInvalidMMStoreTypeError(
|
|
67
|
+
f"{value} is not a valid endpoint store, please choose a valid value: %{valid_values}."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_model_endpoint_store(
|
|
72
|
+
project: str,
|
|
73
|
+
access_key: str = None,
|
|
74
|
+
secret_provider: typing.Optional[typing.Callable[[str], str]] = None,
|
|
75
|
+
) -> StoreBase:
|
|
76
|
+
# Leaving here for backwards compatibility
|
|
77
|
+
warnings.warn(
|
|
78
|
+
"The 'get_model_endpoint_store' function is deprecated and will be removed in 1.9.0. "
|
|
79
|
+
"Please use `get_store_object` instead.",
|
|
80
|
+
# TODO: remove in 1.9.0
|
|
81
|
+
FutureWarning,
|
|
82
|
+
)
|
|
83
|
+
return get_store_object(
|
|
84
|
+
project=project, access_key=access_key, secret_provider=secret_provider
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_store_object(
|
|
89
|
+
project: str,
|
|
90
|
+
secret_provider: typing.Optional[typing.Callable[[str], str]] = None,
|
|
91
|
+
store_connection_string: typing.Optional[str] = None,
|
|
92
|
+
**kwargs,
|
|
93
|
+
) -> StoreBase:
|
|
94
|
+
"""
|
|
95
|
+
Generate a store object. If a connection string is provided, the store type will be updated according to the
|
|
96
|
+
connection string. Currently, the supported store types are SQL and v3io-nosql.
|
|
97
|
+
|
|
98
|
+
:param project: The name of the project.
|
|
99
|
+
:param secret_provider: An optional secret provider to get the connection string secret.
|
|
100
|
+
:param store_connection_string: Optional explicit connection string of the store.
|
|
101
|
+
|
|
102
|
+
:return: `StoreBase` object. Using this object, the user can apply different operations such as write, update, get
|
|
103
|
+
and delete a model endpoint record.
|
|
104
|
+
:raise: `MLRunInvalidMMStoreTypeError` if the user didn't provide store connection
|
|
105
|
+
or the provided store connection is invalid.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
store_connection_string = (
|
|
109
|
+
store_connection_string
|
|
110
|
+
or mlrun.model_monitoring.helpers.get_connection_string(
|
|
111
|
+
secret_provider=secret_provider
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if store_connection_string and (
|
|
116
|
+
store_connection_string.startswith("mysql")
|
|
117
|
+
or store_connection_string.startswith("sqlite")
|
|
118
|
+
):
|
|
119
|
+
store_type = mlrun.common.schemas.model_monitoring.ModelEndpointTarget.SQL
|
|
120
|
+
kwargs["store_connection_string"] = store_connection_string
|
|
121
|
+
elif store_connection_string and store_connection_string == "v3io":
|
|
122
|
+
store_type = (
|
|
123
|
+
mlrun.common.schemas.model_monitoring.ModelEndpointTarget.V3IO_NOSQL
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
raise mlrun.errors.MLRunInvalidMMStoreTypeError(
|
|
127
|
+
"You must provide a valid store connection by using "
|
|
128
|
+
"set_model_monitoring_credentials API."
|
|
129
|
+
)
|
|
130
|
+
# Get store type value from ObjectStoreFactory enum class
|
|
131
|
+
store_type_fact = ObjectStoreFactory(store_type)
|
|
132
|
+
|
|
133
|
+
# Convert into store target object
|
|
134
|
+
return store_type_fact.to_object_store(
|
|
135
|
+
project=project, secret_provider=secret_provider, **kwargs
|
|
136
|
+
)
|
|
@@ -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 .store import StoreBase
|
|
@@ -0,0 +1,213 @@
|
|
|
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 json
|
|
16
|
+
import typing
|
|
17
|
+
from abc import ABC, abstractmethod
|
|
18
|
+
|
|
19
|
+
import mlrun.common.schemas.model_monitoring as mm_schemas
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StoreBase(ABC):
|
|
23
|
+
type: typing.ClassVar[str]
|
|
24
|
+
"""
|
|
25
|
+
An abstract class to handle the store object in the DB target.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, project: str):
|
|
29
|
+
"""
|
|
30
|
+
Initialize a new store target.
|
|
31
|
+
|
|
32
|
+
:param project: The name of the project.
|
|
33
|
+
"""
|
|
34
|
+
self.project = project
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def write_model_endpoint(self, endpoint: dict[str, typing.Any]):
|
|
38
|
+
"""
|
|
39
|
+
Create a new endpoint record in the DB table.
|
|
40
|
+
|
|
41
|
+
:param endpoint: model endpoint dictionary that will be written into the DB.
|
|
42
|
+
"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def update_model_endpoint(
|
|
47
|
+
self, endpoint_id: str, attributes: dict[str, typing.Any]
|
|
48
|
+
):
|
|
49
|
+
"""
|
|
50
|
+
Update a model endpoint record with a given attributes.
|
|
51
|
+
|
|
52
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
53
|
+
:param attributes: Dictionary of attributes that will be used for update the model endpoint. Note that the keys
|
|
54
|
+
of the attributes dictionary should exist in the DB table.
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
@abstractmethod
|
|
60
|
+
def delete_model_endpoint(self, endpoint_id: str):
|
|
61
|
+
"""
|
|
62
|
+
Deletes the record of a given model endpoint id.
|
|
63
|
+
|
|
64
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
65
|
+
"""
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def delete_model_endpoints_resources(self):
|
|
70
|
+
"""
|
|
71
|
+
Delete all model endpoints resources.
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def get_model_endpoint(
|
|
78
|
+
self,
|
|
79
|
+
endpoint_id: str,
|
|
80
|
+
) -> dict[str, typing.Any]:
|
|
81
|
+
"""
|
|
82
|
+
Get a single model endpoint record.
|
|
83
|
+
|
|
84
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
85
|
+
|
|
86
|
+
:return: A model endpoint record as a dictionary.
|
|
87
|
+
"""
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def list_model_endpoints(
|
|
92
|
+
self,
|
|
93
|
+
model: str = None,
|
|
94
|
+
function: str = None,
|
|
95
|
+
labels: list[str] = None,
|
|
96
|
+
top_level: bool = None,
|
|
97
|
+
uids: list = None,
|
|
98
|
+
include_stats: bool = None,
|
|
99
|
+
) -> list[dict[str, typing.Any]]:
|
|
100
|
+
"""
|
|
101
|
+
Returns a list of model endpoint dictionaries, supports filtering by model, function, labels or top level.
|
|
102
|
+
By default, when no filters are applied, all available model endpoints for the given project will
|
|
103
|
+
be listed.
|
|
104
|
+
|
|
105
|
+
:param model: The name of the model to filter by.
|
|
106
|
+
:param function: The name of the function to filter by.
|
|
107
|
+
:param labels: A list of labels to filter by. Label filters work by either filtering a specific value
|
|
108
|
+
of a label (i.e. list("key=value")) or by looking for the existence of a given
|
|
109
|
+
key (i.e. "key").
|
|
110
|
+
:param top_level: If True will return only routers and endpoint that are NOT children of any router.
|
|
111
|
+
:param uids: List of model endpoint unique ids to include in the result.
|
|
112
|
+
:param include_stats: If True, will include model endpoint statistics in the result.
|
|
113
|
+
|
|
114
|
+
:return: A list of model endpoint dictionaries.
|
|
115
|
+
"""
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
@abstractmethod
|
|
119
|
+
def write_application_event(
|
|
120
|
+
self,
|
|
121
|
+
event: dict[str, typing.Any],
|
|
122
|
+
kind: mm_schemas.WriterEventKind = mm_schemas.WriterEventKind.RESULT,
|
|
123
|
+
) -> None:
|
|
124
|
+
"""
|
|
125
|
+
Write a new event in the target table.
|
|
126
|
+
|
|
127
|
+
:param event: An event dictionary that represents the application result, should be corresponded to the
|
|
128
|
+
schema defined in the :py:class:`~mlrun.common.schemas.model_monitoring.constants.WriterEvent`
|
|
129
|
+
object.
|
|
130
|
+
:param kind: The type of the event, can be either "result" or "metric".
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
@abstractmethod
|
|
134
|
+
def get_last_analyzed(self, endpoint_id: str, application_name: str) -> int:
|
|
135
|
+
"""
|
|
136
|
+
Get the last analyzed time for the provided model endpoint and application.
|
|
137
|
+
|
|
138
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
139
|
+
:param application_name: Registered application name.
|
|
140
|
+
|
|
141
|
+
:return: Timestamp as a Unix time.
|
|
142
|
+
:raise: MLRunNotFoundError if last analyzed value is not found.
|
|
143
|
+
"""
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
@abstractmethod
|
|
147
|
+
def update_last_analyzed(
|
|
148
|
+
self,
|
|
149
|
+
endpoint_id: str,
|
|
150
|
+
application_name: str,
|
|
151
|
+
last_analyzed: int,
|
|
152
|
+
):
|
|
153
|
+
"""
|
|
154
|
+
Update the last analyzed time for the provided model endpoint and application.
|
|
155
|
+
|
|
156
|
+
:param endpoint_id: The unique id of the model endpoint.
|
|
157
|
+
:param application_name: Registered application name.
|
|
158
|
+
:param last_analyzed: Timestamp as a Unix time that represents the last analyzed time of a certain
|
|
159
|
+
application and model endpoint.
|
|
160
|
+
|
|
161
|
+
"""
|
|
162
|
+
pass
|
|
163
|
+
|
|
164
|
+
@abstractmethod
|
|
165
|
+
def get_model_endpoint_metrics(
|
|
166
|
+
self, endpoint_id: str, type: mm_schemas.ModelEndpointMonitoringMetricType
|
|
167
|
+
) -> list[mm_schemas.ModelEndpointMonitoringMetric]:
|
|
168
|
+
"""
|
|
169
|
+
Get the model monitoring results and metrics of the requested model endpoint.
|
|
170
|
+
|
|
171
|
+
:param: endpoint_id: The model endpoint identifier.
|
|
172
|
+
:param: type: The type of the requested metrics ("result" or "metric").
|
|
173
|
+
|
|
174
|
+
:return: A list of the available metrics.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
@staticmethod
|
|
178
|
+
def _validate_labels(
|
|
179
|
+
endpoint_dict: dict,
|
|
180
|
+
labels: list,
|
|
181
|
+
) -> bool:
|
|
182
|
+
"""Validate that the model endpoint dictionary has the provided labels. There are 2 possible cases:
|
|
183
|
+
1 - Labels were provided as a list of key-values pairs (e.g. ['label_1=value_1', 'label_2=value_2']): Validate
|
|
184
|
+
that each pair exist in the endpoint dictionary.
|
|
185
|
+
2 - Labels were provided as a list of key labels (e.g. ['label_1', 'label_2']): Validate that each key exist in
|
|
186
|
+
the endpoint labels dictionary.
|
|
187
|
+
|
|
188
|
+
:param endpoint_dict: Dictionary of the model endpoint records.
|
|
189
|
+
:param labels: List of dictionary of required labels.
|
|
190
|
+
|
|
191
|
+
:return: True if the labels exist in the endpoint labels dictionary, otherwise False.
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
# Convert endpoint labels into dictionary
|
|
195
|
+
endpoint_labels = json.loads(
|
|
196
|
+
endpoint_dict.get(mm_schemas.EventFieldType.LABELS)
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
for label in labels:
|
|
200
|
+
# Case 1 - label is a key=value pair
|
|
201
|
+
if "=" in label:
|
|
202
|
+
lbl, value = list(map(lambda x: x.strip(), label.split("=")))
|
|
203
|
+
if lbl not in endpoint_labels or str(endpoint_labels[lbl]) != value:
|
|
204
|
+
return False
|
|
205
|
+
# Case 2 - label is just a key
|
|
206
|
+
else:
|
|
207
|
+
if label not in endpoint_labels:
|
|
208
|
+
return False
|
|
209
|
+
|
|
210
|
+
return True
|
|
211
|
+
|
|
212
|
+
def create_tables(self):
|
|
213
|
+
pass
|
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Copyright 2023 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 functools import partial
|
|
16
|
+
from typing import Optional, TypeVar, Union
|
|
17
|
+
|
|
18
|
+
from .mysql import ApplicationMetricsTable as MySQLApplicationMetricsTable
|
|
19
|
+
from .mysql import ApplicationResultTable as MySQLApplicationResultTable
|
|
20
|
+
from .mysql import ModelEndpointsTable as MySQLModelEndpointsTable
|
|
21
|
+
from .mysql import MonitoringSchedulesTable as MySQLMonitoringSchedulesTable
|
|
22
|
+
from .sqlite import ApplicationMetricsTable as SQLiteApplicationMetricsTable
|
|
23
|
+
from .sqlite import ApplicationResultTable as SQLiteApplicationResultTable
|
|
24
|
+
from .sqlite import ModelEndpointsTable as SQLiteModelEndpointsTable
|
|
25
|
+
from .sqlite import MonitoringSchedulesTable as SQLiteMonitoringSchedulesTable
|
|
26
|
+
|
|
27
|
+
MySQLTableType = TypeVar("MySQLTableType")
|
|
28
|
+
SQLiteTableType = TypeVar("SQLiteTableType")
|
|
29
|
+
|
|
30
|
+
_MYSQL_SCHEME = "mysql:"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_sql_table(
|
|
34
|
+
*,
|
|
35
|
+
mysql_table: MySQLTableType,
|
|
36
|
+
sqlite_table: SQLiteTableType,
|
|
37
|
+
connection_string: Optional[str] = None,
|
|
38
|
+
) -> Union[MySQLTableType, SQLiteTableType]:
|
|
39
|
+
"""
|
|
40
|
+
Return a SQLAlchemy table for MySQL or SQLite according to the connection string.
|
|
41
|
+
Note: this function should not be directly used in other modules.
|
|
42
|
+
"""
|
|
43
|
+
if connection_string and _MYSQL_SCHEME in connection_string:
|
|
44
|
+
return mysql_table
|
|
45
|
+
return sqlite_table
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
_get_model_endpoints_table = partial(
|
|
49
|
+
_get_sql_table,
|
|
50
|
+
mysql_table=MySQLModelEndpointsTable,
|
|
51
|
+
sqlite_table=SQLiteModelEndpointsTable,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_get_application_result_table = partial(
|
|
56
|
+
_get_sql_table,
|
|
57
|
+
mysql_table=MySQLApplicationResultTable,
|
|
58
|
+
sqlite_table=SQLiteApplicationResultTable,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
_get_application_metrics_table = partial(
|
|
62
|
+
_get_sql_table,
|
|
63
|
+
mysql_table=MySQLApplicationMetricsTable,
|
|
64
|
+
sqlite_table=SQLiteApplicationMetricsTable,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
_get_monitoring_schedules_table = partial(
|
|
68
|
+
_get_sql_table,
|
|
69
|
+
mysql_table=MySQLMonitoringSchedulesTable,
|
|
70
|
+
sqlite_table=SQLiteMonitoringSchedulesTable,
|
|
71
|
+
)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Copyright 2023 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 sqlalchemy import (
|
|
16
|
+
DATETIME,
|
|
17
|
+
TIMESTAMP, # TODO: migrate to DATETIME, see ML-6921
|
|
18
|
+
Boolean,
|
|
19
|
+
Column,
|
|
20
|
+
Float,
|
|
21
|
+
Integer,
|
|
22
|
+
String,
|
|
23
|
+
Text,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from mlrun.common.schemas.model_monitoring import (
|
|
27
|
+
EventFieldType,
|
|
28
|
+
FileTargetKind,
|
|
29
|
+
MetricData,
|
|
30
|
+
ResultData,
|
|
31
|
+
SchedulingKeys,
|
|
32
|
+
WriterEvent,
|
|
33
|
+
)
|
|
34
|
+
from mlrun.utils.db import BaseModel
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ModelEndpointsBaseTable(BaseModel):
|
|
38
|
+
__tablename__ = EventFieldType.MODEL_ENDPOINTS
|
|
39
|
+
|
|
40
|
+
uid = Column(
|
|
41
|
+
EventFieldType.UID,
|
|
42
|
+
String(40),
|
|
43
|
+
primary_key=True,
|
|
44
|
+
)
|
|
45
|
+
state = Column(EventFieldType.STATE, String(10))
|
|
46
|
+
project = Column(EventFieldType.PROJECT, String(40))
|
|
47
|
+
function_uri = Column(
|
|
48
|
+
EventFieldType.FUNCTION_URI,
|
|
49
|
+
String(255),
|
|
50
|
+
)
|
|
51
|
+
model = Column(EventFieldType.MODEL, String(255))
|
|
52
|
+
model_class = Column(
|
|
53
|
+
EventFieldType.MODEL_CLASS,
|
|
54
|
+
String(255),
|
|
55
|
+
)
|
|
56
|
+
labels = Column(EventFieldType.LABELS, Text)
|
|
57
|
+
model_uri = Column(EventFieldType.MODEL_URI, String(255))
|
|
58
|
+
stream_path = Column(EventFieldType.STREAM_PATH, Text)
|
|
59
|
+
algorithm = Column(
|
|
60
|
+
EventFieldType.ALGORITHM,
|
|
61
|
+
String(255),
|
|
62
|
+
)
|
|
63
|
+
active = Column(EventFieldType.ACTIVE, Boolean)
|
|
64
|
+
monitoring_mode = Column(
|
|
65
|
+
EventFieldType.MONITORING_MODE,
|
|
66
|
+
String(10),
|
|
67
|
+
)
|
|
68
|
+
feature_stats = Column(EventFieldType.FEATURE_STATS, Text)
|
|
69
|
+
current_stats = Column(EventFieldType.CURRENT_STATS, Text)
|
|
70
|
+
feature_names = Column(EventFieldType.FEATURE_NAMES, Text)
|
|
71
|
+
children = Column(EventFieldType.CHILDREN, Text)
|
|
72
|
+
label_names = Column(EventFieldType.LABEL_NAMES, Text)
|
|
73
|
+
endpoint_type = Column(
|
|
74
|
+
EventFieldType.ENDPOINT_TYPE,
|
|
75
|
+
String(10),
|
|
76
|
+
)
|
|
77
|
+
children_uids = Column(EventFieldType.CHILDREN_UIDS, Text)
|
|
78
|
+
drift_measures = Column(EventFieldType.DRIFT_MEASURES, Text)
|
|
79
|
+
drift_status = Column(
|
|
80
|
+
EventFieldType.DRIFT_STATUS,
|
|
81
|
+
String(40),
|
|
82
|
+
)
|
|
83
|
+
monitor_configuration = Column(
|
|
84
|
+
EventFieldType.MONITOR_CONFIGURATION,
|
|
85
|
+
Text,
|
|
86
|
+
)
|
|
87
|
+
monitoring_feature_set_uri = Column(
|
|
88
|
+
EventFieldType.FEATURE_SET_URI,
|
|
89
|
+
String(255),
|
|
90
|
+
)
|
|
91
|
+
error_count = Column(EventFieldType.ERROR_COUNT, Integer)
|
|
92
|
+
metrics = Column(EventFieldType.METRICS, Text)
|
|
93
|
+
first_request = Column(
|
|
94
|
+
EventFieldType.FIRST_REQUEST,
|
|
95
|
+
TIMESTAMP(timezone=True), # TODO: migrate to DATETIME, see ML-6921
|
|
96
|
+
)
|
|
97
|
+
last_request = Column(
|
|
98
|
+
EventFieldType.LAST_REQUEST,
|
|
99
|
+
TIMESTAMP(timezone=True), # TODO: migrate to DATETIME, see ML-6921
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ApplicationResultBaseTable(BaseModel):
|
|
104
|
+
__tablename__ = FileTargetKind.APP_RESULTS
|
|
105
|
+
|
|
106
|
+
uid = Column(EventFieldType.UID, String(120), primary_key=True)
|
|
107
|
+
|
|
108
|
+
application_name = Column(
|
|
109
|
+
WriterEvent.APPLICATION_NAME,
|
|
110
|
+
String(40),
|
|
111
|
+
nullable=True,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
endpoint_id = Column(
|
|
115
|
+
WriterEvent.ENDPOINT_ID,
|
|
116
|
+
String(40),
|
|
117
|
+
nullable=True,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
result_name = Column(
|
|
121
|
+
ResultData.RESULT_NAME,
|
|
122
|
+
String(40),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
start_infer_time = Column(
|
|
126
|
+
WriterEvent.START_INFER_TIME,
|
|
127
|
+
DATETIME(timezone=True),
|
|
128
|
+
)
|
|
129
|
+
end_infer_time = Column(
|
|
130
|
+
WriterEvent.END_INFER_TIME,
|
|
131
|
+
DATETIME(timezone=True),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
result_status = Column(ResultData.RESULT_STATUS, String(10))
|
|
135
|
+
result_kind = Column(ResultData.RESULT_KIND, String(40))
|
|
136
|
+
result_value = Column(ResultData.RESULT_VALUE, Float)
|
|
137
|
+
result_extra_data = Column(ResultData.RESULT_EXTRA_DATA, Text)
|
|
138
|
+
current_stats = Column(ResultData.CURRENT_STATS, Text)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class ApplicationMetricsBaseTable(BaseModel):
|
|
142
|
+
__tablename__ = FileTargetKind.APP_METRICS
|
|
143
|
+
|
|
144
|
+
uid = Column(EventFieldType.UID, String(120), primary_key=True)
|
|
145
|
+
application_name = Column(
|
|
146
|
+
WriterEvent.APPLICATION_NAME,
|
|
147
|
+
String(40),
|
|
148
|
+
nullable=True,
|
|
149
|
+
)
|
|
150
|
+
endpoint_id = Column(
|
|
151
|
+
WriterEvent.ENDPOINT_ID,
|
|
152
|
+
String(40),
|
|
153
|
+
nullable=True,
|
|
154
|
+
)
|
|
155
|
+
start_infer_time = Column(
|
|
156
|
+
WriterEvent.START_INFER_TIME,
|
|
157
|
+
DATETIME(timezone=True),
|
|
158
|
+
)
|
|
159
|
+
end_infer_time = Column(
|
|
160
|
+
WriterEvent.END_INFER_TIME,
|
|
161
|
+
DATETIME(timezone=True),
|
|
162
|
+
)
|
|
163
|
+
metric_name = Column(
|
|
164
|
+
MetricData.METRIC_NAME,
|
|
165
|
+
String(40),
|
|
166
|
+
)
|
|
167
|
+
metric_value = Column(MetricData.METRIC_VALUE, Float)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class MonitoringSchedulesBaseTable(BaseModel):
|
|
171
|
+
__tablename__ = FileTargetKind.MONITORING_SCHEDULES
|
|
172
|
+
|
|
173
|
+
uid = Column(SchedulingKeys.UID, String(32), primary_key=True)
|
|
174
|
+
|
|
175
|
+
application_name = Column(
|
|
176
|
+
SchedulingKeys.APPLICATION_NAME,
|
|
177
|
+
String(40),
|
|
178
|
+
nullable=False,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
endpoint_id = Column(
|
|
182
|
+
SchedulingKeys.ENDPOINT_ID,
|
|
183
|
+
String(40),
|
|
184
|
+
nullable=False,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
last_analyzed = Column(
|
|
188
|
+
SchedulingKeys.LAST_ANALYZED,
|
|
189
|
+
Integer,
|
|
190
|
+
)
|