mlrun 1.7.2rc4__py3-none-any.whl → 1.8.0__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.

Files changed (275) hide show
  1. mlrun/__init__.py +26 -22
  2. mlrun/__main__.py +15 -16
  3. mlrun/alerts/alert.py +150 -15
  4. mlrun/api/schemas/__init__.py +1 -9
  5. mlrun/artifacts/__init__.py +2 -3
  6. mlrun/artifacts/base.py +62 -19
  7. mlrun/artifacts/dataset.py +17 -17
  8. mlrun/artifacts/document.py +454 -0
  9. mlrun/artifacts/manager.py +28 -18
  10. mlrun/artifacts/model.py +91 -59
  11. mlrun/artifacts/plots.py +2 -2
  12. mlrun/common/constants.py +8 -0
  13. mlrun/common/formatters/__init__.py +1 -0
  14. mlrun/common/formatters/artifact.py +1 -1
  15. mlrun/common/formatters/feature_set.py +2 -0
  16. mlrun/common/formatters/function.py +1 -0
  17. mlrun/{model_monitoring/db/stores/v3io_kv/__init__.py → common/formatters/model_endpoint.py} +17 -0
  18. mlrun/common/formatters/pipeline.py +1 -2
  19. mlrun/common/formatters/project.py +9 -0
  20. mlrun/common/model_monitoring/__init__.py +0 -5
  21. mlrun/common/model_monitoring/helpers.py +12 -62
  22. mlrun/common/runtimes/constants.py +25 -4
  23. mlrun/common/schemas/__init__.py +9 -5
  24. mlrun/common/schemas/alert.py +114 -19
  25. mlrun/common/schemas/api_gateway.py +3 -3
  26. mlrun/common/schemas/artifact.py +22 -9
  27. mlrun/common/schemas/auth.py +8 -4
  28. mlrun/common/schemas/background_task.py +7 -7
  29. mlrun/common/schemas/client_spec.py +4 -4
  30. mlrun/common/schemas/clusterization_spec.py +2 -2
  31. mlrun/common/schemas/common.py +53 -3
  32. mlrun/common/schemas/constants.py +15 -0
  33. mlrun/common/schemas/datastore_profile.py +1 -1
  34. mlrun/common/schemas/feature_store.py +9 -9
  35. mlrun/common/schemas/frontend_spec.py +4 -4
  36. mlrun/common/schemas/function.py +10 -10
  37. mlrun/common/schemas/hub.py +1 -1
  38. mlrun/common/schemas/k8s.py +3 -3
  39. mlrun/common/schemas/memory_reports.py +3 -3
  40. mlrun/common/schemas/model_monitoring/__init__.py +4 -8
  41. mlrun/common/schemas/model_monitoring/constants.py +127 -46
  42. mlrun/common/schemas/model_monitoring/grafana.py +18 -12
  43. mlrun/common/schemas/model_monitoring/model_endpoints.py +154 -160
  44. mlrun/common/schemas/notification.py +24 -3
  45. mlrun/common/schemas/object.py +1 -1
  46. mlrun/common/schemas/pagination.py +4 -4
  47. mlrun/common/schemas/partition.py +142 -0
  48. mlrun/common/schemas/pipeline.py +3 -3
  49. mlrun/common/schemas/project.py +26 -18
  50. mlrun/common/schemas/runs.py +3 -3
  51. mlrun/common/schemas/runtime_resource.py +5 -5
  52. mlrun/common/schemas/schedule.py +1 -1
  53. mlrun/common/schemas/secret.py +1 -1
  54. mlrun/{model_monitoring/db/stores/sqldb/__init__.py → common/schemas/serving.py} +10 -1
  55. mlrun/common/schemas/tag.py +3 -3
  56. mlrun/common/schemas/workflow.py +6 -5
  57. mlrun/common/types.py +1 -0
  58. mlrun/config.py +157 -89
  59. mlrun/data_types/__init__.py +5 -3
  60. mlrun/data_types/infer.py +13 -3
  61. mlrun/data_types/spark.py +2 -1
  62. mlrun/datastore/__init__.py +59 -18
  63. mlrun/datastore/alibaba_oss.py +4 -1
  64. mlrun/datastore/azure_blob.py +4 -1
  65. mlrun/datastore/base.py +19 -24
  66. mlrun/datastore/datastore.py +10 -4
  67. mlrun/datastore/datastore_profile.py +178 -45
  68. mlrun/datastore/dbfs_store.py +4 -1
  69. mlrun/datastore/filestore.py +4 -1
  70. mlrun/datastore/google_cloud_storage.py +4 -1
  71. mlrun/datastore/hdfs.py +4 -1
  72. mlrun/datastore/inmem.py +4 -1
  73. mlrun/datastore/redis.py +4 -1
  74. mlrun/datastore/s3.py +14 -3
  75. mlrun/datastore/sources.py +89 -92
  76. mlrun/datastore/store_resources.py +7 -4
  77. mlrun/datastore/storeytargets.py +51 -16
  78. mlrun/datastore/targets.py +38 -31
  79. mlrun/datastore/utils.py +87 -4
  80. mlrun/datastore/v3io.py +4 -1
  81. mlrun/datastore/vectorstore.py +291 -0
  82. mlrun/datastore/wasbfs/fs.py +13 -12
  83. mlrun/db/base.py +286 -100
  84. mlrun/db/httpdb.py +1562 -490
  85. mlrun/db/nopdb.py +250 -83
  86. mlrun/errors.py +6 -2
  87. mlrun/execution.py +194 -50
  88. mlrun/feature_store/__init__.py +2 -10
  89. mlrun/feature_store/api.py +20 -458
  90. mlrun/feature_store/common.py +9 -9
  91. mlrun/feature_store/feature_set.py +20 -18
  92. mlrun/feature_store/feature_vector.py +105 -479
  93. mlrun/feature_store/feature_vector_utils.py +466 -0
  94. mlrun/feature_store/retrieval/base.py +15 -11
  95. mlrun/feature_store/retrieval/job.py +2 -1
  96. mlrun/feature_store/retrieval/storey_merger.py +1 -1
  97. mlrun/feature_store/steps.py +3 -3
  98. mlrun/features.py +30 -13
  99. mlrun/frameworks/__init__.py +1 -2
  100. mlrun/frameworks/_common/__init__.py +1 -2
  101. mlrun/frameworks/_common/artifacts_library.py +2 -2
  102. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  103. mlrun/frameworks/_common/model_handler.py +31 -31
  104. mlrun/frameworks/_common/producer.py +3 -1
  105. mlrun/frameworks/_dl_common/__init__.py +1 -2
  106. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  107. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  108. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  109. mlrun/frameworks/_ml_common/__init__.py +1 -2
  110. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  111. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  112. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  113. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  114. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  115. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  116. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  117. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  118. mlrun/frameworks/huggingface/__init__.py +1 -2
  119. mlrun/frameworks/huggingface/model_server.py +9 -9
  120. mlrun/frameworks/lgbm/__init__.py +47 -44
  121. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  122. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  123. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  124. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  125. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  126. mlrun/frameworks/lgbm/model_handler.py +15 -11
  127. mlrun/frameworks/lgbm/model_server.py +11 -7
  128. mlrun/frameworks/lgbm/utils.py +2 -2
  129. mlrun/frameworks/onnx/__init__.py +1 -2
  130. mlrun/frameworks/onnx/dataset.py +3 -3
  131. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  132. mlrun/frameworks/onnx/model_handler.py +7 -5
  133. mlrun/frameworks/onnx/model_server.py +8 -6
  134. mlrun/frameworks/parallel_coordinates.py +11 -11
  135. mlrun/frameworks/pytorch/__init__.py +22 -23
  136. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  137. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  138. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  139. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  140. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  141. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  142. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  143. mlrun/frameworks/pytorch/model_handler.py +21 -17
  144. mlrun/frameworks/pytorch/model_server.py +13 -9
  145. mlrun/frameworks/sklearn/__init__.py +19 -18
  146. mlrun/frameworks/sklearn/estimator.py +2 -2
  147. mlrun/frameworks/sklearn/metric.py +3 -3
  148. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  149. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  150. mlrun/frameworks/sklearn/model_handler.py +4 -3
  151. mlrun/frameworks/tf_keras/__init__.py +11 -12
  152. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  153. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  154. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  155. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  156. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  157. mlrun/frameworks/tf_keras/model_server.py +12 -8
  158. mlrun/frameworks/xgboost/__init__.py +19 -18
  159. mlrun/frameworks/xgboost/model_handler.py +13 -9
  160. mlrun/k8s_utils.py +2 -5
  161. mlrun/launcher/base.py +3 -4
  162. mlrun/launcher/client.py +2 -2
  163. mlrun/launcher/local.py +6 -2
  164. mlrun/launcher/remote.py +1 -1
  165. mlrun/lists.py +8 -4
  166. mlrun/model.py +132 -46
  167. mlrun/model_monitoring/__init__.py +3 -5
  168. mlrun/model_monitoring/api.py +113 -98
  169. mlrun/model_monitoring/applications/__init__.py +0 -5
  170. mlrun/model_monitoring/applications/_application_steps.py +81 -50
  171. mlrun/model_monitoring/applications/base.py +467 -14
  172. mlrun/model_monitoring/applications/context.py +212 -134
  173. mlrun/model_monitoring/{db/stores/base → applications/evidently}/__init__.py +6 -2
  174. mlrun/model_monitoring/applications/evidently/base.py +146 -0
  175. mlrun/model_monitoring/applications/histogram_data_drift.py +89 -56
  176. mlrun/model_monitoring/applications/results.py +67 -15
  177. mlrun/model_monitoring/controller.py +701 -315
  178. mlrun/model_monitoring/db/__init__.py +0 -2
  179. mlrun/model_monitoring/db/_schedules.py +242 -0
  180. mlrun/model_monitoring/db/_stats.py +189 -0
  181. mlrun/model_monitoring/db/tsdb/__init__.py +33 -22
  182. mlrun/model_monitoring/db/tsdb/base.py +243 -49
  183. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +76 -36
  184. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  185. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connection.py +213 -0
  186. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +534 -88
  187. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  188. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +436 -106
  189. mlrun/model_monitoring/helpers.py +356 -114
  190. mlrun/model_monitoring/stream_processing.py +190 -345
  191. mlrun/model_monitoring/tracking_policy.py +11 -4
  192. mlrun/model_monitoring/writer.py +49 -90
  193. mlrun/package/__init__.py +3 -6
  194. mlrun/package/context_handler.py +2 -2
  195. mlrun/package/packager.py +12 -9
  196. mlrun/package/packagers/__init__.py +0 -2
  197. mlrun/package/packagers/default_packager.py +14 -11
  198. mlrun/package/packagers/numpy_packagers.py +16 -7
  199. mlrun/package/packagers/pandas_packagers.py +18 -18
  200. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  201. mlrun/package/packagers_manager.py +35 -32
  202. mlrun/package/utils/__init__.py +0 -3
  203. mlrun/package/utils/_pickler.py +6 -6
  204. mlrun/platforms/__init__.py +47 -16
  205. mlrun/platforms/iguazio.py +4 -1
  206. mlrun/projects/operations.py +30 -30
  207. mlrun/projects/pipelines.py +116 -47
  208. mlrun/projects/project.py +1292 -329
  209. mlrun/render.py +5 -9
  210. mlrun/run.py +57 -14
  211. mlrun/runtimes/__init__.py +1 -3
  212. mlrun/runtimes/base.py +30 -22
  213. mlrun/runtimes/daskjob.py +9 -9
  214. mlrun/runtimes/databricks_job/databricks_runtime.py +6 -5
  215. mlrun/runtimes/function_reference.py +5 -2
  216. mlrun/runtimes/generators.py +3 -2
  217. mlrun/runtimes/kubejob.py +6 -7
  218. mlrun/runtimes/mounts.py +574 -0
  219. mlrun/runtimes/mpijob/__init__.py +0 -2
  220. mlrun/runtimes/mpijob/abstract.py +7 -6
  221. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  222. mlrun/runtimes/nuclio/application/application.py +11 -13
  223. mlrun/runtimes/nuclio/application/reverse_proxy.go +66 -64
  224. mlrun/runtimes/nuclio/function.py +127 -70
  225. mlrun/runtimes/nuclio/serving.py +105 -37
  226. mlrun/runtimes/pod.py +159 -54
  227. mlrun/runtimes/remotesparkjob.py +3 -2
  228. mlrun/runtimes/sparkjob/__init__.py +0 -2
  229. mlrun/runtimes/sparkjob/spark3job.py +22 -12
  230. mlrun/runtimes/utils.py +7 -6
  231. mlrun/secrets.py +2 -2
  232. mlrun/serving/__init__.py +8 -0
  233. mlrun/serving/merger.py +7 -5
  234. mlrun/serving/remote.py +35 -22
  235. mlrun/serving/routers.py +186 -240
  236. mlrun/serving/server.py +41 -10
  237. mlrun/serving/states.py +432 -118
  238. mlrun/serving/utils.py +13 -2
  239. mlrun/serving/v1_serving.py +3 -2
  240. mlrun/serving/v2_serving.py +161 -203
  241. mlrun/track/__init__.py +1 -1
  242. mlrun/track/tracker.py +2 -2
  243. mlrun/track/trackers/mlflow_tracker.py +6 -5
  244. mlrun/utils/async_http.py +35 -22
  245. mlrun/utils/clones.py +7 -4
  246. mlrun/utils/helpers.py +511 -58
  247. mlrun/utils/logger.py +119 -13
  248. mlrun/utils/notifications/notification/__init__.py +22 -19
  249. mlrun/utils/notifications/notification/base.py +39 -15
  250. mlrun/utils/notifications/notification/console.py +6 -6
  251. mlrun/utils/notifications/notification/git.py +11 -11
  252. mlrun/utils/notifications/notification/ipython.py +10 -9
  253. mlrun/utils/notifications/notification/mail.py +176 -0
  254. mlrun/utils/notifications/notification/slack.py +16 -8
  255. mlrun/utils/notifications/notification/webhook.py +24 -8
  256. mlrun/utils/notifications/notification_pusher.py +191 -200
  257. mlrun/utils/regex.py +12 -2
  258. mlrun/utils/version/version.json +2 -2
  259. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/METADATA +69 -54
  260. mlrun-1.8.0.dist-info/RECORD +351 -0
  261. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/WHEEL +1 -1
  262. mlrun/model_monitoring/applications/evidently_base.py +0 -137
  263. mlrun/model_monitoring/db/stores/__init__.py +0 -136
  264. mlrun/model_monitoring/db/stores/base/store.py +0 -213
  265. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
  266. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
  267. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
  268. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
  269. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
  270. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
  271. mlrun/model_monitoring/model_endpoint.py +0 -118
  272. mlrun-1.7.2rc4.dist-info/RECORD +0 -351
  273. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/entry_points.txt +0 -0
  274. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info/licenses}/LICENSE +0 -0
  275. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/top_level.txt +0 -0
