Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job tags support #1393

Merged
merged 5 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.D/1393.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support job tags: `neuro run --tag=experiment-1`, `neuro ps --tag=experiment-1`.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ Name | Description|
|_--http PORT_|Enable HTTP port forwarding to container \[default: 80]|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_\-n, --name NAME_|Optional job name|
|_--tag TAG_|Optional job tag, multiple values allowed|
|_\-d, --description DESC_|Optional job description in free format|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-v, --volume MOUNT_|Mounts directory from vault into container. Use multiple options to mount more than one volume. --volume=HOME is an alias for storage::/var/storage/home:rw and storage://neuromation/public:/var/storage/neuromation:ro|
Expand Down Expand Up @@ -480,6 +481,7 @@ Name | Description|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_\-p, --preemptible / -P, --non-preemptible_|Run job on a lower-cost preemptible instance \[default: False]|
|_\-n, --name NAME_|Optional job name|
|_--tag TAG_|Optional job tag, multiple values allowed|
|_\-d, --description DESC_|Optional job description in free format|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-v, --volume MOUNT_|Mounts directory from vault into container. Use multiple options to mount more than one volume. --volume=HOME is an alias for storage::/var/storage/home:rw and storage://neuromation/public:/var/storage/neuromation:ro|
Expand Down Expand Up @@ -516,6 +518,7 @@ neuro ps -a --owner=user-1 --owner=user-2
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description=my favourite job
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2

```

Expand All @@ -527,6 +530,7 @@ Name | Description|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option).|
|_\-a, --all_|Show all jobs regardless the status \(equivalent to `\-s pending -s running -s succeeded -s failed`).|
|_\-n, --name NAME_|Filter out jobs by name.|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_\-d, --description DESCRIPTION_|Filter out jobs by description \(exact match).|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-w, --wide_|Do not cut long lines for terminal width.|
Expand Down Expand Up @@ -1669,6 +1673,7 @@ Name | Description|
|_--http PORT_|Enable HTTP port forwarding to container \[default: 80]|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_\-n, --name NAME_|Optional job name|
|_--tag TAG_|Optional job tag, multiple values allowed|
|_\-d, --description DESC_|Optional job description in free format|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-v, --volume MOUNT_|Mounts directory from vault into container. Use multiple options to mount more than one volume. --volume=HOME is an alias for storage::/var/storage/home:rw and storage://neuromation/public:/var/storage/neuromation:ro|
Expand Down Expand Up @@ -1726,6 +1731,7 @@ Name | Description|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_\-p, --preemptible / -P, --non-preemptible_|Run job on a lower-cost preemptible instance \[default: False]|
|_\-n, --name NAME_|Optional job name|
|_--tag TAG_|Optional job tag, multiple values allowed|
|_\-d, --description DESC_|Optional job description in free format|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-v, --volume MOUNT_|Mounts directory from vault into container. Use multiple options to mount more than one volume. --volume=HOME is an alias for storage::/var/storage/home:rw and storage://neuromation/public:/var/storage/neuromation:ro|
Expand Down Expand Up @@ -1762,6 +1768,7 @@ neuro ps -a --owner=user-1 --owner=user-2
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description=my favourite job
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2

```

Expand All @@ -1773,6 +1780,7 @@ Name | Description|
|_\-o, --owner TEXT_|Filter out jobs by owner \(multiple option).|
|_\-a, --all_|Show all jobs regardless the status \(equivalent to `\-s pending -s running -s succeeded -s failed`).|
|_\-n, --name NAME_|Filter out jobs by name.|
|_\-t, --tag TAG_|Filter out jobs by tag \(multiple option)|
|_\-d, --description DESCRIPTION_|Filter out jobs by description \(exact match).|
|_\-q, --quiet_|Run command in quiet mode \(DEPRECATED)|
|_\-w, --wide_|Do not cut long lines for terminal width.|
Expand Down
14 changes: 14 additions & 0 deletions docs/jobs_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Jobs

.. comethod:: list(*, statuses: Iterable[JobStatus] = (), \
name: str = "" \
tags: Sequence[str] = (), \
owners: Iterable[str] = (),
) -> List[JobDescription]

Expand All @@ -69,6 +70,11 @@ Jobs

Empty string means that no filter is applied (default).

:param str name: Filter jobs by :attr:`~JobDescription.tags`. Retrieves all
jobs submitted with at least one tag from the specified list.

Empty list means that no filter is applied (default).

:param ~typing.Iterable[str] owners: filter jobs by their owners.

