mlrun 1.7.0rc34__py3-none-any.whl → 1.7.0rc35__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 (34) hide show
  1. mlrun/artifacts/base.py +1 -0
  2. mlrun/common/schemas/__init__.py +0 -1
  3. mlrun/common/schemas/model_monitoring/__init__.py +1 -2
  4. mlrun/common/schemas/model_monitoring/constants.py +3 -16
  5. mlrun/common/schemas/notification.py +1 -1
  6. mlrun/common/types.py +1 -0
  7. mlrun/config.py +6 -7
  8. mlrun/datastore/sources.py +8 -4
  9. mlrun/db/base.py +2 -3
  10. mlrun/db/httpdb.py +3 -3
  11. mlrun/model.py +1 -1
  12. mlrun/model_monitoring/applications/evidently_base.py +4 -5
  13. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +5 -0
  14. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +2 -2
  15. mlrun/model_monitoring/db/tsdb/base.py +6 -3
  16. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +0 -3
  17. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +22 -3
  18. mlrun/model_monitoring/stream_processing.py +5 -153
  19. mlrun/projects/pipelines.py +76 -73
  20. mlrun/run.py +4 -0
  21. mlrun/runtimes/nuclio/application/application.py +25 -2
  22. mlrun/runtimes/nuclio/function.py +5 -0
  23. mlrun/runtimes/nuclio/serving.py +1 -1
  24. mlrun/runtimes/pod.py +2 -4
  25. mlrun/serving/states.py +3 -1
  26. mlrun/utils/helpers.py +27 -14
  27. mlrun/utils/version/version.json +2 -2
  28. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/METADATA +3 -1
  29. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/RECORD +33 -34
  30. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/WHEEL +1 -1
  31. mlrun/model_monitoring/prometheus.py +0 -216
  32. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/LICENSE +0 -0
  33. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/entry_points.txt +0 -0
  34. {mlrun-1.7.0rc34.dist-info → mlrun-1.7.0rc35.dist-info}/top_level.txt +0 -0
@@ -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()