From 6612bb4e3e55cb2608a0988f2bc0e219b759ca64 Mon Sep 17 00:00:00 2001 From: Yaron Haviv Date: Thu, 1 Jul 2021 01:27:25 +0300 Subject: [PATCH] [API] Fix bugs when using feature vectors and in real time ingestion (#1073) --- mlrun/execution.py | 15 +++++++++++---- mlrun/feature_store/api.py | 2 +- mlrun/runtimes/base.py | 4 +++- mlrun/runtimes/function.py | 18 ++++++++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/mlrun/execution.py b/mlrun/execution.py index a12dc5a4d4c..96955206109 100644 --- a/mlrun/execution.py +++ b/mlrun/execution.py @@ -233,7 +233,14 @@ def get_meta(self): @classmethod def from_dict( - cls, attrs: dict, rundb="", autocommit=False, tmp="", host=None, log_stream=None + cls, + attrs: dict, + rundb="", + autocommit=False, + tmp="", + host=None, + log_stream=None, + is_api=False, ): """create execution context from dict""" @@ -269,15 +276,15 @@ def from_dict( self._init_dbs(rundb) - if spec: - # init data related objects (require DB & Secrets to be set first) + if spec and not is_api: + # init data related objects (require DB & Secrets to be set first), skip when running in the api service self._data_stores.from_dict(spec) if inputs and isinstance(inputs, dict): for k, v in inputs.items(): if v: self._set_input(k, v) - if host: + if host and not is_api: self.set_label("host", host) start = get_in(attrs, "status.start_time") diff --git a/mlrun/feature_store/api.py b/mlrun/feature_store/api.py index dcaf2aa5411..85cac9b66df 100644 --- a/mlrun/feature_store/api.py +++ b/mlrun/feature_store/api.py @@ -433,7 +433,7 @@ def deploy_ingestion_service( featureset, source, targets, run_config.parameters ) - name = name or f"{featureset.metadata.name}_ingest" + name = name or f"{featureset.metadata.name}-ingest" if not run_config.function: function_ref = featureset.spec.function.copy() if function_ref.is_empty(): diff --git a/mlrun/runtimes/base.py b/mlrun/runtimes/base.py index 68cab7e659c..bfbcd8e5bd5 100644 --- a/mlrun/runtimes/base.py +++ b/mlrun/runtimes/base.py @@ -435,7 +435,9 @@ def run( "warning!, Api url not set, " "trying to exec remote runtime locally" ) - execution = MLClientCtx.from_dict(runspec.to_dict(), db, autocommit=False) + execution = MLClientCtx.from_dict( + runspec.to_dict(), db, autocommit=False, is_api=self._is_api_server + ) self._pre_run(runspec, execution) # hook for runtime specific prep # create task generator (for child runs) from spec diff --git a/mlrun/runtimes/function.py b/mlrun/runtimes/function.py index 8a8b57ac5cd..d8513d49b39 100644 --- a/mlrun/runtimes/function.py +++ b/mlrun/runtimes/function.py @@ -371,6 +371,8 @@ def add_vault_config_to_spec(self): def deploy( self, dashboard="", project="", tag="", verbose=False, ): + # todo: verify that the function name is normalized + verbose = verbose or self.verbose if verbose: self.set_env("MLRUN_LOG_LEVEL", "DEBUG") @@ -738,6 +740,11 @@ def deploy_nuclio_function(function: RemoteRuntime, dashboard="", watch=False): spec.set_config("spec.resources", function.spec.resources) if function.spec.no_cache: spec.set_config("spec.build.noCache", True) + if function.spec.build.functionSourceCode: + spec.set_config( + "spec.build.functionSourceCode", function.spec.build.functionSourceCode + ) + if function.spec.replicas: spec.set_config("spec.minReplicas", function.spec.replicas) spec.set_config("spec.maxReplicas", function.spec.replicas) @@ -746,9 +753,16 @@ def deploy_nuclio_function(function: RemoteRuntime, dashboard="", watch=False): spec.set_config("spec.maxReplicas", function.spec.max_replicas) dashboard = dashboard or mlconf.nuclio_dashboard_url - if function.spec.base_spec: + if function.spec.base_spec or function.spec.build.functionSourceCode: + config = function.spec.base_spec + if not config: + # if base_spec was not set (when not using code_to_function) and we have base64 code + # we create the base spec with essential attributes + config = nuclio.config.new_config() + update_in(config, "spec.handler", handler or "main:handler") + config = nuclio.config.extend_config( - function.spec.base_spec, spec, tag, function.spec.build.code_origin + config, spec, tag, function.spec.build.code_origin ) update_in(config, "metadata.name", function.metadata.name) update_in(config, "spec.volumes", function.spec.generate_nuclio_volumes())