mlrun 1.7.0rc33__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 (44) hide show
  1. mlrun/artifacts/base.py +1 -0
  2. mlrun/common/schemas/__init__.py +1 -1
  3. mlrun/common/schemas/common.py +3 -0
  4. mlrun/common/schemas/function.py +7 -0
  5. mlrun/common/schemas/model_monitoring/__init__.py +1 -2
  6. mlrun/common/schemas/model_monitoring/constants.py +3 -16
  7. mlrun/common/schemas/notification.py +1 -1
  8. mlrun/common/schemas/project.py +35 -3
  9. mlrun/common/types.py +1 -0
  10. mlrun/config.py +6 -7
  11. mlrun/datastore/sources.py +8 -4
  12. mlrun/db/base.py +7 -5
  13. mlrun/db/httpdb.py +10 -8
  14. mlrun/execution.py +1 -3
  15. mlrun/model.py +143 -23
  16. mlrun/model_monitoring/applications/context.py +13 -15
  17. mlrun/model_monitoring/applications/evidently_base.py +4 -5
  18. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +5 -0
  19. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +2 -2
  20. mlrun/model_monitoring/db/tsdb/base.py +6 -3
  21. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +0 -3
  22. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +22 -3
  23. mlrun/model_monitoring/stream_processing.py +5 -153
  24. mlrun/projects/pipelines.py +76 -73
  25. mlrun/projects/project.py +7 -1
  26. mlrun/run.py +26 -9
  27. mlrun/runtimes/nuclio/api_gateway.py +22 -6
  28. mlrun/runtimes/nuclio/application/application.py +62 -11
  29. mlrun/runtimes/nuclio/function.py +8 -0
  30. mlrun/runtimes/nuclio/serving.py +6 -6
  31. mlrun/runtimes/pod.py +2 -4
  32. mlrun/serving/server.py +12 -7
  33. mlrun/serving/states.py +16 -2
  34. mlrun/utils/db.py +3 -0
  35. mlrun/utils/helpers.py +30 -19
  36. mlrun/utils/notifications/notification/webhook.py +8 -1
  37. mlrun/utils/version/version.json +2 -2
  38. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/METADATA +4 -2
  39. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/RECORD +43 -44
  40. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/WHEEL +1 -1
  41. mlrun/model_monitoring/prometheus.py +0 -216
  42. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/LICENSE +0 -0
  43. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/entry_points.txt +0 -0
  44. {mlrun-1.7.0rc33.dist-info → mlrun-1.7.0rc35.dist-info}/top_level.txt +0 -0
@@ -23,7 +23,7 @@ import mlrun.model_monitoring.applications.base as mm_base
23
23
  import mlrun.model_monitoring.applications.context as mm_context
24
24
  from mlrun.errors import MLRunIncompatibleVersionError
25
25
 
26
- SUPPORTED_EVIDENTLY_VERSION = semver.Version.parse("0.4.11")
26
+ SUPPORTED_EVIDENTLY_VERSION = semver.Version.parse("0.4.32")
27
27
 
28
28
 
29
29
  def _check_evidently_version(*, cur: semver.Version, ref: semver.Version) -> None:
@@ -57,12 +57,11 @@ except ModuleNotFoundError:
57
57
 
58
58
 
59
59
  if _HAS_EVIDENTLY:
60
- from evidently.renderers.notebook_utils import determine_template
61
60
  from evidently.report.report import Report
62
61
  from evidently.suite.base_suite import Suite
63
62
  from evidently.ui.type_aliases import STR_UUID
64
63
  from evidently.ui.workspace import Workspace
65
- from evidently.utils.dashboard import TemplateParams
64
+ from evidently.utils.dashboard import TemplateParams, file_html_template
66
65
 
67
66
 
68
67
  class EvidentlyModelMonitoringApplicationBase(mm_base.ModelMonitoringApplicationBase):
@@ -123,7 +122,7 @@ class EvidentlyModelMonitoringApplicationBase(mm_base.ModelMonitoringApplication
123
122
  additional_graphs={},
124
123
  )
125
124
 
