Skip to content

Commit

Permalink
Enable to set scrape metrics label on piplines runs (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Oct 25, 2020
1 parent d96592f commit b45eaa4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
8 changes: 8 additions & 0 deletions mlrun/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def main():
@click.option("--label", multiple=True, help="run labels (key=val)")
@click.option("--watch", "-w", is_flag=True, help="watch/tail run log")
@click.option("--verbose", is_flag=True, help="verbose log")
@click.option(
"--scrape-metrics",
is_flag=True,
help="whether to add the `mlrun/scrape-metrics` label to this run's resources",
)
@click.argument("run_args", nargs=-1, type=click.UNPROCESSED)
def run(
url,
Expand Down Expand Up @@ -153,6 +158,7 @@ def run(
label,
watch,
verbose,
scrape_metrics,
run_args,
):
"""Execute a task and inject parameters."""
Expand Down Expand Up @@ -237,6 +243,8 @@ def run(
set_item(
runobj.spec, secrets, run_keys.secrets, line2keylist(secrets, "kind", "source")
)
set_item(runobj.spec, verbose, "verbose")
set_item(runobj.spec, scrape_metrics, "scrape_metrics")

if kfp or runobj.spec.verbose or verbose:
print("MLRun version: {}".format(str(Version().get())))
Expand Down
5 changes: 5 additions & 0 deletions mlrun/kfpops.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def mlrun_op(
more_args: list = None,
tuning_strategy=None,
verbose=None,
scrape_metrics=False,
):
"""mlrun KubeFlow pipelines operator, use to form pipeline steps
Expand Down Expand Up @@ -190,6 +191,7 @@ def mlrun_op(
:param handler code entry-point/hanfler name
:param job_image name of the image user for the job
:param verbose: add verbose prints/logs
:param scrape_metrics: whether to add the `mlrun/scrape-metrics` label to this run's resources
:returns: KFP step operation
Expand Down Expand Up @@ -293,6 +295,7 @@ def mlrun_pipeline(
project = project or runobj.metadata.project
labels = runobj.metadata.labels or labels
verbose = verbose or runobj.spec.verbose
scrape_metrics = scrape_metrics or runobj.spec.scrape_metrics

if not name:
if not function_name:
Expand Down Expand Up @@ -355,6 +358,8 @@ def mlrun_pipeline(
cmd += ["--mode", mode]
if verbose:
cmd += ["--verbose"]
if scrape_metrics:
cmd += ["--scrape-metrics"]
if more_args:
cmd += more_args

Expand Down
33 changes: 18 additions & 15 deletions mlrun/runtimes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,24 +614,26 @@ def as_step(
labels: dict = None,
use_db=True,
verbose=None,
scrape_metrics=False,
):
"""Run a local or remote task.
:param runspec: run template object or dict (see RunTemplate)
:param handler: name of the function handler
:param name: execution name
:param project: project name
:param params: input parameters (dict)
:param hyperparams: hyper parameters
:param selector: selection criteria for hyper params
:param inputs: input objects (dict of key: path)
:param outputs: list of outputs which can pass in the workflow
:param artifact_path: default artifact output path (replace out_path)
:param workdir: default input artifacts path
:param image: container image to use
:param labels: labels to tag the job/run with ({key:val, ..})
:param use_db: save function spec in the db (vs the workflow file)
:param verbose: add verbose prints/logs
:param runspec: run template object or dict (see RunTemplate)
:param handler: name of the function handler
:param name: execution name
:param project: project name
:param params: input parameters (dict)
:param hyperparams: hyper parameters
:param selector: selection criteria for hyper params
:param inputs: input objects (dict of key: path)
:param outputs: list of outputs which can pass in the workflow
:param artifact_path: default artifact output path (replace out_path)
:param workdir: default input artifacts path
:param image: container image to use
:param labels: labels to tag the job/run with ({key:val, ..})
:param use_db: save function spec in the db (vs the workflow file)
:param verbose: add verbose prints/logs
:param scrape_metrics: whether to add the `mlrun/scrape-metrics` label to this run's resources
:return: KubeFlow containerOp
"""
Expand Down Expand Up @@ -667,6 +669,7 @@ def as_step(
out_path=artifact_path,
in_path=workdir,
verbose=verbose,
scrape_metrics=scrape_metrics,
)

def export(self, target="", format=".yaml", secrets=None, strip=True):
Expand Down

0 comments on commit b45eaa4

Please sign in to comment.