mlrun 1.8.0rc1__py3-none-any.whl → 1.8.0rc3__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 +5 -7
- mlrun/__main__.py +1 -1
- mlrun/artifacts/__init__.py +1 -0
- mlrun/artifacts/document.py +313 -0
- mlrun/artifacts/manager.py +2 -0
- mlrun/common/formatters/project.py +9 -0
- mlrun/common/schemas/__init__.py +4 -0
- mlrun/common/schemas/alert.py +31 -18
- mlrun/common/schemas/api_gateway.py +3 -3
- mlrun/common/schemas/artifact.py +7 -7
- mlrun/common/schemas/auth.py +6 -4
- mlrun/common/schemas/background_task.py +7 -7
- mlrun/common/schemas/client_spec.py +2 -2
- mlrun/common/schemas/clusterization_spec.py +2 -2
- mlrun/common/schemas/common.py +5 -5
- mlrun/common/schemas/constants.py +15 -0
- mlrun/common/schemas/datastore_profile.py +1 -1
- mlrun/common/schemas/feature_store.py +9 -9
- mlrun/common/schemas/frontend_spec.py +4 -4
- mlrun/common/schemas/function.py +10 -10
- mlrun/common/schemas/hub.py +1 -1
- mlrun/common/schemas/k8s.py +3 -3
- mlrun/common/schemas/memory_reports.py +3 -3
- mlrun/common/schemas/model_monitoring/grafana.py +1 -1
- mlrun/common/schemas/model_monitoring/model_endpoint_v2.py +1 -1
- mlrun/common/schemas/model_monitoring/model_endpoints.py +1 -1
- mlrun/common/schemas/notification.py +18 -3
- mlrun/common/schemas/object.py +1 -1
- mlrun/common/schemas/pagination.py +4 -4
- mlrun/common/schemas/partition.py +16 -1
- mlrun/common/schemas/pipeline.py +2 -2
- mlrun/common/schemas/project.py +22 -17
- mlrun/common/schemas/runs.py +2 -2
- mlrun/common/schemas/runtime_resource.py +5 -5
- mlrun/common/schemas/schedule.py +1 -1
- mlrun/common/schemas/secret.py +1 -1
- mlrun/common/schemas/tag.py +3 -3
- mlrun/common/schemas/workflow.py +5 -5
- mlrun/config.py +23 -1
- mlrun/datastore/datastore_profile.py +38 -19
- mlrun/datastore/vectorstore.py +186 -0
- mlrun/db/base.py +58 -6
- mlrun/db/httpdb.py +267 -15
- mlrun/db/nopdb.py +44 -5
- mlrun/execution.py +47 -1
- mlrun/model.py +2 -2
- mlrun/model_monitoring/applications/results.py +2 -2
- mlrun/model_monitoring/db/tsdb/base.py +2 -2
- mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +37 -13
- mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +32 -40
- mlrun/model_monitoring/helpers.py +4 -10
- mlrun/model_monitoring/stream_processing.py +14 -11
- mlrun/platforms/__init__.py +44 -13
- mlrun/projects/__init__.py +6 -1
- mlrun/projects/pipelines.py +184 -55
- mlrun/projects/project.py +309 -33
- mlrun/run.py +4 -1
- mlrun/runtimes/base.py +2 -1
- mlrun/runtimes/mounts.py +572 -0
- mlrun/runtimes/nuclio/function.py +1 -2
- mlrun/runtimes/pod.py +82 -18
- mlrun/runtimes/remotesparkjob.py +1 -1
- mlrun/runtimes/sparkjob/spark3job.py +1 -1
- mlrun/utils/clones.py +1 -1
- mlrun/utils/helpers.py +12 -2
- mlrun/utils/logger.py +2 -2
- mlrun/utils/notifications/notification/__init__.py +22 -19
- mlrun/utils/notifications/notification/base.py +12 -12
- mlrun/utils/notifications/notification/console.py +6 -6
- mlrun/utils/notifications/notification/git.py +6 -6
- mlrun/utils/notifications/notification/ipython.py +6 -6
- mlrun/utils/notifications/notification/mail.py +149 -0
- mlrun/utils/notifications/notification/slack.py +6 -6
- mlrun/utils/notifications/notification/webhook.py +6 -6
- mlrun/utils/notifications/notification_pusher.py +20 -12
- mlrun/utils/regex.py +2 -0
- mlrun/utils/version/version.json +2 -2
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/METADATA +190 -186
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/RECORD +83 -79
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/WHEEL +1 -1
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/LICENSE +0 -0
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/entry_points.txt +0 -0
- {mlrun-1.8.0rc1.dist-info → mlrun-1.8.0rc3.dist-info}/top_level.txt +0 -0
mlrun/projects/project.py
CHANGED
|
@@ -41,6 +41,7 @@ import mlrun.artifacts.model
|
|
|
41
41
|
import mlrun.common.formatters
|
|
42
42
|
import mlrun.common.helpers
|
|
43
43
|
import mlrun.common.runtimes.constants
|
|
44
|
+
import mlrun.common.schemas.alert
|
|
44
45
|
import mlrun.common.schemas.artifact
|
|
45
46
|
import mlrun.common.schemas.model_monitoring.constants as mm_constants
|
|
46
47
|
import mlrun.db
|
|
@@ -49,6 +50,7 @@ import mlrun.k8s_utils
|
|
|
49
50
|
import mlrun.lists
|
|
50
51
|
import mlrun.model_monitoring.applications as mm_app
|
|
51
52
|
import mlrun.runtimes
|
|
53
|
+
import mlrun.runtimes.mounts
|
|
52
54
|
import mlrun.runtimes.nuclio.api_gateway
|
|
53
55
|
import mlrun.runtimes.pod
|
|
54
56
|
import mlrun.runtimes.utils
|
|
@@ -56,14 +58,25 @@ import mlrun.serving
|
|
|
56
58
|
import mlrun.utils
|
|
57
59
|
import mlrun.utils.regex
|
|
58
60
|
import mlrun_pipelines.common.models
|
|
59
|
-
import mlrun_pipelines.mounts
|
|
60
61
|
from mlrun.alerts.alert import AlertConfig
|
|
61
|
-
from mlrun.
|
|
62
|
-
|
|
62
|
+
from mlrun.datastore.datastore_profile import (
|
|
63
|
+
DatastoreProfile,
|
|
64
|
+
DatastoreProfile2Json,
|
|
65
|
+
VectorStoreProfile,
|
|
66
|
+
datastore_profile_read,
|
|
67
|
+
)
|
|
68
|
+
from mlrun.datastore.vectorstore import VectorStoreCollection
|
|
63
69
|
from mlrun.runtimes.nuclio.function import RemoteRuntime
|
|
64
70
|
from mlrun_pipelines.models import PipelineNodeWrapper
|
|
65
71
|
|
|
66
|
-
from ..artifacts import
|
|
72
|
+
from ..artifacts import (
|
|
73
|
+
Artifact,
|
|
74
|
+
ArtifactProducer,
|
|
75
|
+
DatasetArtifact,
|
|
76
|
+
DocumentArtifact,
|
|
77
|
+
DocumentLoaderSpec,
|
|
78
|
+
ModelArtifact,
|
|
79
|
+
)
|
|
67
80
|
from ..artifacts.manager import ArtifactManager, dict_to_artifact, extend_artifact_path
|
|
68
81
|
from ..datastore import store_manager
|
|
69
82
|
from ..features import Feature
|
|
@@ -1520,6 +1533,10 @@ class MlrunProject(ModelObj):
|
|
|
1520
1533
|
is_retained_producer=is_retained_producer,
|
|
1521
1534
|
)
|
|
1522
1535
|
|
|
1536
|
+
def update_artifact(self, artifact_object: Artifact):
|
|
1537
|
+
artifacts_manager = self._get_artifact_manager()
|
|
1538
|
+
artifacts_manager.update_artifact(artifact_object, artifact_object)
|
|
1539
|
+
|
|
1523
1540
|
def _get_artifact_manager(self):
|
|
1524
1541
|
if self._artifact_manager:
|
|
1525
1542
|
return self._artifact_manager
|
|
@@ -1839,6 +1856,72 @@ class MlrunProject(ModelObj):
|
|
|
1839
1856
|
)
|
|
1840
1857
|
return item
|
|
1841
1858
|
|
|
1859
|
+
def get_or_create_vector_store_collection(
|
|
1860
|
+
self,
|
|
1861
|
+
collection_name: str,
|
|
1862
|
+
profile: Union[str, VectorStoreProfile],
|
|
1863
|
+
**kwargs,
|
|
1864
|
+
) -> VectorStoreCollection:
|
|
1865
|
+
"""
|
|
1866
|
+
Create or retrieve a VectorStoreCollection.
|
|
1867
|
+
|
|
1868
|
+
:param collection_name: Name of the collection
|
|
1869
|
+
:param profile: Name of the VectorStoreProfile or a VectorStoreProfile object
|
|
1870
|
+
:param kwargs: Additional arguments for the VectorStoreCollection
|
|
1871
|
+
:return: VectorStoreCollection object
|
|
1872
|
+
"""
|
|
1873
|
+
if isinstance(profile, str):
|
|
1874
|
+
profile = datastore_profile_read(f"ds://{profile}")
|
|
1875
|
+
|
|
1876
|
+
if not isinstance(profile, VectorStoreProfile):
|
|
1877
|
+
raise ValueError(
|
|
1878
|
+
"Profile must be a VectorStoreProfile object or a profile name"
|
|
1879
|
+
)
|
|
1880
|
+
return VectorStoreCollection(
|
|
1881
|
+
profile.vector_store_class,
|
|
1882
|
+
self,
|
|
1883
|
+
profile.name,
|
|
1884
|
+
collection_name,
|
|
1885
|
+
**profile.attributes(kwargs),
|
|
1886
|
+
)
|
|
1887
|
+
|
|
1888
|
+
def log_document(
|
|
1889
|
+
self,
|
|
1890
|
+
key: str,
|
|
1891
|
+
artifact_path: Optional[str] = None,
|
|
1892
|
+
document_loader: DocumentLoaderSpec = DocumentLoaderSpec(),
|
|
1893
|
+
tag: str = "",
|
|
1894
|
+
upload: Optional[bool] = False,
|
|
1895
|
+
labels: Optional[dict[str, str]] = None,
|
|
1896
|
+
**kwargs,
|
|
1897
|
+
) -> DocumentArtifact:
|
|
1898
|
+
"""
|
|
1899
|
+
Log a document as an artifact.
|
|
1900
|
+
|
|
1901
|
+
:param key: Artifact key
|
|
1902
|
+
:param target_path: Path to the local file
|
|
1903
|
+
:param artifact_path: Target path for artifact storage
|
|
1904
|
+
:param document_loader: Spec to use to load the artifact as langchain document
|
|
1905
|
+
:param tag: Version tag
|
|
1906
|
+
:param upload: Whether to upload the artifact
|
|
1907
|
+
:param labels: Key-value labels
|
|
1908
|
+
:param kwargs: Additional keyword arguments
|
|
1909
|
+
:return: DocumentArtifact object
|
|
1910
|
+
"""
|
|
1911
|
+
doc_artifact = DocumentArtifact(
|
|
1912
|
+
key=key,
|
|
1913
|
+
document_loader=document_loader,
|
|
1914
|
+
**kwargs,
|
|
1915
|
+
)
|
|
1916
|
+
|
|
1917
|
+
return self.log_artifact(
|
|
1918
|
+
doc_artifact,
|
|
1919
|
+
artifact_path=artifact_path,
|
|
1920
|
+
tag=tag,
|
|
1921
|
+
upload=upload,
|
|
1922
|
+
labels=labels,
|
|
1923
|
+
)
|
|
1924
|
+
|
|
1842
1925
|
def import_artifact(
|
|
1843
1926
|
self, item_path: str, new_key=None, artifact_path=None, tag=None
|
|
1844
1927
|
):
|
|
@@ -1995,8 +2078,6 @@ class MlrunProject(ModelObj):
|
|
|
1995
2078
|
:param application_kwargs: Additional keyword arguments to be passed to the
|
|
1996
2079
|
monitoring application's constructor.
|
|
1997
2080
|
"""
|
|
1998
|
-
|
|
1999
|
-
function_object: RemoteRuntime = None
|
|
2000
2081
|
(
|
|
2001
2082
|
resolved_function_name,
|
|
2002
2083
|
function_object,
|
|
@@ -2094,7 +2175,6 @@ class MlrunProject(ModelObj):
|
|
|
2094
2175
|
) -> tuple[str, mlrun.runtimes.BaseRuntime, dict]:
|
|
2095
2176
|
import mlrun.model_monitoring.api
|
|
2096
2177
|
|
|
2097
|
-
function_object: RemoteRuntime = None
|
|
2098
2178
|
kind = None
|
|
2099
2179
|
if (isinstance(func, str) or func is None) and application_class is not None:
|
|
2100
2180
|
kind = mlrun.run.RuntimeKinds.serving
|
|
@@ -2133,9 +2213,6 @@ class MlrunProject(ModelObj):
|
|
|
2133
2213
|
mm_constants.ModelMonitoringAppLabel.VAL,
|
|
2134
2214
|
)
|
|
2135
2215
|
|
|
2136
|
-
if not mlrun.mlconf.is_ce_mode():
|
|
2137
|
-
function_object.apply(mlrun.mount_v3io())
|
|
2138
|
-
|
|
2139
2216
|
return resolved_function_name, function_object, func
|
|
2140
2217
|
|
|
2141
2218
|
def _wait_for_functions_deployment(self, function_names: list[str]) -> None:
|
|
@@ -3390,6 +3467,61 @@ class MlrunProject(ModelObj):
|
|
|
3390
3467
|
"and set `rebuild_images=True`"
|
|
3391
3468
|
)
|
|
3392
3469
|
|
|
3470
|
+
def list_model_endpoints(
|
|
3471
|
+
self,
|
|
3472
|
+
model: Optional[str] = None,
|
|
3473
|
+
function: Optional[str] = None,
|
|
3474
|
+
labels: Optional[list[str]] = None,
|
|
3475
|
+
start: str = "now-1h",
|
|
3476
|
+
end: str = "now",
|
|
3477
|
+
top_level: bool = False,
|
|
3478
|
+
uids: Optional[list[str]] = None,
|
|
3479
|
+
) -> list[mlrun.model_monitoring.model_endpoint.ModelEndpoint]:
|
|
3480
|
+
"""
|
|
3481
|
+
Returns a list of `ModelEndpoint` objects. Each `ModelEndpoint` object represents the current state of a
|
|
3482
|
+
model endpoint. This functions supports filtering by the following parameters:
|
|
3483
|
+
1) model
|
|
3484
|
+
2) function
|
|
3485
|
+
3) labels
|
|
3486
|
+
4) top level
|
|
3487
|
+
5) uids
|
|
3488
|
+
By default, when no filters are applied, all available endpoints for the given project will be listed.
|
|
3489
|
+
|
|
3490
|
+
In addition, this functions provides a facade for listing endpoint related metrics. This facade is time-based
|
|
3491
|
+
and depends on the 'start' and 'end' parameters.
|
|
3492
|
+
|
|
3493
|
+
:param model: The name of the model to filter by
|
|
3494
|
+
:param function: The name of the function to filter by
|
|
3495
|
+
:param labels: Filter model endpoints by label key-value pairs or key existence. This can be provided as:
|
|
3496
|
+
- A dictionary in the format `{"label": "value"}` to match specific label key-value pairs,
|
|
3497
|
+
or `{"label": None}` to check for key existence.
|
|
3498
|
+
- A list of strings formatted as `"label=value"` to match specific label key-value pairs,
|
|
3499
|
+
or just `"label"` for key existence.
|
|
3500
|
+
- A comma-separated string formatted as `"label1=value1,label2"` to match entities with
|
|
3501
|
+
the specified key-value pairs or key existence.
|
|
3502
|
+
:param start: The start time of the metrics. Can be represented by a string containing an RFC 3339 time, a
|
|
3503
|
+
Unix timestamp in milliseconds, a relative time (`'now'` or `'now-[0-9]+[mhd]'`, where
|
|
3504
|
+
`m` = minutes, `h` = hours, `'d'` = days, and `'s'` = seconds), or 0 for the earliest time.
|
|
3505
|
+
:param end: The end time of the metrics. Can be represented by a string containing an RFC 3339 time, a
|
|
3506
|
+
Unix timestamp in milliseconds, a relative time (`'now'` or `'now-[0-9]+[mhd]'`, where
|
|
3507
|
+
`m` = minutes, `h` = hours, `'d'` = days, and `'s'` = seconds), or 0 for the earliest time.
|
|
3508
|
+
:param top_level: if true will return only routers and endpoint that are NOT children of any router
|
|
3509
|
+
:param uids: if passed will return a list `ModelEndpoint` object with uid in uids
|
|
3510
|
+
|
|
3511
|
+
:returns: Returns a list of `ModelEndpoint` objects.
|
|
3512
|
+
"""
|
|
3513
|
+
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
3514
|
+
return db.list_model_endpoints(
|
|
3515
|
+
project=self.name,
|
|
3516
|
+
model=model,
|
|
3517
|
+
function=function,
|
|
3518
|
+
labels=labels,
|
|
3519
|
+
start=start,
|
|
3520
|
+
end=end,
|
|
3521
|
+
top_level=top_level,
|
|
3522
|
+
uids=uids,
|
|
3523
|
+
)
|
|
3524
|
+
|
|
3393
3525
|
def run_function(
|
|
3394
3526
|
self,
|
|
3395
3527
|
function: typing.Union[str, mlrun.runtimes.BaseRuntime],
|
|
@@ -3809,6 +3941,16 @@ class MlrunProject(ModelObj):
|
|
|
3809
3941
|
format_: Optional[
|
|
3810
3942
|
mlrun.common.formatters.ArtifactFormat
|
|
3811
3943
|
] = mlrun.common.formatters.ArtifactFormat.full,
|
|
3944
|
+
partition_by: Optional[
|
|
3945
|
+
Union[mlrun.common.schemas.ArtifactPartitionByField, str]
|
|
3946
|
+
] = None,
|
|
3947
|
+
rows_per_partition: int = 1,
|
|
3948
|
+
partition_sort_by: Optional[
|
|
3949
|
+
Union[mlrun.common.schemas.SortField, str]
|
|
3950
|
+
] = mlrun.common.schemas.SortField.updated,
|
|
3951
|
+
partition_order: Union[
|
|
3952
|
+
mlrun.common.schemas.OrderType, str
|
|
3953
|
+
] = mlrun.common.schemas.OrderType.desc,
|
|
3812
3954
|
) -> mlrun.lists.ArtifactList:
|
|
3813
3955
|
"""List artifacts filtered by various parameters.
|
|
3814
3956
|
|
|
@@ -3845,6 +3987,13 @@ class MlrunProject(ModelObj):
|
|
|
3845
3987
|
:param tree: Return artifacts of the requested tree.
|
|
3846
3988
|
:param limit: Maximum number of artifacts to return.
|
|
3847
3989
|
:param format_: The format in which to return the artifacts. Default is 'full'.
|
|
3990
|
+
:param partition_by: Field to group results by. When `partition_by` is specified, the `partition_sort_by`
|
|
3991
|
+
parameter must be provided as well.
|
|
3992
|
+
:param rows_per_partition: How many top rows (per sorting defined by `partition_sort_by` and `partition_order`)
|
|
3993
|
+
to return per group. Default value is 1.
|
|
3994
|
+
:param partition_sort_by: What field to sort the results by, within each partition defined by `partition_by`.
|
|
3995
|
+
Currently the only allowed values are `created` and `updated`.
|
|
3996
|
+
:param partition_order: Order of sorting within partitions - `asc` or `desc`. Default is `desc`.
|
|
3848
3997
|
"""
|
|
3849
3998
|
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
3850
3999
|
return db.list_artifacts(
|
|
@@ -3861,6 +4010,10 @@ class MlrunProject(ModelObj):
|
|
|
3861
4010
|
tree=tree,
|
|
3862
4011
|
format_=format_,
|
|
3863
4012
|
limit=limit,
|
|
4013
|
+
partition_by=partition_by,
|
|
4014
|
+
rows_per_partition=rows_per_partition,
|
|
4015
|
+
partition_sort_by=partition_sort_by,
|
|
4016
|
+
partition_order=partition_order,
|
|
3864
4017
|
)
|
|
3865
4018
|
|
|
3866
4019
|
def paginated_list_artifacts(
|
|
@@ -4051,6 +4204,8 @@ class MlrunProject(ModelObj):
|
|
|
4051
4204
|
name: Optional[str] = None,
|
|
4052
4205
|
tag: Optional[str] = None,
|
|
4053
4206
|
labels: Optional[Union[str, dict[str, Optional[str]], list[str]]] = None,
|
|
4207
|
+
kind: Optional[str] = None,
|
|
4208
|
+
format_: Optional[str] = None,
|
|
4054
4209
|
):
|
|
4055
4210
|
"""Retrieve a list of functions, filtered by specific criteria.
|
|
4056
4211
|
|
|
@@ -4068,10 +4223,19 @@ class MlrunProject(ModelObj):
|
|
|
4068
4223
|
or just `"label"` for key existence.
|
|
4069
4224
|
- A comma-separated string formatted as `"label1=value1,label2"` to match entities with
|
|
4070
4225
|
the specified key-value pairs or key existence.
|
|
4226
|
+
:param kind: Return functions of the specified kind. If not provided, all function kinds will be returned.
|
|
4227
|
+
:param format_: The format in which to return the functions. Default is 'full'.
|
|
4071
4228
|
:returns: List of function objects.
|
|
4072
4229
|
"""
|
|
4073
4230
|
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
4074
|
-
functions = db.list_functions(
|
|
4231
|
+
functions = db.list_functions(
|
|
4232
|
+
name,
|
|
4233
|
+
project=self.metadata.name,
|
|
4234
|
+
tag=tag,
|
|
4235
|
+
kind=kind,
|
|
4236
|
+
labels=labels,
|
|
4237
|
+
format_=format_,
|
|
4238
|
+
)
|
|
4075
4239
|
if functions:
|
|
4076
4240
|
# convert dict to function objects
|
|
4077
4241
|
return [mlrun.new_function(runtime=func) for func in functions]
|
|
@@ -4133,9 +4297,8 @@ class MlrunProject(ModelObj):
|
|
|
4133
4297
|
page_token=page_token,
|
|
4134
4298
|
**kwargs,
|
|
4135
4299
|
)
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
return [mlrun.new_function(runtime=func) for func in functions], token
|
|
4300
|
+
# convert dict to function objects
|
|
4301
|
+
return [mlrun.new_function(runtime=func) for func in functions], token
|
|
4139
4302
|
|
|
4140
4303
|
def list_model_monitoring_functions(
|
|
4141
4304
|
self,
|
|
@@ -4241,9 +4404,11 @@ class MlrunProject(ModelObj):
|
|
|
4241
4404
|
uid,
|
|
4242
4405
|
self.metadata.name,
|
|
4243
4406
|
labels=labels,
|
|
4244
|
-
states=
|
|
4245
|
-
|
|
4246
|
-
|
|
4407
|
+
states=(
|
|
4408
|
+
mlrun.utils.helpers.as_list(state)
|
|
4409
|
+
if state is not None
|
|
4410
|
+
else states or None
|
|
4411
|
+
),
|
|
4247
4412
|
sort=sort,
|
|
4248
4413
|
last=last,
|
|
4249
4414
|
iter=iter,
|
|
@@ -4555,7 +4720,9 @@ class MlrunProject(ModelObj):
|
|
|
4555
4720
|
alert_name = alert_data.name
|
|
4556
4721
|
db.reset_alert_config(alert_name, self.metadata.name)
|
|
4557
4722
|
|
|
4558
|
-
def get_alert_template(
|
|
4723
|
+
def get_alert_template(
|
|
4724
|
+
self, template_name: str
|
|
4725
|
+
) -> mlrun.common.schemas.alert.AlertTemplate:
|
|
4559
4726
|
"""
|
|
4560
4727
|
Retrieve a specific alert template.
|
|
4561
4728
|
|
|
@@ -4565,7 +4732,7 @@ class MlrunProject(ModelObj):
|
|
|
4565
4732
|
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
4566
4733
|
return db.get_alert_template(template_name)
|
|
4567
4734
|
|
|
4568
|
-
def list_alert_templates(self) -> list[AlertTemplate]:
|
|
4735
|
+
def list_alert_templates(self) -> list[mlrun.common.schemas.alert.AlertTemplate]:
|
|
4569
4736
|
"""
|
|
4570
4737
|
Retrieve list of all alert templates.
|
|
4571
4738
|
|
|
@@ -4574,6 +4741,109 @@ class MlrunProject(ModelObj):
|
|
|
4574
4741
|
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
4575
4742
|
return db.list_alert_templates()
|
|
4576
4743
|
|
|
4744
|
+
def list_alert_activations(
|
|
4745
|
+
self,
|
|
4746
|
+
name: Optional[str] = None,
|
|
4747
|
+
since: Optional[datetime.datetime] = None,
|
|
4748
|
+
until: Optional[datetime.datetime] = None,
|
|
4749
|
+
entity: Optional[str] = None,
|
|
4750
|
+
severity: Optional[
|
|
4751
|
+
list[Union[mlrun.common.schemas.alert.AlertSeverity, str]]
|
|
4752
|
+
] = None,
|
|
4753
|
+
entity_kind: Optional[
|
|
4754
|
+
Union[mlrun.common.schemas.alert.EventEntityKind, str]
|
|
4755
|
+
] = None,
|
|
4756
|
+
event_kind: Optional[Union[mlrun.common.schemas.alert.EventKind, str]] = None,
|
|
4757
|
+
) -> list[mlrun.common.schemas.alert.AlertActivation]:
|
|
4758
|
+
"""
|
|
4759
|
+
Retrieve a list of alert activations for a project.
|
|
4760
|
+
|
|
4761
|
+
:param name: The alert name to filter by. Supports exact matching or partial matching if prefixed with `~`.
|
|
4762
|
+
:param since: Filters for alert activations occurring after this timestamp.
|
|
4763
|
+
:param until: Filters for alert activations occurring before this timestamp.
|
|
4764
|
+
:param entity: The entity ID to filter by. Supports wildcard matching if prefixed with `~`.
|
|
4765
|
+
:param severity: A list of severity levels to filter by (e.g., ["high", "low"]).
|
|
4766
|
+
:param entity_kind: The kind of entity (e.g., "job", "endpoint") to filter by.
|
|
4767
|
+
:param event_kind: The kind of event (e.g., ""data-drift-detected"", "failed") to filter by.
|
|
4768
|
+
|
|
4769
|
+
:returns: A list of alert activations matching the provided filters.
|
|
4770
|
+
"""
|
|
4771
|
+
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
4772
|
+
return db.list_alert_activations(
|
|
4773
|
+
project=self.metadata.name,
|
|
4774
|
+
name=name,
|
|
4775
|
+
since=since,
|
|
4776
|
+
until=until,
|
|
4777
|
+
entity=entity,
|
|
4778
|
+
severity=severity,
|
|
4779
|
+
entity_kind=entity_kind,
|
|
4780
|
+
event_kind=event_kind,
|
|
4781
|
+
)
|
|
4782
|
+
|
|
4783
|
+
def paginated_list_alert_activations(
|
|
4784
|
+
self,
|
|
4785
|
+
*args,
|
|
4786
|
+
page: Optional[int] = None,
|
|
4787
|
+
page_size: Optional[int] = None,
|
|
4788
|
+
page_token: Optional[str] = None,
|
|
4789
|
+
**kwargs,
|
|
4790
|
+
) -> tuple[mlrun.common.schemas.alert.AlertActivation, Optional[str]]:
|
|
4791
|
+
"""
|
|
4792
|
+
List alerts activations with support for pagination and various filtering options.
|
|
4793
|
+
|
|
4794
|
+
This method retrieves a paginated list of alert activations based on the specified filter parameters.
|
|
4795
|
+
Pagination is controlled using the `page`, `page_size`, and `page_token` parameters. The method
|
|
4796
|
+
will return a list of alert activations that match the filtering criteria provided.
|
|
4797
|
+
|
|
4798
|
+
For detailed information about the parameters, refer to the list_alert_activations method:
|
|
4799
|
+
See :py:func:`~list_alert_activations` for more details.
|
|
4800
|
+
|
|
4801
|
+
Examples::
|
|
4802
|
+
|
|
4803
|
+
# Fetch first page of alert activations with page size of 5
|
|
4804
|
+
alert_activations, token = project.paginated_list_alert_activations(page_size=5)
|
|
4805
|
+
# Fetch next page using the pagination token from the previous response
|
|
4806
|
+
alert_activations, token = project.paginated_list_alert_activations(
|
|
4807
|
+
page_token=token
|
|
4808
|
+
)
|
|
4809
|
+
# Fetch alert activations for a specific page (e.g., page 3)
|
|
4810
|
+
alert_activations, token = project.paginated_list_alert_activations(
|
|
4811
|
+
page=3, page_size=5
|
|
4812
|
+
)
|
|
4813
|
+
|
|
4814
|
+
# Automatically iterate over all pages without explicitly specifying the page number
|
|
4815
|
+
alert_activations = []
|
|
4816
|
+
token = None
|
|
4817
|
+
while True:
|
|
4818
|
+
page_alert_activations, token = project.paginated_list_alert_activations(
|
|
4819
|
+
page_token=token, page_size=5
|
|
4820
|
+
)
|
|
4821
|
+
alert_activations.extend(page_alert_activations)
|
|
4822
|
+
|
|
4823
|
+
# If token is None and page_alert_activations is empty, we've reached the end (no more activations).
|
|
4824
|
+
# If token is None and page_alert_activations is not empty, we've fetched the last page of activations.
|
|
4825
|
+
if not token:
|
|
4826
|
+
break
|
|
4827
|
+
print(f"Total alert activations retrieved: {len(alert_activations)}")
|
|
4828
|
+
|
|
4829
|
+
:param page: The page number to retrieve. If not provided, the next page will be retrieved.
|
|
4830
|
+
:param page_size: The number of items per page to retrieve. Up to `page_size` responses are expected.
|
|
4831
|
+
:param page_token: A pagination token used to retrieve the next page of results. Should not be provided
|
|
4832
|
+
for the first request.
|
|
4833
|
+
|
|
4834
|
+
:returns: A tuple containing the list of alert activations and an optional `page_token` for pagination.
|
|
4835
|
+
"""
|
|
4836
|
+
db = mlrun.db.get_run_db(secrets=self._secrets)
|
|
4837
|
+
return db.paginated_list_alert_activations(
|
|
4838
|
+
*args,
|
|
4839
|
+
project=self.metadata.name,
|
|
4840
|
+
page=page,
|
|
4841
|
+
page_size=page_size,
|
|
4842
|
+
page_token=page_token,
|
|
4843
|
+
return_all=False,
|
|
4844
|
+
**kwargs,
|
|
4845
|
+
)
|
|
4846
|
+
|
|
4577
4847
|
def _run_authenticated_git_action(
|
|
4578
4848
|
self,
|
|
4579
4849
|
action: Callable,
|
|
@@ -4686,23 +4956,29 @@ class MlrunProject(ModelObj):
|
|
|
4686
4956
|
)
|
|
4687
4957
|
|
|
4688
4958
|
if producer_dict.get("kind", "") == "run":
|
|
4689
|
-
return
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4959
|
+
return (
|
|
4960
|
+
ArtifactProducer(
|
|
4961
|
+
name=producer_dict.get("name", ""),
|
|
4962
|
+
kind=producer_dict.get("kind", ""),
|
|
4963
|
+
project=producer_project,
|
|
4964
|
+
tag=producer_tag,
|
|
4965
|
+
owner=producer_dict.get("owner", ""),
|
|
4966
|
+
),
|
|
4967
|
+
True,
|
|
4968
|
+
)
|
|
4696
4969
|
|
|
4697
4970
|
# do not retain the artifact's producer, replace it with the project as the producer
|
|
4698
4971
|
project_producer_tag = project_producer_tag or self._get_project_tag()
|
|
4699
|
-
return
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4972
|
+
return (
|
|
4973
|
+
ArtifactProducer(
|
|
4974
|
+
kind="project",
|
|
4975
|
+
name=self.metadata.name,
|
|
4976
|
+
project=self.metadata.name,
|
|
4977
|
+
tag=project_producer_tag,
|
|
4978
|
+
owner=self._resolve_artifact_owner(),
|
|
4979
|
+
),
|
|
4980
|
+
False,
|
|
4981
|
+
)
|
|
4706
4982
|
|
|
4707
4983
|
def _resolve_existing_artifact(
|
|
4708
4984
|
self,
|
mlrun/run.py
CHANGED
|
@@ -73,6 +73,9 @@ from .utils import (
|
|
|
73
73
|
update_in,
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
+
if typing.TYPE_CHECKING:
|
|
77
|
+
from mlrun.datastore import DataItem
|
|
78
|
+
|
|
76
79
|
|
|
77
80
|
def function_to_module(code="", workdir=None, secrets=None, silent=False):
|
|
78
81
|
"""Load code, notebook or mlrun function as .py module
|
|
@@ -1089,7 +1092,7 @@ def get_object(url, secrets=None, size=None, offset=0, db=None):
|
|
|
1089
1092
|
return stores.object(url=url).get(size, offset)
|
|
1090
1093
|
|
|
1091
1094
|
|
|
1092
|
-
def get_dataitem(url, secrets=None, db=None) ->
|
|
1095
|
+
def get_dataitem(url, secrets=None, db=None) -> "DataItem":
|
|
1093
1096
|
"""get mlrun dataitem object (from path/url)"""
|
|
1094
1097
|
stores = store_manager.set(secrets, db=db)
|
|
1095
1098
|
return stores.object(url=url)
|
mlrun/runtimes/base.py
CHANGED
|
@@ -25,9 +25,10 @@ from nuclio.build import mlrun_footer
|
|
|
25
25
|
|
|
26
26
|
import mlrun.common.constants
|
|
27
27
|
import mlrun.common.constants as mlrun_constants
|
|
28
|
+
import mlrun.common.formatters
|
|
29
|
+
import mlrun.common.runtimes
|
|
28
30
|
import mlrun.common.schemas
|
|
29
31
|
import mlrun.common.schemas.model_monitoring.constants as mm_constants
|
|
30
|
-
import mlrun.db
|
|
31
32
|
import mlrun.errors
|
|
32
33
|
import mlrun.launcher.factory
|
|
33
34
|
import mlrun.utils.helpers
|