126
- dashboard_html = self._render(determine_template("inline"), template_params)
125
+ dashboard_html = self._render(file_html_template, template_params)
127
126
  self.context.log_artifact(
128
127
  artifact_name, body=dashboard_html.encode("utf-8"), format="html"
129
128
  )
@@ -201,7 +200,7 @@ class EvidentlyModelMonitoringApplicationBaseV2(
201
200
  additional_graphs={},
202
201
  )
203
202
 
204
- dashboard_html = self._render(determine_template("inline"), template_params)
203
+ dashboard_html = self._render(file_html_template, template_params)
205
204
  monitoring_context.log_artifact(
206
205
  artifact_name, body=dashboard_html.encode("utf-8"), format="html"
207
206
  )
@@ -177,6 +177,11 @@ class SQLStoreBase(StoreBase):
177
177
  param table: SQLAlchemy declarative table.
178
178
  :param criteria: A list of binary expressions that filter the query.
179
179
  """
180
+ if not self._engine.has_table(table.__tablename__):
181
+ logger.debug(
182
+ f"Table {table.__tablename__} does not exist in the database. Skipping deletion."
183
+ )
184
+ return
180
185
  with create_session(dsn=self._sql_connection_string) as session:
181
186
  # Generate and commit the delete query
182
187
  session.query(
@@ -408,14 +408,14 @@ class KVStoreBase(StoreBase):
408
408
 
409
409
  """
410
410
  try:
