mlrun 1.7.0rc4__py3-none-any.whl → 1.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mlrun might be problematic. Click here for more details.

Files changed (235) hide show
  1. mlrun/__init__.py +11 -1
  2. mlrun/__main__.py +39 -121
  3. mlrun/{datastore/helpers.py → alerts/__init__.py} +2 -5
  4. mlrun/alerts/alert.py +248 -0
  5. mlrun/api/schemas/__init__.py +4 -3
  6. mlrun/artifacts/__init__.py +8 -3
  7. mlrun/artifacts/base.py +39 -254
  8. mlrun/artifacts/dataset.py +9 -190
  9. mlrun/artifacts/manager.py +73 -46
  10. mlrun/artifacts/model.py +30 -158
  11. mlrun/artifacts/plots.py +23 -380
  12. mlrun/common/constants.py +73 -1
  13. mlrun/common/db/sql_session.py +3 -2
  14. mlrun/common/formatters/__init__.py +21 -0
  15. mlrun/common/formatters/artifact.py +46 -0
  16. mlrun/common/formatters/base.py +113 -0
  17. mlrun/common/formatters/feature_set.py +44 -0
  18. mlrun/common/formatters/function.py +46 -0
  19. mlrun/common/formatters/pipeline.py +53 -0
  20. mlrun/common/formatters/project.py +51 -0
  21. mlrun/common/formatters/run.py +29 -0
  22. mlrun/common/helpers.py +11 -1
  23. mlrun/{runtimes → common/runtimes}/constants.py +32 -4
  24. mlrun/common/schemas/__init__.py +31 -4
  25. mlrun/common/schemas/alert.py +202 -0
  26. mlrun/common/schemas/api_gateway.py +196 -0
  27. mlrun/common/schemas/artifact.py +28 -1
  28. mlrun/common/schemas/auth.py +13 -2
  29. mlrun/common/schemas/client_spec.py +2 -1
  30. mlrun/common/schemas/common.py +7 -4
  31. mlrun/common/schemas/constants.py +3 -0
  32. mlrun/common/schemas/feature_store.py +58 -28
  33. mlrun/common/schemas/frontend_spec.py +8 -0
  34. mlrun/common/schemas/function.py +11 -0
  35. mlrun/common/schemas/hub.py +7 -9
  36. mlrun/common/schemas/model_monitoring/__init__.py +21 -4
  37. mlrun/common/schemas/model_monitoring/constants.py +136 -42
  38. mlrun/common/schemas/model_monitoring/grafana.py +9 -5
  39. mlrun/common/schemas/model_monitoring/model_endpoints.py +89 -41
  40. mlrun/common/schemas/notification.py +69 -12
  41. mlrun/{runtimes/mpijob/v1alpha1.py → common/schemas/pagination.py} +10 -13
  42. mlrun/common/schemas/pipeline.py +7 -0
  43. mlrun/common/schemas/project.py +67 -16
  44. mlrun/common/schemas/runs.py +17 -0
  45. mlrun/common/schemas/schedule.py +1 -1
  46. mlrun/common/schemas/workflow.py +10 -2
  47. mlrun/common/types.py +14 -1
  48. mlrun/config.py +233 -58
  49. mlrun/data_types/data_types.py +11 -1
  50. mlrun/data_types/spark.py +5 -4
  51. mlrun/data_types/to_pandas.py +75 -34
  52. mlrun/datastore/__init__.py +8 -10
  53. mlrun/datastore/alibaba_oss.py +131 -0
  54. mlrun/datastore/azure_blob.py +131 -43
  55. mlrun/datastore/base.py +107 -47
  56. mlrun/datastore/datastore.py +17 -7
  57. mlrun/datastore/datastore_profile.py +91 -7
  58. mlrun/datastore/dbfs_store.py +3 -7
  59. mlrun/datastore/filestore.py +1 -3
  60. mlrun/datastore/google_cloud_storage.py +92 -32
  61. mlrun/datastore/hdfs.py +5 -0
  62. mlrun/datastore/inmem.py +6 -3
  63. mlrun/datastore/redis.py +3 -2
  64. mlrun/datastore/s3.py +30 -12
  65. mlrun/datastore/snowflake_utils.py +45 -0
  66. mlrun/datastore/sources.py +274 -59
  67. mlrun/datastore/spark_utils.py +30 -0
  68. mlrun/datastore/store_resources.py +9 -7
  69. mlrun/datastore/storeytargets.py +151 -0
  70. mlrun/datastore/targets.py +387 -119
  71. mlrun/datastore/utils.py +68 -5
  72. mlrun/datastore/v3io.py +28 -50
  73. mlrun/db/auth_utils.py +152 -0
  74. mlrun/db/base.py +245 -20
  75. mlrun/db/factory.py +1 -4
  76. mlrun/db/httpdb.py +909 -231
  77. mlrun/db/nopdb.py +279 -14
  78. mlrun/errors.py +35 -5
  79. mlrun/execution.py +111 -38
  80. mlrun/feature_store/__init__.py +0 -2
  81. mlrun/feature_store/api.py +46 -53
  82. mlrun/feature_store/common.py +6 -11
  83. mlrun/feature_store/feature_set.py +48 -23
  84. mlrun/feature_store/feature_vector.py +13 -2
  85. mlrun/feature_store/ingestion.py +7 -6
  86. mlrun/feature_store/retrieval/base.py +9 -4
  87. mlrun/feature_store/retrieval/dask_merger.py +2 -0
  88. mlrun/feature_store/retrieval/job.py +13 -4
  89. mlrun/feature_store/retrieval/local_merger.py +2 -0
  90. mlrun/feature_store/retrieval/spark_merger.py +24 -32
  91. mlrun/feature_store/steps.py +38 -19
  92. mlrun/features.py +6 -14
  93. mlrun/frameworks/_common/plan.py +3 -3
  94. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +7 -12
  95. mlrun/frameworks/_ml_common/plan.py +1 -1
  96. mlrun/frameworks/auto_mlrun/auto_mlrun.py +2 -2
  97. mlrun/frameworks/lgbm/__init__.py +1 -1
  98. mlrun/frameworks/lgbm/callbacks/callback.py +2 -4
  99. mlrun/frameworks/lgbm/model_handler.py +1 -1
  100. mlrun/frameworks/parallel_coordinates.py +4 -4
  101. mlrun/frameworks/pytorch/__init__.py +2 -2
  102. mlrun/frameworks/sklearn/__init__.py +1 -1
  103. mlrun/frameworks/sklearn/mlrun_interface.py +13 -3
  104. mlrun/frameworks/tf_keras/__init__.py +5 -2
  105. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +1 -1
  106. mlrun/frameworks/tf_keras/mlrun_interface.py +2 -2
  107. mlrun/frameworks/xgboost/__init__.py +1 -1
  108. mlrun/k8s_utils.py +57 -12
  109. mlrun/launcher/__init__.py +1 -1
  110. mlrun/launcher/base.py +6 -5
  111. mlrun/launcher/client.py +13 -11
  112. mlrun/launcher/factory.py +1 -1
  113. mlrun/launcher/local.py +15 -5
  114. mlrun/launcher/remote.py +10 -3
  115. mlrun/lists.py +6 -2
  116. mlrun/model.py +297 -48
  117. mlrun/model_monitoring/__init__.py +1 -1
  118. mlrun/model_monitoring/api.py +152 -357
  119. mlrun/model_monitoring/applications/__init__.py +10 -0
  120. mlrun/model_monitoring/applications/_application_steps.py +190 -0
  121. mlrun/model_monitoring/applications/base.py +108 -0
  122. mlrun/model_monitoring/applications/context.py +341 -0
  123. mlrun/model_monitoring/{evidently_application.py → applications/evidently_base.py} +27 -22
  124. mlrun/model_monitoring/applications/histogram_data_drift.py +227 -91
  125. mlrun/model_monitoring/applications/results.py +99 -0
  126. mlrun/model_monitoring/controller.py +130 -303
  127. mlrun/model_monitoring/{stores/models/sqlite.py → db/__init__.py} +5 -10
  128. mlrun/model_monitoring/db/stores/__init__.py +136 -0
  129. mlrun/model_monitoring/db/stores/base/__init__.py +15 -0
  130. mlrun/model_monitoring/db/stores/base/store.py +213 -0
  131. mlrun/model_monitoring/db/stores/sqldb/__init__.py +13 -0
  132. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +71 -0
  133. mlrun/model_monitoring/db/stores/sqldb/models/base.py +190 -0
  134. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +103 -0
  135. mlrun/model_monitoring/{stores/models/mysql.py → db/stores/sqldb/models/sqlite.py} +19 -13
  136. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +659 -0
  137. mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +13 -0
  138. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +726 -0
  139. mlrun/model_monitoring/db/tsdb/__init__.py +105 -0
  140. mlrun/model_monitoring/db/tsdb/base.py +448 -0
  141. mlrun/model_monitoring/db/tsdb/helpers.py +30 -0
  142. mlrun/model_monitoring/db/tsdb/tdengine/__init__.py +15 -0
  143. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +298 -0
  144. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +42 -0
  145. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +522 -0
  146. mlrun/model_monitoring/db/tsdb/v3io/__init__.py +15 -0
  147. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +158 -0
  148. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +849 -0
  149. mlrun/model_monitoring/features_drift_table.py +34 -22
  150. mlrun/model_monitoring/helpers.py +177 -39
  151. mlrun/model_monitoring/model_endpoint.py +3 -2
  152. mlrun/model_monitoring/stream_processing.py +165 -398
  153. mlrun/model_monitoring/tracking_policy.py +7 -1
  154. mlrun/model_monitoring/writer.py +161 -125
  155. mlrun/package/packagers/default_packager.py +2 -2
  156. mlrun/package/packagers_manager.py +1 -0
  157. mlrun/package/utils/_formatter.py +2 -2
  158. mlrun/platforms/__init__.py +11 -10
  159. mlrun/platforms/iguazio.py +67 -228
  160. mlrun/projects/__init__.py +6 -1
  161. mlrun/projects/operations.py +47 -20
  162. mlrun/projects/pipelines.py +396 -249
  163. mlrun/projects/project.py +1176 -406
  164. mlrun/render.py +28 -22
  165. mlrun/run.py +208 -181
  166. mlrun/runtimes/__init__.py +76 -11
  167. mlrun/runtimes/base.py +54 -24
  168. mlrun/runtimes/daskjob.py +9 -2
  169. mlrun/runtimes/databricks_job/databricks_runtime.py +1 -0
  170. mlrun/runtimes/databricks_job/databricks_wrapper.py +1 -1
  171. mlrun/runtimes/funcdoc.py +1 -29
  172. mlrun/runtimes/kubejob.py +34 -128
  173. mlrun/runtimes/local.py +39 -10
  174. mlrun/runtimes/mpijob/__init__.py +0 -20
  175. mlrun/runtimes/mpijob/abstract.py +8 -8
  176. mlrun/runtimes/mpijob/v1.py +1 -1
  177. mlrun/runtimes/nuclio/__init__.py +1 -0
  178. mlrun/runtimes/nuclio/api_gateway.py +769 -0
  179. mlrun/runtimes/nuclio/application/__init__.py +15 -0
  180. mlrun/runtimes/nuclio/application/application.py +758 -0
  181. mlrun/runtimes/nuclio/application/reverse_proxy.go +95 -0
  182. mlrun/runtimes/nuclio/function.py +188 -68
  183. mlrun/runtimes/nuclio/serving.py +57 -60
  184. mlrun/runtimes/pod.py +191 -58
  185. mlrun/runtimes/remotesparkjob.py +11 -8
  186. mlrun/runtimes/sparkjob/spark3job.py +17 -18
  187. mlrun/runtimes/utils.py +40 -73
  188. mlrun/secrets.py +6 -2
  189. mlrun/serving/__init__.py +8 -1
  190. mlrun/serving/remote.py +2 -3
  191. mlrun/serving/routers.py +89 -64
  192. mlrun/serving/server.py +54 -26
  193. mlrun/serving/states.py +187 -56
  194. mlrun/serving/utils.py +19 -11
  195. mlrun/serving/v2_serving.py +136 -63
  196. mlrun/track/tracker.py +2 -1
  197. mlrun/track/trackers/mlflow_tracker.py +5 -0
  198. mlrun/utils/async_http.py +26 -6
  199. mlrun/utils/db.py +18 -0
  200. mlrun/utils/helpers.py +375 -105
  201. mlrun/utils/http.py +2 -2
  202. mlrun/utils/logger.py +75 -9
  203. mlrun/utils/notifications/notification/__init__.py +14 -10
  204. mlrun/utils/notifications/notification/base.py +48 -0
  205. mlrun/utils/notifications/notification/console.py +2 -0
  206. mlrun/utils/notifications/notification/git.py +24 -1
  207. mlrun/utils/notifications/notification/ipython.py +2 -0
  208. mlrun/utils/notifications/notification/slack.py +96 -21
  209. mlrun/utils/notifications/notification/webhook.py +63 -2
  210. mlrun/utils/notifications/notification_pusher.py +146 -16
  211. mlrun/utils/regex.py +9 -0
  212. mlrun/utils/retryer.py +3 -2
  213. mlrun/utils/v3io_clients.py +2 -3
  214. mlrun/utils/version/version.json +2 -2
  215. mlrun-1.7.2.dist-info/METADATA +390 -0
  216. mlrun-1.7.2.dist-info/RECORD +351 -0
  217. {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/WHEEL +1 -1
  218. mlrun/feature_store/retrieval/conversion.py +0 -271
  219. mlrun/kfpops.py +0 -868
  220. mlrun/model_monitoring/application.py +0 -310
  221. mlrun/model_monitoring/batch.py +0 -974
  222. mlrun/model_monitoring/controller_handler.py +0 -37
  223. mlrun/model_monitoring/prometheus.py +0 -216
  224. mlrun/model_monitoring/stores/__init__.py +0 -111
  225. mlrun/model_monitoring/stores/kv_model_endpoint_store.py +0 -574
  226. mlrun/model_monitoring/stores/model_endpoint_store.py +0 -145
  227. mlrun/model_monitoring/stores/models/__init__.py +0 -27
  228. mlrun/model_monitoring/stores/models/base.py +0 -84
  229. mlrun/model_monitoring/stores/sql_model_endpoint_store.py +0 -382
  230. mlrun/platforms/other.py +0 -305
  231. mlrun-1.7.0rc4.dist-info/METADATA +0 -269
  232. mlrun-1.7.0rc4.dist-info/RECORD +0 -321
  233. {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/LICENSE +0 -0
  234. {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/entry_points.txt +0 -0
  235. {mlrun-1.7.0rc4.dist-info → mlrun-1.7.2.dist-info}/top_level.txt +0 -0
@@ -1,37 +0,0 @@
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
- import nuclio
15
-
16
- import mlrun
17
- from mlrun.model_monitoring.controller import MonitoringApplicationController
18
-
19
-
20
- def handler(context: nuclio.Context, event: nuclio.Event) -> None:
21
- """
22
- Run model monitoring application processor
23
-
24
- :param context: the Nuclio context
25
- :param event: trigger event
26
- """
27
- context.user_data.monitor_app_controller.run(event)
28
-
29
-
30
- def init_context(context):
31
- mlrun_context = mlrun.get_or_create_ctx("model_monitoring_controller")
32
- mlrun_context.logger.info("Initialize monitoring app controller")
33
- monitor_app_controller = MonitoringApplicationController(
34
- mlrun_context=mlrun_context,
35
- project=mlrun_context.project,
36
- )
37
- setattr(context.user_data, "monitor_app_controller", monitor_app_controller)
@@ -1,216 +0,0 @@
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
-
16
- import prometheus_client
17
-
18
- from mlrun.common.schemas.model_monitoring import EventFieldType, PrometheusMetric
19
-
20
- # Memory path for Prometheus registry file
21
- _registry_path = "/tmp/prom-reg.txt"
22
-
23
- # Initializing Promethues metric collector registry
24
- _registry: prometheus_client.CollectorRegistry = prometheus_client.CollectorRegistry()
25
-
26
- # The following real-time metrics are being updated through the monitoring stream graph steps
27
- _prediction_counter: prometheus_client.Counter = prometheus_client.Counter(
28
- name=PrometheusMetric.PREDICTIONS_TOTAL,
29
- documentation="Counter for total predictions",
30
- registry=_registry,
31
- labelnames=[
32
- EventFieldType.PROJECT,
33
- EventFieldType.ENDPOINT_ID,
34
- EventFieldType.MODEL,
35
- EventFieldType.ENDPOINT_TYPE,
36
- ],
37
- )
38
- _model_latency: prometheus_client.Summary = prometheus_client.Summary(
39
- name=PrometheusMetric.MODEL_LATENCY_SECONDS,
40
- documentation="Summary for for model latency",
41
- registry=_registry,
42
- labelnames=[
43
- EventFieldType.PROJECT,
44
- EventFieldType.ENDPOINT_ID,
45
- EventFieldType.MODEL,
46
- EventFieldType.ENDPOINT_TYPE,
47
- ],
48
- )
49
- _income_features: prometheus_client.Gauge = prometheus_client.Gauge(
50
- name=PrometheusMetric.INCOME_FEATURES,
51
- documentation="Samples of features and predictions",
52
- registry=_registry,
53
- labelnames=[
54
- EventFieldType.PROJECT,
55
- EventFieldType.ENDPOINT_ID,
56
- EventFieldType.METRIC,
57
- ],
58
- )
59
- _error_counter: prometheus_client.Counter = prometheus_client.Counter(
60
- name=PrometheusMetric.ERRORS_TOTAL,
61
- documentation="Counter for total errors",
62
- registry=_registry,
63
- labelnames=[
64
- EventFieldType.PROJECT,
65
- EventFieldType.ENDPOINT_ID,
66
- EventFieldType.MODEL,
67
- ],
68
- )
69
-
70
- # The following metrics are being updated through the model monitoring batch job
71
- _batch_metrics: prometheus_client.Gauge = prometheus_client.Gauge(
72
- name=PrometheusMetric.DRIFT_METRICS,
73
- documentation="Results from the batch drift analysis",
74
- registry=_registry,
75
- labelnames=[
76
- EventFieldType.PROJECT,
77
- EventFieldType.ENDPOINT_ID,
78
- EventFieldType.METRIC,
79
- ],
80
- )
81
- _drift_status: prometheus_client.Enum = prometheus_client.Enum(
82
- name=PrometheusMetric.DRIFT_STATUS,
83
- documentation="Drift status of the model endpoint",
84
- registry=_registry,
85
- states=["NO_DRIFT", "DRIFT_DETECTED", "POSSIBLE_DRIFT"],
86
- labelnames=[EventFieldType.PROJECT, EventFieldType.ENDPOINT_ID],
87
- )
88
-
89
-
90
- def _write_registry(func):
91
- def wrapper(*args, **kwargs):
92
- global _registry
93
- """A wrapper function to update the registry file each time a metric has been updated"""
94
- func(*args, **kwargs)
95
- prometheus_client.write_to_textfile(path=_registry_path, registry=_registry)
96
-
97
- return wrapper
98
-
99
-
100
- @_write_registry
101
- def write_predictions_and_latency_metrics(
102
- project: str, endpoint_id: str, latency: int, model_name: str, endpoint_type: int
103
- ):
104
- """
105
- Update the prediction counter and the latency value of the provided model endpoint within Prometheus registry.
106
- Please note that while the prediction counter is ALWAYS increasing by 1,the latency summary metric is being
107
- increased by the event latency time. Grafana dashboard will query the average latency time by dividing the total
108
- latency value by the total amount of predictions.
109
-
110
- :param project: Project name.
111
- :param endpoint_id: Model endpoint unique id.
112
- :param latency: Latency time (microsecond) in which the event has been processed through the model server.
113
- :param model_name: Model name which will be used by Grafana for displaying the results by model.
114
- :param endpoint_type: Endpoint type that is represented by an int (possible values: 1,2,3) corresponding to the
115
- Enum class :py:class:`~mlrun.common.schemas.model_monitoring.EndpointType`.
116
- """
117
-
118
- # Increase the prediction counter by 1
119
- _prediction_counter.labels(
120
- project=project,
121
- endpoint_id=endpoint_id,
122
- model=model_name,
123
- endpoint_type=endpoint_type,
124
- ).inc(1)
125
-
126
- # Increase the latency value according to the provided latency of the current event
127
- _model_latency.labels(
128
- project=project,
129
- endpoint_id=endpoint_id,
130
- model=model_name,
131
- endpoint_type=endpoint_type,
132
- ).observe(latency)
133
-
134
-
135
- @_write_registry
136
- def write_income_features(project: str, endpoint_id: str, features: dict[str, float]):
137
- """Update a sample of features.
138
-
139
- :param project: Project name.
140
- :param endpoint_id: Model endpoint unique id.
141
- :param features: Dictionary in which the key is a feature name and the value is a float number.
142
-
143
-
144
- """
145
-
146
- for metric in features:
147
- _income_features.labels(
148
- project=project, endpoint_id=endpoint_id, metric=metric
149
- ).set(value=features[metric])
150
-
151
-
152
- @_write_registry
153
- def write_drift_metrics(project: str, endpoint_id: str, metric: str, value: float):
154
- """Update drift metrics that have been calculated through the monitoring batch job
155
-
156
- :param project: Project name.
157
- :param endpoint_id: Model endpoint unique id.
158
- :param metric: Metric name (e.g. TVD, Hellinger).
159
- :param value: Metric value as a float.
160
-
161
- """
162
-
163
- _batch_metrics.labels(project=project, endpoint_id=endpoint_id, metric=metric).set(
164
- value=value
165
- )
166
-
167
-
168
- @_write_registry
169
- def write_drift_status(project: str, endpoint_id: str, drift_status: str):
170
- """
171
- Update the drift status enum for a specific model endpoint.
172
-
173
- :param project: Project name.
174
- :param endpoint_id: Model endpoint unique id.
175
- :param drift_status: Drift status value, can be one of the following: 'NO_DRIFT', 'DRIFT_DETECTED', or
176
- 'POSSIBLE_DRIFT'.
177
- """
178
-
179
- _drift_status.labels(project=project, endpoint_id=endpoint_id).state(drift_status)
180
-
181
-
182
- @_write_registry
183
- def write_errors(project: str, endpoint_id: str, model_name: str):
184
- """
185
- Update the error counter for a specific model endpoint.
186
-
187
- :param project: Project name.
188
- :param endpoint_id: Model endpoint unique id.
189
- :param model_name: Model name. Will be used by Grafana to show the amount of errors per model by time.
190
- """
191
-
192
- _error_counter.labels(
193
- project=project, endpoint_id=endpoint_id, model=model_name
194
- ).inc(1)
195
-
196
-
197
- def get_registry() -> str:
198
- """Returns the parsed registry file according to the exposition format of Prometheus."""
199
-
200
- # Read the registry file (note that the text is stored in UTF-8 format)
201
- f = open(_registry_path)
202
- lines = f.read()
203
- f.close()
204
-
205
- # Reset part of the metrics to avoid a repeating scraping of the same value
206
- clean_metrics()
207
-
208
- return lines
209
-
210
-
211
- @_write_registry
212
- def clean_metrics():
213
- """Clean the income features values. As these results are relevant only for a certain timestamp, we will remove
214
- them from the global registry after they have been scraped by Prometheus."""
215
-
216
- _income_features.clear()
@@ -1,111 +0,0 @@
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
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
16
-
17
- import enum
18
- import typing
19
-
20
- import mlrun.common.schemas.secret
21
- import mlrun.errors
22
-
23
- from .model_endpoint_store import ModelEndpointStore
24
-
25
-
26
- class ModelEndpointStoreType(enum.Enum):
27
- """Enum class to handle the different store type values for saving a model endpoint record."""
28
-
29
- v3io_nosql = "v3io-nosql"
30
- SQL = "sql"
31
-
32
- def to_endpoint_store(
33
- self,
34
- project: str,
35
- access_key: str = None,
36
- endpoint_store_connection: str = None,
37
- secret_provider: typing.Callable = None,
38
- ) -> ModelEndpointStore:
39
- """
40
- Return a ModelEndpointStore object based on the provided enum value.
41
-
42
- :param project: The name of the project.
43
- :param access_key: Access key with permission to the DB table. Note that if access key is None
44
- and the endpoint target is from type KV then the access key will be
45
- retrieved from the environment variable.
46
- :param endpoint_store_connection: A valid connection string for model endpoint target. Contains several
47
- key-value pairs that required for the database connection.
48
- e.g. A root user with password 1234, tries to connect a schema called
49
- mlrun within a local MySQL DB instance:
50
- 'mysql+pymysql://root:1234@localhost:3306/mlrun'.
51
- :param secret_provider: An optional secret provider to get the connection string secret.
52
-
53
- :return: `ModelEndpointStore` object.
54
-
55
- """
56
-
57
- if self.value == ModelEndpointStoreType.v3io_nosql.value:
58
- from .kv_model_endpoint_store import KVModelEndpointStore
59
-
60
- # Get V3IO access key from env
61
- access_key = access_key or mlrun.mlconf.get_v3io_access_key()
62
-
63
- return KVModelEndpointStore(project=project, access_key=access_key)
64
-
65
- # Assuming SQL store target if store type is not KV.
66
- # Update these lines once there are more than two store target types.
67
-
68
- from .sql_model_endpoint_store import SQLModelEndpointStore
69
-
70
- return SQLModelEndpointStore(
71
- project=project,
72
- sql_connection_string=endpoint_store_connection,
73
- secret_provider=secret_provider,
74
- )
75
-
76
- @classmethod
77
- def _missing_(cls, value: typing.Any):
78
- """A lookup function to handle an invalid value.
79
- :param value: Provided enum (invalid) value.
80
- """
81
- valid_values = list(cls.__members__.keys())
82
- raise mlrun.errors.MLRunInvalidArgumentError(
83
- f"{value} is not a valid endpoint store, please choose a valid value: %{valid_values}."
84
- )
85
-
86
-
87
- def get_model_endpoint_store(
88
- project: str,
89
- access_key: str = None,
90
- secret_provider: typing.Callable = None,
91
- ) -> ModelEndpointStore:
92
- """
93
- Getting the DB target type based on mlrun.config.model_endpoint_monitoring.store_type.
94
-
95
- :param project: The name of the project.
96
- :param access_key: Access key with permission to the DB table.
97
- :param secret_provider: An optional secret provider to get the connection string secret.
98
-
99
- :return: `ModelEndpointStore` object. Using this object, the user can apply different operations on the
100
- model endpoint record such as write, update, get and delete.
101
- """
102
-
103
- # Get store type value from ModelEndpointStoreType enum class
104
- model_endpoint_store_type = ModelEndpointStoreType(
105
- mlrun.mlconf.model_endpoint_monitoring.store_type
106
- )
107
-
108
- # Convert into model endpoint store target object
109
- return model_endpoint_store_type.to_endpoint_store(
110
- project=project, access_key=access_key, secret_provider=secret_provider
111
- )