mlrun/__init__.py CHANGED
@@ -12,8 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
16
-
17
15
  __all__ = [
18
16
  "get_version",
19
17
  "set_environment",
@@ -29,9 +27,9 @@ __all__ = [
29
27
  ]
30
28
 
31
29
  from os import environ, path
30
+ from typing import Optional
32
31
 
33
32
  import dotenv
34
- import mlrun_pipelines
35
33
 
36
34
  from .config import config as mlconf
37
35
  from .datastore import DataItem, store_manager
@@ -41,6 +39,7 @@ from .execution import MLClientCtx
41
39
  from .model import RunObject, RunTemplate, new_task
42
40
  from .package import ArtifactType, DefaultPackager, Packager, handler
43
41
  from .projects import (
42
+ MlrunProject,
44
43
  ProjectMetadata,
45
44
  build_function,
46
45
  deploy_function,
@@ -61,18 +60,19 @@ from .run import (
61
60
  get_pipeline,
62
61
  import_function,
63
62
  new_function,
63
+ retry_pipeline,
64
64
  wait_for_pipeline_completion,
65
65
  )
66
- from .runtimes import new_model_server
66
+ from .runtimes import mounts, new_model_server
67
67
  from .secrets import get_secret_or_env
68
68
  from .utils.version import Version
69
69
 
70
70
  __version__ = Version().get()["version"]
71
71
 
72
- VolumeMount = mlrun_pipelines.common.mounts.VolumeMount
73
- mount_v3io = mlrun_pipelines.mounts.mount_v3io
74
- v3io_cred = mlrun_pipelines.mounts.v3io_cred
75
- auto_mount = mlrun_pipelines.mounts.auto_mount
72
+ VolumeMount = mounts.VolumeMount
73
+ mount_v3io = mounts.mount_v3io
74
+ v3io_cred = mounts.v3io_cred
75
+ auto_mount = mounts.auto_mount
76
76
 
77
77
 
78
78
  def get_version():
@@ -88,12 +88,12 @@ if "IGZ_NAMESPACE_DOMAIN" in environ:
88
88
 
89
89
 
90
90
  def set_environment(
91
- api_path: str = None,
91
+ api_path: Optional[str] = None,
92
92
  artifact_path: str = "",
93
- access_key: str = None,
94
- username: str = None,
95
- env_file: str = None,
96
- mock_functions: str = None,
93
+ access_key: Optional[str] = None,
94
+ username: Optional[str] = None,
95
+ env_file: Optional[str] = None,
96
+ mock_functions: Optional[str] = None,
97
97
  ):
98
98
  """set and test default config for: api path, artifact_path and project
99
99
 
@@ -136,15 +136,16 @@ def set_environment(
136
136
  if not mlconf.dbpath:
137
137
  raise ValueError("DB/API path was not detected, please specify its address")
138
138
 
139
- if mock_functions is not None:
140
- mock_functions = "1" if mock_functions is True else mock_functions
141
- mlconf.force_run_local = mock_functions
142
- mlconf.mock_nuclio_deployment = mock_functions
143
-
144
139
  # check connectivity and load remote defaults
145
140
  get_run_db()
146
141
  if api_path:
147
142
  environ["MLRUN_DBPATH"] = mlconf.dbpath
143
+ mlconf.reload()
144
+
145
+ if mock_functions is not None:
146
+ mock_functions = "1" if mock_functions is True else mock_functions
147
+ mlconf.force_run_local = mock_functions
148
+ mlconf.mock_nuclio_deployment = mock_functions
148
149
 
149
150
  if not mlconf.artifact_path and not artifact_path:
150
151
  raise ValueError(
@@ -159,13 +160,14 @@ def set_environment(
159
160
  "artifact_path must refer to an absolute path" " or a valid url"
160
161
  )
161
162
  mlconf.artifact_path = artifact_path
163
+
162
164
  return mlconf.default_project, mlconf.artifact_path
163
165
 
164
166
 
165
- def get_current_project(silent=False):
167
+ def get_current_project(silent: bool = False) -> Optional[MlrunProject]:
166
168
  if not pipeline_context.project and not silent:
167
169
  raise MLRunInvalidArgumentError(
168
- "current project is not initialized, use new, get or load project methods first"
170
+ "No current project is initialized. Use new, get or load project functions first."
169
171
  )
170
172
  return pipeline_context.project
171
173
 
@@ -182,7 +184,7 @@ def get_sample_path(subpath=""):
182
184
  return samples_path
183
185
 
184
186
 
185
- def set_env_from_file(env_file: str, return_dict: bool = False):
187
+ def set_env_from_file(env_file: str, return_dict: bool = False) -> Optional[dict]:
186
188
  """Read and set and/or return environment variables from a file
187
189
  the env file should have lines in the form KEY=VALUE, comment line start with "#"
188
190
 
@@ -211,7 +213,9 @@ def set_env_from_file(env_file: str, return_dict: bool = False):
211
213
  env_vars = dotenv.dotenv_values(env_file)
212
214
  if None in env_vars.values():
213
215
  raise MLRunInvalidArgumentError("env file lines must be in the form key=value")
216
+
214
217
  for key, value in env_vars.items():
215
- environ[key] = value # Load to local environ
218
+ environ[key] = value
219
+
216
220
  mlconf.reload() # reload mlrun configuration
217
221
  return env_vars if return_dict else None
mlrun/__main__.py CHANGED
@@ -17,9 +17,8 @@ import json
17
17
  import pathlib
18
18
  import socket
19
19
  import traceback
20
- import warnings
21
20
  from ast import literal_eval
22
- from base64 import b64decode, b64encode
21
+ from base64 import b64decode
23
22
  from os import environ, path, remove
24
23
  from pprint import pprint
25
24
 
@@ -27,13 +26,14 @@ import click
27
26
  import dotenv
28
27
  import pandas as pd
29
28
  import yaml
30
- from mlrun_pipelines.mounts import auto_mount as auto_mount_modifier
31
29
  from tabulate import tabulate
32
30
 
33
31
  import mlrun
34
32
  import mlrun.common.constants as mlrun_constants
35
33
  import mlrun.common.schemas
34
+ import mlrun.utils.helpers
36
35
  from mlrun.common.helpers import parse_versioned_object_uri
36
+ from mlrun.runtimes.mounts import auto_mount as auto_mount_modifier
37
37
 
38
38
  from .config import config as mlconf
39
39
  from .db import get_run_db
@@ -297,13 +297,14 @@ def run(
297
297
  if url_file and path.isfile(url_file):
298
298
  with open(url_file) as fp:
299
299
  body = fp.read()
300
- based = b64encode(body.encode("utf-8")).decode("utf-8")
300
+ based = mlrun.utils.helpers.encode_user_code(body)
301
301
  logger.info(f"packing code at {url_file}")
302
302
  update_in(runtime, "spec.build.functionSourceCode", based)
303
303
  url = f"main{pathlib.Path(url_file).suffix} {url_args}"
304
304
  update_in(runtime, "spec.build.code_origin", url_file)
305
305
  elif runtime:
306
306
  runtime = py_eval(runtime)
307
+ runtime = mlrun.utils.helpers.as_dict(runtime)
307
308
  if not isinstance(runtime, dict):
308
309
  print(f"Runtime parameter must be a dict, not {type(runtime)}")
309
310
  exit(1)
@@ -515,6 +516,7 @@ def build(
515
516
 
516
517
  if runtime:
517
518
  runtime = py_eval(runtime)
519
+ runtime = mlrun.utils.helpers.as_dict(runtime)
518
520
  if not isinstance(runtime, dict):
519
521
  print(f"Runtime parameter must be a dict, not {type(runtime)}")
520
522
  exit(1)
@@ -554,7 +556,7 @@ def build(
554
556
  exit(1)
555
557
  with open(source) as fp:
556
558
  body = fp.read()
557
- based = b64encode(body.encode("utf-8")).decode("utf-8")
559
+ based = mlrun.utils.helpers.encode_user_code(body)
558
560
  logger.info(f"Packing code at {source}")
559
561
  b.functionSourceCode = based
560
562
  func.spec.command = ""
@@ -662,6 +664,8 @@ def deploy(
662
664
  runtime = py_eval(spec)
663
665
  else:
664
666
  runtime = {}
667
+
668
+ runtime = mlrun.utils.helpers.as_dict(runtime)
665
669
  if not isinstance(runtime, dict):
666
670
  print(f"Runtime parameter must be a dict, not {type(runtime)}")
667
671
  exit(1)
@@ -767,10 +771,11 @@ def get(kind, name, selector, namespace, uid, project, tag, db, extra_args):
767
771
 
768
772
  runs = run_db.list_runs(uid=uid, project=project, labels=selector)
769
773
  df = runs.to_df()[
770
- ["name", "uid", "iter", "start", "state", "parameters", "results"]
774
+ ["name", "uid", "iter", "start", "end", "state", "parameters", "results"]
771
775
  ]
772
776
  # df['uid'] = df['uid'].apply(lambda x: f'..{x[-6:]}')
773
- df["start"] = df["start"].apply(time_str)
777
+ for time_column in ["start", "end"]:
778
+ df[time_column] = df[time_column].apply(time_str)
774
779
  df["parameters"] = df["parameters"].apply(dict_to_str)
775
780
  df["results"] = df["results"].apply(dict_to_str)
776
781
  print(tabulate(df, headers="keys"))
@@ -858,14 +863,8 @@ def version():
858
863
  )
859
864
  @click.option("--offset", type=int, default=0, help="byte offset")
860
865
  @click.option("--db", help="api and db service path/url")
861
- @click.option("--watch", "-w", is_flag=True, help="Deprecated. not in use")
862
- def logs(uid, project, offset, db, watch):
866
+ def logs(uid, project, offset, db):
863
867
  """Get or watch task logs"""
864
- if watch:
865
- warnings.warn(
866
- "'--watch' is deprecated in 1.6.0, and will be removed in 1.8.0, "
867
- # TODO: Remove in 1.8.0
868
- )
869
868
  mldb = get_run_db(db or mlconf.dbpath)
870
869
  if mldb.kind == "http":
871
870
  state, _ = mldb.watch_log(uid, project, watch=False, offset=offset)
@@ -1248,10 +1247,10 @@ def show_or_set_config(
1248
1247
  }
1249
1248
  for key, value in env_dict.items():
1250
1249
  if value:
1251
- dotenv.set_key(filename, key, value, quote_mode="")
1250
+ dotenv.set_key(filename, key, value, quote_mode="always")
1252
1251
  if env_vars:
1253
1252
  for key, value in list2dict(env_vars).items():
1254
- dotenv.set_key(filename, key, value, quote_mode="")
1253
+ dotenv.set_key(filename, key, value, quote_mode="always")
1255
1254
  if env_file:
1256
1255
  # if its not the default file print the usage details
1257
1256
  print(
mlrun/alerts/alert.py CHANGED
@@ -11,8 +11,8 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
15
- from typing import Union
14
+ from datetime import datetime
15
+ from typing import Optional, Union
16
16
 
17
17
  import mlrun
18
18
  import mlrun.common.schemas.alert as alert_objects
@@ -30,6 +30,7 @@ class AlertConfig(ModelObj):
30
30
  "state",
31
31
  "count",
32
32
  "created",
33
+ "updated",
33
34
  ]
34
35
  _fields_to_serialize = ModelObj._fields_to_serialize + [
35
36
  "entities",
@@ -40,21 +41,23 @@ class AlertConfig(ModelObj):
40
41
 
41
42
  def __init__(
42
43
  self,
43
- project: str = None,
44
- name: str = None,
44
+ project: Optional[str] = None,
45
+ name: Optional[str] = None,
45
46
  template: Union[alert_objects.AlertTemplate, str] = None,
46
- description: str = None,
47
- summary: str = None,
47
+ description: Optional[str] = None,
48
+ summary: Optional[str] = None,
48
49
  severity: alert_objects.AlertSeverity = None,
49
50
  trigger: alert_objects.AlertTrigger = None,
50
51
  criteria: alert_objects.AlertCriteria = None,
51
52
  reset_policy: alert_objects.ResetPolicy = None,
52
- notifications: list[alert_objects.AlertNotification] = None,
53
+ notifications: Optional[list[alert_objects.AlertNotification]] = None,
53
54
  entities: alert_objects.EventEntities = None,
54
- id: int = None,
55
+ id: Optional[int] = None,
55
56
  state: alert_objects.AlertActiveState = None,
56
- created: str = None,
57
- count: int = None,
57
+ created: Optional[str] = None,
58
+ count: Optional[int] = None,
59
+ updated: Optional[str] = None,
60
+ **kwargs,
58
61
  ):
59
62
  """Alert config object
60
63
 
@@ -109,7 +112,7 @@ class AlertConfig(ModelObj):
109
112
  complex trigger which is based on a prometheus alert
110
113
  :param criteria: When the alert will be triggered based on the specified number of events within the
111
114
  defined time period.
112
- :param reset_policy: When to clear the alert. May be "manual" for manual reset of the alert, or
115
+ :param reset_policy: When to clear the alert. Either "manual" for manual reset of the alert, or
113
116
  "auto" if the criteria contains a time period
114
117
  :param notifications: List of notifications to invoke once the alert is triggered
115
118
  :param entities: Entities that the event relates to. The entity object will contain fields that
@@ -118,6 +121,7 @@ class AlertConfig(ModelObj):
118
121
  :param state: State of the alert, may be active/inactive (user should not supply it)
119
122
  :param created: When the alert is created (user should not supply it)
120
123
  :param count: Internal counter of the alert (user should not supply it)
124
+ :param updated: The last update time of the alert (user should not supply it)
121
125
  """
122
126
  self.project = project
123
127
  self.name = name
@@ -131,18 +135,45 @@ class AlertConfig(ModelObj):
131
135
  self.entities = entities
132
136
  self.id = id
133
137
  self.state = state
134
- self.created = created
138
+ self._created = created
135
139
  self.count = count
140
+ self._updated = updated
136
141
 
137
142
  if template:
138
143
  self._apply_template(template)
139
144
 
145
+ @property
146
+ def created(self) -> datetime:
147
+ """
148
+ Get the `created` field as a datetime object.
149
+ """
150
+ if isinstance(self._created, str):
151
+ return datetime.fromisoformat(self._created)
152
+ return self._created
153
+
154
+ @created.setter
155
+ def created(self, created):
156
+ self._created = created
157
+
158
+ @property
159
+ def updated(self) -> datetime:
160
+ """
161
+ Get the `updated` field as a datetime object.
162
+ """
163
+ if isinstance(self._updated, str):
164
+ return datetime.fromisoformat(self._updated)
165
+ return self._updated
166
+
167
+ @updated.setter
168
+ def updated(self, updated):
169
+ self._updated = updated
170
+
140
171
  def validate_required_fields(self):
141
172
  if not self.name:
142
173
  raise mlrun.errors.MLRunInvalidArgumentError("Alert name must be provided")
143
174
 
144
175
  def _serialize_field(
145
- self, struct: dict, field_name: str = None, strip: bool = False
176
+ self, struct: dict, field_name: Optional[str] = None, strip: bool = False
146
177
  ):
147
178
  if field_name == "entities":
148
179
  if self.entities:
@@ -179,7 +210,12 @@ class AlertConfig(ModelObj):
179
210
  return None
180
211
  return super()._serialize_field(struct, field_name, strip)
181
212
 
182
- def to_dict(self, fields: list = None, exclude: list = None, strip: bool = False):
213
+ def to_dict(
214
+ self,
215
+ fields: Optional[list] = None,
216
+ exclude: Optional[list] = None,
217
+ strip: bool = False,
218
+ ):
183
219
  if self.entities is None:
184
220
  raise mlrun.errors.MLRunBadRequestError("Alert entity field is missing")
185
221
  if not self.notifications:
@@ -189,7 +225,9 @@ class AlertConfig(ModelObj):
189
225
  return super().to_dict(self._dict_fields)
190
226
 
191
227
  @classmethod
192
- def from_dict(cls, struct=None, fields=None, deprecated_fields: dict = None):
228
+ def from_dict(
229
+ cls, struct=None, fields=None, deprecated_fields: Optional[dict] = None
230
+ ):
193
231
  new_obj = super().from_dict(struct, fields=fields)
194
232
 
195
233
  entity_data = struct.get("entities")
@@ -246,3 +284,100 @@ class AlertConfig(ModelObj):
246
284
  self.criteria = self.criteria or template.criteria
247
285
  self.trigger = self.trigger or template.trigger
248
286
  self.reset_policy = self.reset_policy or template.reset_policy
287
+
288
+ def list_activations(
289
+ self,
290
+ since: Optional[datetime] = None,
291
+ until: Optional[datetime] = None,
292
+ from_last_update: bool = False,
293
+ ) -> list[mlrun.common.schemas.alert.AlertActivation]:
294
+ """
295
+ Retrieve a list of all alert activations.
296
+
297
+ :param since: Filters for alert activations occurring after this timestamp.
298
+ :param until: Filters for alert activations occurring before this timestamp.
299
+ :param from_last_update: If set to True, retrieves alert activations since the alert's last update time.
300
+ if both since and from_last_update=True are provided, from_last_update takes precedence
301
+ and the since value will be overridden by the alert's last update timestamp.
302
+
303
+ :returns: A list of alert activations matching the provided filters.
304
+ """
305
+ db = mlrun.get_run_db()
306
+ if from_last_update and self._updated:
307
+ since = self.updated
308
+
309
+ return db.list_alert_activations(
310
+ project=self.project,
311
+ name=self.name,
312
+ since=since,
313
+ until=until,
314
+ )
315
+
316
+ def paginated_list_activations(
317
+ self,
318
+ *args,
319
+ page: Optional[int] = None,
320
+ page_size: Optional[int] = None,
321
+ page_token: Optional[str] = None,
322
+ from_last_update: bool = False,
323
+ **kwargs,
324
+ ) -> tuple[mlrun.common.schemas.alert.AlertActivation, Optional[str]]:
325
+ """
326
+ List alerts activations with support for pagination and various filtering options.
327
+
328
+ This method retrieves a paginated list of alert activations based on the specified filter parameters.
329
+ Pagination is controlled using the `page`, `page_size`, and `page_token` parameters. The method
330
+ will return a list of alert activations that match the filtering criteria provided.
331
+
332
+ For detailed information about the parameters, refer to the list_activations method:
333
+ See :py:func:`~list_activations` for more details.
334
+
335
+ Examples::
336
+
337
+ # Fetch first page of alert activations with page size of 5
338
+ alert_activations, token = alert_config.paginated_list_activations(page_size=5)
339
+ # Fetch next page using the pagination token from the previous response
340
+ alert_activations, token = alert_config.paginated_list_activations(
341
+ page_token=token
342
+ )
343
+ # Fetch alert activations for a specific page (e.g., page 3)
344
+ alert_activations, token = alert_config.paginated_list_activations(
345
+ page=3, page_size=5
346
+ )
347
+
348
+ # Automatically iterate over all pages without explicitly specifying the page number
349
+ alert_activations = []
350
+ token = None
351
+ while True:
352
+ page_alert_activations, token = alert_config.paginated_list_activations(
353
+ page_token=token, page_size=5
354
+ )
355
+ alert_activations.extend(page_alert_activations)
356
+
357
+ # If token is None and page_alert_activations is empty, we've reached the end (no more activations).
358
+ # If token is None and page_alert_activations is not empty, we've fetched the last page of activations.
359
+ if not token:
360
+ break
361
+ print(f"Total alert activations retrieved: {len(alert_activations)}")
362
+
363
+ :param page: The page number to retrieve. If not provided, the next page will be retrieved.
364
+ :param page_size: The number of items per page to retrieve. Up to `page_size` responses are expected.
365
+ :param page_token: A pagination token used to retrieve the next page of results. Should not be provided
366
+ for the first request.
367
+ :param from_last_update: If set to True, retrieves alert activations since the alert's last update time.
368
+
369
+ :returns: A tuple containing the list of alert activations and an optional `page_token` for pagination.
370
+ """
371
+ if from_last_update and self._updated:
372
+ kwargs["since"] = self.updated
373
+
374
+ db = mlrun.get_run_db()
375
+ return db.paginated_list_alert_activations(
376
+ *args,
377
+ project=self.project,
378
+ name=self.name,
379
+ page=page,
380
+ page_size=page_size,
381
+ page_token=page_token,
382
+ **kwargs,
383
+ )
@@ -193,9 +193,7 @@ FeatureValues = DeprecationHelper(mlrun.common.schemas.FeatureValues)
193
193
  GrafanaColumn = DeprecationHelper(
194
194
  mlrun.common.schemas.model_monitoring.grafana.GrafanaColumn
195
195
  )
196
- GrafanaDataPoint = DeprecationHelper(
197
- mlrun.common.schemas.model_monitoring.grafana.GrafanaDataPoint
198
- )
196
+
199
197
  GrafanaNumberColumn = DeprecationHelper(
200
198
  mlrun.common.schemas.model_monitoring.grafana.GrafanaNumberColumn
201
199
  )
@@ -205,17 +203,11 @@ GrafanaStringColumn = DeprecationHelper(
205
203
  GrafanaTable = DeprecationHelper(
206
204
  mlrun.common.schemas.model_monitoring.grafana.GrafanaTable
207
205
  )
208
- GrafanaTimeSeriesTarget = DeprecationHelper(
209
- mlrun.common.schemas.model_monitoring.grafana.GrafanaTimeSeriesTarget
210
- )
211
206
  ModelEndpoint = DeprecationHelper(mlrun.common.schemas.ModelEndpoint)
212
207
  ModelEndpointList = DeprecationHelper(mlrun.common.schemas.ModelEndpointList)
213
208
  ModelEndpointMetadata = DeprecationHelper(mlrun.common.schemas.ModelEndpointMetadata)
214
209
  ModelEndpointSpec = DeprecationHelper(mlrun.common.schemas.ModelEndpointSpec)
215
210
  ModelEndpointStatus = DeprecationHelper(mlrun.common.schemas.ModelEndpointStatus)
216
- ModelMonitoringStoreKinds = DeprecationHelper(
217
- mlrun.common.schemas.ModelMonitoringStoreKinds
218
- )
219
211
  NotificationSeverity = DeprecationHelper(mlrun.common.schemas.NotificationSeverity)
220
212
  NotificationStatus = DeprecationHelper(mlrun.common.schemas.NotificationStatus)
221
213
  ObjectKind = DeprecationHelper(mlrun.common.schemas.ObjectKind)
@@ -12,10 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
16
-
17
15
  # Don't remove this, used by sphinx documentation
18
- __all__ = ["get_model", "update_model"]
16
+ __all__ = ["get_model", "update_model", "DocumentLoaderSpec", "MLRunLoader"]
19
17
 
20
18
  from .base import (
21
19
  Artifact,
@@ -25,6 +23,7 @@ from .base import (
25
23
  get_artifact_meta,
26
24
  )
27
25
  from .dataset import DatasetArtifact, TableArtifact, update_dataset_meta
26
+ from .document import DocumentArtifact, DocumentLoaderSpec, MLRunLoader
28
27
  from .manager import (
29
28
  ArtifactManager,
30
29
  ArtifactProducer,