411
- data = self.client.kv.get(
411
+ response = self.client.kv.get(
412
412
  container=self._get_monitoring_schedules_container(
413
413
  project_name=self.project
414
414
  ),
415
415
  table_path=endpoint_id,
416
416
  key=application_name,
417
417
  )
418
- return data.output.item[mm_schemas.SchedulingKeys.LAST_ANALYZED]
418
+ return response.output.item[mm_schemas.SchedulingKeys.LAST_ANALYZED]
419
419
  except v3io.dataplane.response.HttpResponseError as err:
420
420
  logger.debug("Error while getting last analyzed time", err=err)
421
421
  raise mlrun.errors.MLRunNotFoundError(
@@ -27,7 +27,7 @@ from mlrun.utils import logger
27
27
  class TSDBConnector(ABC):
28
28
  type: typing.ClassVar[str]
29
29
 
30
- def __init__(self, project: str):
30
+ def __init__(self, project: str) -> None:
31
31
  """
32
32
  Initialize a new TSDB connector. The connector is used to interact with the TSDB and store monitoring data.
33
33
  At the moment we have 3 different types of monitoring data:
@@ -42,10 +42,10 @@ class TSDBConnector(ABC):
42
42
  writer.
43
43
 
44
44
  :param project: the name of the project.
45
-
46
45
  """
47
46
  self.project = project
48
47
 
48
+ @abstractmethod
49
49
  def apply_monitoring_stream_steps(self, graph):
50
50
  """
51
51
  Apply TSDB steps on the provided monitoring graph. Throughout these steps, the graph stores live data of
@@ -58,6 +58,7 @@ class TSDBConnector(ABC):
58
58
  """
59
59
  pass
60
60
 
61
+ @abstractmethod
61
62
  def write_application_event(
62
63
  self,
63
64
  event: dict,
@@ -69,13 +70,14 @@ class TSDBConnector(ABC):
69
70
  :raise mlrun.errors.MLRunRuntimeError: If an error occurred while writing the event.
70
71
  """
71
72
 
73
+ @abstractmethod
72
74
  def delete_tsdb_resources(self):
73
75
  """
74
76
  Delete all project resources in the TSDB connector, such as model endpoints data and drift results.
75
77
  """
76
-
77
78
  pass
78
79
 
80
+ @abstractmethod
79
81
  def get_model_endpoint_real_time_metrics(
80
82
  self,
81
83
  endpoint_id: str,
@@ -102,6 +104,7 @@ class TSDBConnector(ABC):
102
104
  """
103
105
  pass
104
106
 
107
+ @abstractmethod
105
108
  def create_tables(self) -> None:
106
109
  """
107
110
  Create the TSDB tables using the TSDB connector. At the moment we support 3 types of tables:
@@ -11,7 +11,6 @@
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
14
 
16
15
  import json
17
16
 
@@ -21,8 +20,6 @@ from mlrun.common.schemas.model_monitoring import (
21
20
  EventKeyMetrics,
22
21
  )
23
22
 
24
- _TABLE_COLUMN = "table_column"
25
-
26
23
 
27
24
  class ProcessBeforeTDEngine(mlrun.feature_store.steps.MapClass):
28
25
  def __init__(self, **kwargs):
@@ -11,7 +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
- #
14
+
15
+ from typing import Any
15
16
 
16
17
  import mlrun.feature_store.steps
17
18
  from mlrun.common.schemas.model_monitoring import (
@@ -21,6 +22,24 @@ from mlrun.common.schemas.model_monitoring import (
21
22
  )
22
23
 
23
24
 
25
+ def _normalize_dict_for_v3io_frames(event: dict[str, Any]) -> dict[str, Any]:
26
+ """
27
+ Normalize user defined keys - input data to a model and its predictions,
28
+ to a form V3IO frames tolerates.
29
+
30
+ The dictionary keys should conform to '^[a-zA-Z_:]([a-zA-Z0-9_:])*$'.
31
+ """
32
+ prefix = "_"
33
+
34
+ def norm_key(key: str) -> str:
35
+ key = key.replace("-", "_") # hyphens `-` are not allowed
36
+ if key and key[0].isdigit(): # starting with a digit is not allowed
37
+ return prefix + key
38
+ return key
39
+
40
+ return {norm_key(k): v for k, v in event.items()}
41
+
42
+
24
43
  class ProcessBeforeTSDB(mlrun.feature_store.steps.MapClass):
25
44
  def __init__(self, **kwargs):
26
45
  """
@@ -68,8 +87,8 @@ class ProcessBeforeTSDB(mlrun.feature_store.steps.MapClass):
68
87
  # endpoint_features includes the event values of each feature and prediction
69
88
  endpoint_features = {
70
89
  EventFieldType.RECORD_TYPE: EventKeyMetrics.ENDPOINT_FEATURES,
71
- **event[EventFieldType.NAMED_PREDICTIONS],
72
- **event[EventFieldType.NAMED_FEATURES],
90
+ **_normalize_dict_for_v3io_frames(event[EventFieldType.NAMED_PREDICTIONS]),
91
+ **_normalize_dict_for_v3io_frames(event[EventFieldType.NAMED_FEATURES]),
73
92
  **base_event,
74
93
  }
75
94
  # Create a dictionary that includes both base_metrics and endpoint_features
@@ -27,7 +27,6 @@ import mlrun.datastore.targets
27
27
  import mlrun.feature_store as fstore
28
28
  import mlrun.feature_store.steps
29
29
  import mlrun.model_monitoring.db
30
- import mlrun.model_monitoring.prometheus
31
30
  import mlrun.serving.states
32
31
  import mlrun.utils
33
32
  from mlrun.common.schemas.model_monitoring.constants import (
@@ -37,7 +36,6 @@ from mlrun.common.schemas.model_monitoring.constants import (
37
36
  FileTargetKind,
38
37
  ModelEndpointTarget,
39
38
  ProjectSecretKeys,
40
- PrometheusEndpoints,
41
39
  )
42
40
  from mlrun.utils import logger
43
41
 
@@ -172,39 +170,12 @@ class EventStreamProcessor:
172
170
  fn.set_topology(mlrun.serving.states.StepKinds.flow),
173
171
  )
174
172
 
175
- # Event routing based on the provided path
176
- def apply_event_routing():
177
- typing.cast(
178
- mlrun.serving.TaskStep,
179
- graph.add_step(
180
- "EventRouting",
181
- full_event=True,
182
- project=self.project,
183
- ),
184
- ).respond()
185
-
186
- apply_event_routing()
187
-
188
- # Filter out events with '-' in the path basename from going forward
189
- # through the next steps of the stream graph
190
- def apply_storey_filter_stream_events():
191
- # Filter events with Prometheus endpoints path
192
- graph.add_step(
193
- "storey.Filter",
194
- "filter_stream_event",
195
- _fn=f"(event.path not in {PrometheusEndpoints.list()})",
196
- full_event=True,
197
- )
198
-
199
- apply_storey_filter_stream_events()
200
-
201
173
  # Process endpoint event: splitting into sub-events and validate event data
202
174
  def apply_process_endpoint_event():
203
175
  graph.add_step(
204
176
  "ProcessEndpointEvent",
205
177
  full_event=True,
206
178
  project=self.project,
207
- after="filter_stream_event",
208
179
  )
209
180
 
210
181
  apply_process_endpoint_event()
@@ -324,33 +295,10 @@ class EventStreamProcessor:
324
295
 
325
296
  apply_storey_sample_window()
326
297
 
327
- # TSDB branch (skip to Prometheus if in CE env)
328
- if not mlrun.mlconf.is_ce_mode():
329
- tsdb_connector = mlrun.model_monitoring.get_tsdb_connector(
330
- project=self.project, secret_provider=secret_provider
331
- )
332
- tsdb_connector.apply_monitoring_stream_steps(graph=graph)
333
-
334
- else:
335
- # Prometheus
336
- # Increase the prediction counter by 1 and update the latency value
337
- graph.add_step(
338
- "IncCounter",
339
- name="IncCounter",
340
- after="MapFeatureNames",
341
- project=self.project,
342
- )
343
-
344
- # Record a sample of features and labels
345
- def apply_record_features_to_prometheus():
346
- graph.add_step(
347
- "RecordFeatures",
348
- name="RecordFeaturesToPrometheus",
349
- after="sample",
350
- project=self.project,
351
- )
352
-
353
- apply_record_features_to_prometheus()
298
+ tsdb_connector = mlrun.model_monitoring.get_tsdb_connector(
299
+ project=self.project, secret_provider=secret_provider
300
+ )
301
+ tsdb_connector.apply_monitoring_stream_steps(graph=graph)
354
302
 
355
303
  # Parquet branch
356
304
  # Filter and validate different keys before writing the data to Parquet target
@@ -542,11 +490,7 @@ class ProcessEndpointEvent(mlrun.feature_store.steps.MapClass):
542
490
  error = event.get("error")
543
491
  if error:
544
492
  self.error_count[endpoint_id] += 1
545
- mlrun.model_monitoring.prometheus.write_errors(
546
- project=self.project,
547
- endpoint_id=event["endpoint_id"],
548
- model_name=event["model"],
549
- )
493
+ # TODO: write to tsdb / kv once in a while
550
494
  raise mlrun.errors.MLRunInvalidArgumentError(str(error))
551
495
 
552
496
  # Validate event fields
@@ -973,98 +917,6 @@ class InferSchema(mlrun.feature_store.steps.MapClass):
973
917
  return event
974
918
 
975
919
 
976
- class EventRouting(mlrun.feature_store.steps.MapClass):
977
- """
978
- Router the event according to the configured path under event.path. Please note that this step returns the result
979
- to the caller. At the moment there are several paths:
980
-
981
- - /model-monitoring-metrics (GET): return Prometheus registry results as a text. Will be used by Prometheus client
982
- to scrape the results from the monitoring stream memory.
983
-
984
- - /monitoring-batch-metrics (POST): update the Prometheus registry with the provided statistical metrics such as the
985
- statistical metrics from the monitoring batch job. Note that the event body is a list of dictionaries of different
986
- metrics.
987
-
988
- - /monitoring-drift-status (POST): update the Prometheus registry with the provided model drift status.
989
-
990
- """
991
-
992
- def __init__(
993
- self,
994
- project: str,
995
- **kwargs,
996
- ):
997
- super().__init__(**kwargs)
998
- self.project: str = project
999
-
1000
- def do(self, event):
1001
- if event.path == PrometheusEndpoints.MODEL_MONITORING_METRICS:
1002
- # Return a parsed Prometheus registry file
1003
- event.body = mlrun.model_monitoring.prometheus.get_registry()
1004
- elif event.path == PrometheusEndpoints.MONITORING_BATCH_METRICS:
1005
- # Update statistical metrics
1006
- for event_metric in event.body:
1007
- mlrun.model_monitoring.prometheus.write_drift_metrics(
1008
- project=self.project,
1009
- endpoint_id=event_metric[EventFieldType.ENDPOINT_ID],
1010
- metric=event_metric[EventFieldType.METRIC],
1011
- value=event_metric[EventFieldType.VALUE],
1012
- )
1013
- elif event.path == PrometheusEndpoints.MONITORING_DRIFT_STATUS:
1014
- # Update drift status
1015
- mlrun.model_monitoring.prometheus.write_drift_status(
1016
- project=self.project,
1017
- endpoint_id=event.body[EventFieldType.ENDPOINT_ID],
1018
- drift_status=event.body[EventFieldType.DRIFT_STATUS],
1019
- )
1020
-
1021
- return event
1022
-
1023
-
1024
- class IncCounter(mlrun.feature_store.steps.MapClass):
1025
- """Increase prediction counter by 1 and update the total latency value"""
1026
-
1027
- def __init__(self, project: str, **kwargs):
1028
- super().__init__(**kwargs)
1029
- self.project: str = project
1030
-
1031
- def do(self, event):
1032
- # Compute prediction per second
1033
-
1034
- mlrun.model_monitoring.prometheus.write_predictions_and_latency_metrics(
1035
- project=self.project,
1036
- endpoint_id=event[EventFieldType.ENDPOINT_ID],
1037
- latency=event[EventFieldType.LATENCY],
1038
- model_name=event[EventFieldType.MODEL],
1039
- endpoint_type=event[EventFieldType.ENDPOINT_TYPE],
1040
- )
1041
-
1042
- return event
1043
-
1044
-
1045
- class RecordFeatures(mlrun.feature_store.steps.MapClass):
1046
- """Record a sample of features and labels in Prometheus registry"""
1047
-
1048
- def __init__(self, project: str, **kwargs):
1049
- super().__init__(**kwargs)
1050
- self.project: str = project
1051
-
1052
- def do(self, event):
1053
- # Generate a dictionary of features and predictions
1054
- features = {
1055
- **event[EventFieldType.NAMED_PREDICTIONS],
1056
- **event[EventFieldType.NAMED_FEATURES],
1057
- }
1058
-
1059
- mlrun.model_monitoring.prometheus.write_income_features(
1060
- project=self.project,
1061
- endpoint_id=event[EventFieldType.ENDPOINT_ID],
1062
- features=features,
1063
- )
1064
-
1065
- return event
1066
-
1067
-
1068
920
  def update_endpoint_record(
1069
921
  project: str,
1070
922
  endpoint_id: str,
@@ -404,12 +404,15 @@ class _PipelineRunStatus:
404
404
  return self._exc
405
405
 
406
406
  def wait_for_completion(self, timeout=None, expected_statuses=None):
407
- self._state = self._engine.wait_for_completion(
408
- self.run_id,
407
+ returned_state = self._engine.wait_for_completion(
408
+ self,
409
409
  project=self.project,
410
410
  timeout=timeout,
411
411
  expected_statuses=expected_statuses,
412
412
  )
413
+ # TODO: returning a state is optional until all runners implement wait_for_completion
414
+ if returned_state:
415
+ self._state = returned_state
413
416
  return self._state
414
417
 
415
418
  def __str__(self):
@@ -458,6 +461,48 @@ class _PipelineRunner(abc.ABC):
458
461
  def get_state(run_id, project=None):
459
462
  pass
460
463
 
464
+ @staticmethod
465
+ def get_run_status(
466
+ project,
467
+ run: _PipelineRunStatus,
468
+ timeout=None,
469
+ expected_statuses=None,
470
+ notifiers: mlrun.utils.notifications.CustomNotificationPusher = None,
471
+ **kwargs,
472
+ ):
473
+ timeout = timeout or 60 * 60
474
+ raise_error = None
475
+ state = ""
476
+ try:
477
+ if timeout:
478
+ state = run.wait_for_completion(
479
+ timeout=timeout, expected_statuses=expected_statuses
480
+ )
481
+ except RuntimeError as exc:
482
+ # push runs table also when we have errors
483
+ raise_error = exc
484
+
485
+ mldb = mlrun.db.get_run_db(secrets=project._secrets)
486
+ runs = mldb.list_runs(project=project.name, labels=f"workflow={run.run_id}")
487
+
488
+ # TODO: The below section duplicates notifiers.push_pipeline_run_results() logic. We should use it instead.
489
+ errors_counter = 0
490
+ for r in runs:
491
+ if r["status"].get("state", "") == "error":
492
+ errors_counter += 1
493
+
494
+ text = _PipelineRunner._generate_workflow_finished_message(
495
+ run.run_id, errors_counter, run._state
496
+ )
497
+
498
+ notifiers = notifiers or project.notifiers
499
+ if notifiers:
500
+ notifiers.push(text, "info", runs)
501
+
502
+ if raise_error:
503
+ raise raise_error
504
+ return state or run._state, errors_counter, text
505
+
461
506
  @staticmethod
462
507
  def _get_handler(workflow_handler, workflow_spec, project, secrets):
463
508
  if not (workflow_handler and callable(workflow_handler)):
@@ -474,16 +519,13 @@ class _PipelineRunner(abc.ABC):
474
519
  return workflow_handler
475
520
 
476
521
  @staticmethod
477
- @abc.abstractmethod
478
- def get_run_status(
479
- project,
480
- run,
481
- timeout=None,
482
- expected_statuses=None,
483
- notifiers: mlrun.utils.notifications.CustomNotificationPusher = None,
484
- **kwargs,
485
- ):
486
- pass
522
+ def _generate_workflow_finished_message(run_id, errors_counter, state):
523
+ text = f"Workflow {run_id} finished"
524
+ if errors_counter:
525
+ text += f" with {errors_counter} errors"
526
+ if state:
527
+ text += f", state={state}"
528
+ return text
487
529
 
488
530
 
489
531
  class _KFPRunner(_PipelineRunner):
@@ -585,12 +627,14 @@ class _KFPRunner(_PipelineRunner):
585
627
  return _PipelineRunStatus(run_id, cls, project=project, workflow=workflow_spec)
586
628
 
587
629
  @staticmethod
588
- def wait_for_completion(run_id, project=None, timeout=None, expected_statuses=None):
589
- if timeout is None:
590
- timeout = 60 * 60
630
+ def wait_for_completion(run, project=None, timeout=None, expected_statuses=None):
631
+ logger.info(
632
+ "Waiting for pipeline run completion", run_id=run.run_id, project=project
633
+ )
634
+ timeout = timeout or 60 * 60
591
635
  project_name = project.metadata.name if project else ""
592
636
  run_info = wait_for_pipeline_completion(
593
- run_id,
637
+ run.run_id,
594
638
  timeout=timeout,
595
639
  expected_statuses=expected_statuses,
596
640
  project=project_name,
@@ -608,51 +652,6 @@ class _KFPRunner(_PipelineRunner):
608
652
  return resp["run"].get("status", "")
609
653
  return ""
610
654
 
611
- @staticmethod
612
- def get_run_status(
613
- project,
614
- run,
615
- timeout=None,
616
- expected_statuses=None,
617
- notifiers: mlrun.utils.notifications.CustomNotificationPusher = None,
618
- **kwargs,
619
- ):
620
- if timeout is None:
621
- timeout = 60 * 60
622
- state = ""
623
- raise_error = None
624
- try:
625
- if timeout:
626
- logger.info("Waiting for pipeline run completion")
627
- state = run.wait_for_completion(
628
- timeout=timeout, expected_statuses=expected_statuses
629
- )
630
- except RuntimeError as exc:
631
- # push runs table also when we have errors
632
- raise_error = exc
633
-
634
- mldb = mlrun.db.get_run_db(secrets=project._secrets)
635
- runs = mldb.list_runs(project=project.name, labels=f"workflow={run.run_id}")
636
-
637
- # TODO: The below section duplicates notifiers.push_pipeline_run_results() logic. We should use it instead.
638
- had_errors = 0
639
- for r in runs:
640
- if r["status"].get("state", "") == "error":
641
- had_errors += 1
642
-
643
- text = f"Workflow {run.run_id} finished"
644
- if had_errors:
645
- text += f" with {had_errors} errors"
646
- if state:
647
- text += f", state={state}"
648
-
649
- notifiers = notifiers or project.notifiers
650
- notifiers.push(text, "info", runs)
651
-
652
- if raise_error:
653
- raise raise_error
654
- return state, had_errors, text
655
-
656
655
 
657
656
  class _LocalRunner(_PipelineRunner):
658
657
  """local pipelines runner"""
@@ -732,18 +731,10 @@ class _LocalRunner(_PipelineRunner):
732
731
  return ""
733
732
 
734
733
  @staticmethod
735
- def wait_for_completion(run_id, project=None, timeout=None, expected_statuses=None):
736
- pass
737
-
738
- @staticmethod
739
- def get_run_status(
740
- project,
741
- run,
742
- timeout=None,
743
- expected_statuses=None,
744
- notifiers: mlrun.utils.notifications.CustomNotificationPusher = None,
745
- **kwargs,
746
- ):
734
+ def wait_for_completion(run, project=None, timeout=None, expected_statuses=None):
735
+ # TODO: local runner blocks for the duration of the pipeline.
736
+ # Therefore usually there will be nothing to wait for.
737
+ # However, users may run functions with watch=False and then it can be useful to wait for the runs here.
747
738
  pass
748
739
 
749
740
 
@@ -924,13 +915,25 @@ class _RemoteRunner(_PipelineRunner):
924
915
  elif inner_engine.engine == _LocalRunner.engine:
925
916
  mldb = mlrun.db.get_run_db(secrets=project._secrets)
926
917
  pipeline_runner_run = mldb.read_run(run.run_id, project=project.name)
918
+
927
919
  pipeline_runner_run = mlrun.run.RunObject.from_dict(pipeline_runner_run)
920
+
921
+ # here we are waiting for the pipeline run to complete and refreshing after that the pipeline run from the
922
+ # db
923
+ # TODO: do it with timeout
928
924
  pipeline_runner_run.logs(db=mldb)
929
925
  pipeline_runner_run.refresh()
930
926
  run._state = mlrun.common.runtimes.constants.RunStates.run_state_to_pipeline_run_status(
931
927
  pipeline_runner_run.status.state
932
928
  )
933
929
  run._exc = pipeline_runner_run.status.error
930
+ return _LocalRunner.get_run_status(
931
+ project,
932
+ run,
933
+ timeout,
934
+ expected_statuses,
935
+ notifiers=notifiers,
936
+ )
934
937
 
935
938
  else:
936
939
  raise mlrun.errors.MLRunInvalidArgumentError(
mlrun/projects/project.py CHANGED
@@ -725,7 +725,7 @@ def _project_instance_from_struct(struct, name, allow_cross_project):
725
725
  # TODO: Remove this warning in version 1.9.0 and also fix cli to support allow_cross_project
726
726
  warnings.warn(
727
727
  f"Project {name=} is different than specified on the context's project yaml. "
728
- "This behavior is deprecated and will not be supported in version 1.9.0."
728
+ "This behavior is deprecated and will not be supported from version 1.9.0."
729
729
  )
730
730
  logger.warn(error_message)
731
731
  elif allow_cross_project:
@@ -4063,6 +4063,12 @@ class MlrunProject(ModelObj):
4063
4063
  db = mlrun.db.get_run_db(secrets=self._secrets)
4064
4064
  if alert_name is None:
4065
4065
  alert_name = alert_data.name
4066
+ if alert_data.project is not None and alert_data.project != self.metadata.name:
4067
+ logger.warn(
4068
+ "Project in alert does not match project in operation",
4069
+ project=alert_data.project,
4070
+ )
4071
+ alert_data.project = self.metadata.name
4066
4072
  return db.store_alert_config(alert_name, alert_data, project=self.metadata.name)
4067
4073
 
4068
4074
  def get_alert_config(self, alert_name: str) -> AlertConfig: