Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Improve CLI telemetry (#513)
Browse files Browse the repository at this point in the history
1. better passing params from API
2. cli actions do not include dynamic subcommands (instead they are
loggen in params now)
  • Loading branch information
mike0sv authored Dec 2, 2022
1 parent 74ca3ae commit de77417
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 128 deletions.
38 changes: 18 additions & 20 deletions mlem/cli/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
for_each_impl,
lazy_class_docstring,
make_not_required,
pass_api_log_params,
)
from mlem.core.data_type import DataAnalyzer
from mlem.core.errors import UnsupportedDataBatchLoading
from mlem.core.import_objects import ImportHook
from mlem.core.metadata import load_meta
from mlem.core.objects import MlemData, MlemModel
from mlem.runtime.client import Client
from mlem.telemetry import pass_telemetry_params
from mlem.ui import set_echo
from mlem.utils.entrypoints import list_implementations

Expand Down Expand Up @@ -108,15 +108,14 @@ def apply(
)
meta = load_meta(model, project, rev, force_type=MlemModel)

result = pass_api_log_params(
apply
)( # pylint: disable=too-many-function-args
meta,
data,
method=method,
output=output,
batch_size=batch_size,
)
with pass_telemetry_params():
result = apply(
meta,
data,
method=method,
output=output,
batch_size=batch_size,
)
if output is None:
print(
dumps(
Expand Down Expand Up @@ -214,6 +213,7 @@ def create_apply_remote(type_name):
hidden=type_name.startswith("_"),
lazy_help=lazy_class_docstring(Client.abs_name, type_name),
no_pass_from_parent=["file_conf"],
is_generated_from_ext=True,
)
def apply_remote_func(
data: str = option_data,
Expand Down Expand Up @@ -259,13 +259,11 @@ def run_apply_remote(
load_value=True,
force_type=MlemData,
)
result = pass_api_log_params(
apply_remote
)( # pylint: disable=too-many-function-args
client,
data,
method=method,
output=output,
target_project=target_project,
)
return result
with pass_telemetry_params():
return apply_remote(
client,
data,
method=method,
output=output,
target_project=target_project,
)
49 changes: 27 additions & 22 deletions mlem/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
for_each_impl,
lazy_class_docstring,
make_not_required,
pass_api_log_params,
)
from mlem.core.metadata import load_meta
from mlem.core.objects import MlemBuilder, MlemModel
from mlem.telemetry import pass_telemetry_params

build = Typer(
name="build",
Expand All @@ -45,16 +45,18 @@ def build_load(
):
from mlem.api.commands import build

pass_api_log_params(build)(
config_arg(
MlemBuilder,
load,
None,
conf=None,
file_conf=None,
),
load_meta(model, project, rev, force_type=MlemModel),
)
mlem_model = load_meta(model, project, rev, force_type=MlemModel)
with pass_telemetry_params():
build(
config_arg(
MlemBuilder,
load,
None,
conf=None,
file_conf=None,
),
mlem_model,
)


@for_each_impl(MlemBuilder)
Expand All @@ -70,6 +72,7 @@ def create_build_command(type_name):
hidden=type_name.startswith("_"),
lazy_help=lazy_class_docstring(MlemBuilder.abs_name, type_name),
no_pass_from_parent=["file_conf"],
is_generated_from_ext=True,
)
def build_type(
model: str = option_model,
Expand All @@ -80,14 +83,16 @@ def build_type(
):
from mlem.api.commands import build

pass_api_log_params(build)(
config_arg(
MlemBuilder,
None,
type_name,
conf=None,
file_conf=file_conf,
**__kwargs__
),
load_meta(model, project, rev, force_type=MlemModel),
)
mlem_model = load_meta(model, project, rev, force_type=MlemModel)
with pass_telemetry_params():
build(
config_arg(
MlemBuilder,
None,
type_name,
conf=None,
file_conf=file_conf,
**__kwargs__
),
mlem_model,
)
16 changes: 9 additions & 7 deletions mlem/cli/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
option_rev,
option_target_project,
)
from mlem.telemetry import pass_telemetry_params


@mlem_command("clone", section="object")
Expand All @@ -23,10 +24,11 @@ def clone(
"""
from mlem.api.commands import clone

clone(
uri,
target,
project=project,
rev=rev,
target_project=target_project,
)
with pass_telemetry_params():
clone(
uri,
target,
project=project,
rev=rev,
target_project=target_project,
)
13 changes: 11 additions & 2 deletions mlem/cli/declare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..core.base import MlemABC, build_mlem_object, load_impl_ext
from ..core.meta_io import Location
from ..core.objects import EnvLink, MlemDeployment, MlemObject
from ..telemetry import telemetry
from ..utils.entrypoints import list_abstractions, list_implementations
from .main import app, mlem_command, mlem_group, option_project
from .utils import (
Expand All @@ -32,7 +33,9 @@
def create_declare_mlem_object(type_name, cls: Type[MlemObject]):
if cls.__is_root__:
typer = Typer(
name=type_name, help=cls.__doc__, cls=mlem_group("Mlem Objects")
name=type_name,
help=cls.__doc__,
cls=mlem_group("Mlem Objects", is_generated_from_ext=True),
)
declare.add_typer(typer)

Expand Down Expand Up @@ -112,6 +115,7 @@ def create_declare_mlem_object_subcommand(
dynamic_options_generator=add_fields(subtype, parent_cls),
hidden=subtype.startswith("_"),
lazy_help=lazy_class_docstring(type_name, subtype),
is_generated_from_ext=True,
)
def subtype_command(
path: str = Argument(
Expand All @@ -120,6 +124,8 @@ def subtype_command(
project: str = option_project,
**__kwargs__,
):
telemetry.log_param("object_type", type_name)
telemetry.log_param(f"{type_name}_type", subtype)
__kwargs__ = process_fields(subtype, parent_cls, __kwargs__)
subtype_cls = load_impl_ext(type_name, subtype)
cls = subtype_cls.__type_map__[subtype]
Expand All @@ -145,7 +151,7 @@ def create_declare_mlem_abc(abs_name: str):
help=root_cls.__doc__
if root_cls
else f"Create `{abs_name}` configuration",
cls=mlem_group("Subtypes"),
cls=mlem_group("Subtypes", is_generated_from_ext=True),
)
declare.add_typer(typer)

Expand All @@ -172,12 +178,15 @@ def create_declare_mlem_abc_subcommand(
else None,
hidden=subtype.startswith("_"),
lazy_help=lazy_class_docstring(abs_name, subtype),
is_generated_from_ext=True,
)
def subtype_command(
path: str = Argument(..., help="Where to save object"),
project: str = option_project,
**__kwargs__,
):
telemetry.log_param("object_type", abs_name)
telemetry.log_param(f"{abs_name}_type", subtype)
with wrap_build_error(subtype, root_cls):
obj = build_mlem_object(
root_cls, subtype, str_conf=None, file_conf=[], **__kwargs__
Expand Down
39 changes: 22 additions & 17 deletions mlem/cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
for_each_impl,
lazy_class_docstring,
make_not_required,
pass_api_log_params,
wrap_build_error,
)
from mlem.core.base import build_mlem_object
Expand All @@ -40,6 +39,7 @@
MlemDeployment,
MlemModel,
)
from mlem.telemetry import pass_telemetry_params
from mlem.ui import echo, no_echo, set_echo

deployment = Typer(
Expand Down Expand Up @@ -74,14 +74,16 @@ def deploy_run_callback(
"""
from mlem.api.commands import deploy

pass_api_log_params(deploy)(
load,
load_meta(
model, project=model_project, rev=model_rev, force_type=MlemModel
),
project=project,
rev=rev,
mlem_model = load_meta(
model, project=model_project, rev=model_rev, force_type=MlemModel
)
with pass_telemetry_params():
deploy(
load,
mlem_model,
project=project,
rev=rev,
)


@for_each_impl(MlemDeployment)
Expand All @@ -97,6 +99,7 @@ def create_deploy_run_command(type_name):
hidden=type_name.startswith("_"),
lazy_help=lazy_class_docstring(MlemDeployment.object_type, type_name),
no_pass_from_parent=["file_conf"],
is_generated_from_ext=True,
)
def deploy_run_command(
path: str = Argument(
Expand Down Expand Up @@ -126,16 +129,18 @@ def deploy_run_command(
file_conf=file_conf,
**__kwargs__,
).dump(path, project=project)
pass_api_log_params(deploy)(
meta,
load_meta(
model,
project=model_project,
rev=model_rev,
force_type=MlemModel,
),
project=project,
mlem_model = load_meta(
model,
project=model_project,
rev=model_rev,
force_type=MlemModel,
)
with pass_telemetry_params():
deploy(
meta,
mlem_model,
project=project,
)


@mlem_command("remove", parent=deployment)
Expand Down
21 changes: 11 additions & 10 deletions mlem/cli/import_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
option_rev,
option_target_project,
)
from mlem.cli.utils import pass_api_log_params
from mlem.core.import_objects import ImportHook
from mlem.telemetry import pass_telemetry_params
from mlem.utils.entrypoints import list_implementations


Expand All @@ -29,12 +29,13 @@ def import_object(
"""Create a `.mlem` metafile for a model or data in any file or directory."""
from mlem.api.commands import import_object

pass_api_log_params(import_object)(
uri,
project=project,
rev=rev,
target=target,
target_project=target_project,
copy_data=copy,
type_=type_,
)
with pass_telemetry_params():
import_object(
uri,
project=project,
rev=rev,
target=target,
target_project=target_project,
copy_data=copy,
type_=type_,
)
3 changes: 2 additions & 1 deletion mlem/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mlem.cli.main import mlem_command, option_json, option_project, option_rev
from mlem.core.metadata import load_meta
from mlem.core.objects import MLEM_EXT, MlemLink, MlemObject
from mlem.telemetry import pass_telemetry_params
from mlem.ui import echo, set_echo

OBJECT_TYPE_NAMES = {"data": "Data"}
Expand Down Expand Up @@ -49,7 +50,7 @@ def pretty_print(
"""Display all details about a specific MLEM Object from an existing MLEM
project.
"""
with set_echo(None if json else ...):
with set_echo(None if json else ...), pass_telemetry_params():
meta = load_meta(
path, project, rev, follow_links=follow_links, load_value=False
).dict()
Expand Down
5 changes: 3 additions & 2 deletions mlem/cli/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typer import Argument

from mlem.cli.main import PATH_METAVAR, mlem_command
from mlem.cli.utils import pass_api_log_params
from mlem.telemetry import pass_telemetry_params


@mlem_command("init", section="common")
Expand All @@ -16,4 +16,5 @@ def init(
"""Initialize a MLEM project."""
from mlem.api.commands import init

pass_api_log_params(init)(path)
with pass_telemetry_params():
init(path)
Loading

0 comments on commit de77417

Please sign in to comment.