The parameter can be a set or list of owner
Expand Down Expand Up @@ -113,6 +119,7 @@ Jobs
.. comethod:: run(container: Container, \
*, \
name: Optional[str] = None, \
tags: Sequence[str] = (), \
description: Optional[str] = None, \
is_preemptible: bool = False, \
schedule_timeout: Optional[float] = None, \
Expand All @@ -125,6 +132,8 @@ Jobs

:param str name: optional container name.

:param str name: optional job tags.

:param str desciption: optional container description.

:param bool is_preemtible: a flag that specifies is the job is *preemptible* or
Expand Down Expand Up @@ -269,6 +278,11 @@ JobDescription
Job name provided by user at creation time, :class:`str` or ``None`` if name is
omitted.

.. attribute:: tags

List of job tags provided by user at creation time, :class:`Sequence[str]` or
``()`` if tags omitted.

.. attribute:: description

Job description text provided by user at creation time, :class:`str` or ``None``
Expand Down
9 changes: 9 additions & 0 deletions neuromation/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class JobDescription:
container: Container
is_preemptible: bool
name: Optional[str] = None
tags: Sequence[str] = ()
description: Optional[str] = None
http_url: URL = URL()
ssh_server: URL = URL()
Expand All @@ -135,6 +136,7 @@ async def run(
container: Container,
*,
name: Optional[str] = None,
tags: Sequence[str] = (),
description: Optional[str] = None,
is_preemptible: bool = False,
schedule_timeout: Optional[float] = None,
Expand All @@ -147,6 +149,8 @@ async def run(
}
if name:
payload["name"] = name
if tags:
payload["tags"] = tags
if description:
payload["description"] = description
if schedule_timeout:
Expand All @@ -164,6 +168,7 @@ async def list(
*,
statuses: Iterable[JobStatus] = (),
name: str = "",
tags: Iterable[str] = (),
owners: Iterable[str] = (),
) -> List[JobDescription]:
url = self._config.api_url / "jobs"
Expand All @@ -174,6 +179,8 @@ async def list(
params.add("name", name)
for owner in owners:
params.add("owner", owner)
for tag in tags:
params.add("tag", tag)
params["cluster_name"] = self._config.cluster_name
auth = await self._config._api_auth()
async with self._core.request("GET", url, params=params, auth=auth) as resp:
Expand Down Expand Up @@ -513,6 +520,7 @@ def _job_description_from_api(res: Dict[str, Any], parse: Parser) -> JobDescript
owner = res["owner"]
cluster_name = res["cluster_name"]
name = res.get("name")
tags = res.get("tags", ())
description = res.get("description")
history = JobStatusHistory(
status=JobStatus(res["history"].get("status", "unknown")),
Expand All @@ -536,6 +544,7 @@ def _job_description_from_api(res: Dict[str, Any], parse: Parser) -> JobDescript
container=container,
is_preemptible=res["is_preemptible"],
name=name,
tags=tags,
description=description,
http_url=http_url_named or http_url,
ssh_server=ssh_server,
Expand Down
35 changes: 34 additions & 1 deletion neuromation/cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ def job() -> None:
default=None,
secure=True,
)
@option(
"--tag",
metavar="TAG",
type=str,
help="Optional job tag, multiple values allowed",
multiple=True,
)
@option(
"-d",
"--description",
Expand Down Expand Up @@ -298,6 +305,7 @@ async def submit(
life_span: Optional[str],
preemptible: bool,
name: Optional[str],
tag: Sequence[str],
description: Optional[str],
wait_start: bool,
pass_config: bool,
Expand Down Expand Up @@ -344,6 +352,7 @@ async def submit(
life_span=life_span,
preemptible=preemptible,
name=name,
tags=tag,
description=description,
wait_start=wait_start,
pass_config=pass_config,
Expand Down Expand Up @@ -516,6 +525,14 @@ async def _print_logs(root: Root, job: str) -> None:
),
)
@option("-n", "--name", metavar="NAME", help="Filter out jobs by name.", secure=True)
@option(
"-t",
"--tag",
metavar="TAG",
type=str,
help="Filter out jobs by tag (multiple option)",
multiple=True,
)
@option(
"-d",
"--description",
Expand All @@ -542,6 +559,7 @@ async def ls(
status: Sequence[str],
all: bool,
name: str,
tag: Sequence[str],
owner: Sequence[str],
description: str,
wide: bool,
Expand All @@ -557,13 +575,17 @@ async def ls(
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description="my favourite job"
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the only short or long version in the example (doesn't matter what form will you choose).
I believe it is less confusing, people can learn an alternative by neuro help ps easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will consider in the following-up PR.

"""

format = await calc_columns(root.client, format)

statuses = calc_statuses(status, all)
owners = set(owner)
jobs = await root.client.jobs.list(statuses=statuses, name=name, owners=owners)
tags = set(tag)
jobs = await root.client.jobs.list(
statuses=statuses, name=name, owners=owners, tags=tags
)

# client-side filtering
if description:
Expand Down Expand Up @@ -750,6 +772,13 @@ def format_fail(job: str, reason: Exception) -> str:
default=None,
secure=True,
)
@option(
"--tag",
metavar="TAG",
type=str,
help="Optional job tag, multiple values allowed",
multiple=True,
)
@option(
"-d",
"--description",
Expand Down Expand Up @@ -843,6 +872,7 @@ async def run(
life_span: Optional[str],
preemptible: Optional[bool],
name: Optional[str],
tag: Sequence[str],
description: Optional[str],
wait_start: bool,
pass_config: bool,
Expand Down Expand Up @@ -897,6 +927,7 @@ async def run(
life_span=life_span,
preemptible=job_preset.is_preemptible,
name=name,
tags=tag,
description=description,
wait_start=wait_start,
pass_config=pass_config,
Expand Down Expand Up @@ -944,6 +975,7 @@ async def run_job(
life_span: Optional[str],
preemptible: bool,
name: Optional[str],
tags: Sequence[str],
description: Optional[str],
wait_start: bool,
pass_config: bool,
Expand Down Expand Up @@ -1021,6 +1053,7 @@ async def run_job(
container,
is_preemptible=preemptible,
name=name,
tags=tags,
description=description,
life_span=job_life_span,
)
Expand Down
Loading