Skip to content

Commit 4977515

Browse files
committed
WIP: adding GPU data
1 parent 9f8c25f commit 4977515

File tree

4 files changed

+915
-89
lines changed

4 files changed

+915
-89
lines changed

cometx/cli/admin.py

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
To perform admin functions
1616
1717
cometx admin chargeback-report
18-
cometx admin usage-report WORKSPACE/PROJECT
18+
cometx admin usage-report WORKSPACE [WORKSPACE ...]
19+
cometx admin usage-report WORKSPACE/PROJECT [WORKSPACE/PROJECT ...]
1920
2021
"""
2122

@@ -31,41 +32,80 @@
3132
ADDITIONAL_ARGS = False
3233

3334

35+
def add_global_arguments(parser):
36+
"""Add global arguments that are available for all commands."""
37+
parser.add_argument("--api-key", help="Set the COMET_API_KEY", type=str)
38+
parser.add_argument("--url-override", help="Set the COMET_URL_OVERRIDE", type=str)
39+
40+
3441
def get_parser_arguments(parser):
42+
# Add global arguments to the main admin parser so they can appear anywhere in the command line
43+
# (e.g., "cometx admin --api-key KEY usage-report" or "cometx admin usage-report --api-key KEY")
44+
# The top-level parser will consume them first, but having them here ensures they're accepted
45+
# and shown in help if they appear after "admin"
46+
add_global_arguments(parser)
47+
48+
# Add common arguments that apply to all admin subcommands
3549
parser.add_argument(
36-
"ACTION",
37-
help="The admin action to perform (chargeback-report, usage-report)",
50+
"--host",
51+
help="Override the HOST URL",
3852
type=str,
3953
)
4054
parser.add_argument(
55+
"--debug", help="If given, allow debugging", default=False, action="store_true"
56+
)
57+
58+
# Create subparsers for different admin actions
59+
subparsers = parser.add_subparsers(
60+
dest="ACTION",
61+
help="The admin action to perform",
62+
required=True,
63+
)
64+
65+
# chargeback-report subcommand
66+
chargeback_parser = subparsers.add_parser(
67+
"chargeback-report",
68+
help="Generate a chargeback report",
69+
)
70+
# Add global arguments to subparser so they show in help
71+
add_global_arguments(chargeback_parser)
72+
chargeback_parser.add_argument(
4173
"YEAR_MONTH",
4274
nargs="?",
4375
help="(deprecated) The YEAR-MONTH to run report for, eg 2024-09",
4476
metavar="YEAR-MONTH",
4577
type=str,
4678
default=None,
4779
)
48-
parser.add_argument(
49-
"WORKSPACE_PROJECT",
50-
nargs="?",
51-
help="The WORKSPACE/PROJECT to run usage report for (required for usage-report action)",
52-
type=str,
53-
default=None,
80+
81+
# usage-report subcommand
82+
usage_parser = subparsers.add_parser(
83+
"usage-report",
84+
help="Generate a usage report for one or more workspaces/projects",
85+
description="Generate usage reports with experiment counts by month for one or more workspaces/projects.",
5486
)
55-
parser.add_argument(
56-
"--host",
57-
help="Override the HOST URL",
87+
# Add global arguments to subparser so they show in help
88+
add_global_arguments(usage_parser)
89+
usage_parser.add_argument(
90+
"WORKSPACE_PROJECT",
91+
nargs="+",
92+
help="One or more WORKSPACE or WORKSPACE/PROJECT to run usage report for",
93+
metavar="WORKSPACE",
5894
type=str,
5995
)
60-
parser.add_argument(
61-
"--debug", help="If given, allow debugging", default=False, action="store_true"
62-
)
63-
parser.add_argument(
96+
usage_parser.add_argument(
6497
"--no-open",
6598
help="Don't automatically open the generated PDF file",
6699
default=False,
67100
action="store_true",
68101
)
102+
usage_parser.add_argument(
103+
"--max-experiments-per-chart",
104+
help="Maximum number of workspaces/projects per chart (default: 5). If more are provided, multiple charts will be generated.",
105+
type=int,
106+
default=5,
107+
metavar="N",
108+
)
69109

70110

71111
def admin(parsed_args, remaining=None):
@@ -74,7 +114,6 @@ def admin(parsed_args, remaining=None):
74114
api = API()
75115

76116
if parsed_args.ACTION == "chargeback-report":
77-
78117
if parsed_args.host is not None:
79118
admin_url = parsed_args.host
80119
else:
@@ -110,23 +149,20 @@ def admin(parsed_args, remaining=None):
110149
fp.write(json.dumps(response.json()))
111150
print("Chargeback report is saved in %r" % filename)
112151
elif parsed_args.ACTION == "usage-report":
113-
# For usage-report, the workspace/project is passed as YEAR_MONTH argument
114-
workspace_project = parsed_args.YEAR_MONTH or parsed_args.WORKSPACE_PROJECT
115-
if not workspace_project:
116-
print("ERROR: WORKSPACE/PROJECT is required for usage-report action")
117-
print("Usage: cometx admin usage-report WORKSPACE/PROJECT")
118-
return
119-
try:
120-
generate_usage_report(api, workspace_project, parsed_args.no_open)
152+
# WORKSPACE_PROJECT is now required (nargs="+") so we always have at least one
153+
workspace_projects = parsed_args.WORKSPACE_PROJECT
121154

155+
try:
156+
generate_usage_report(
157+
api,
158+
workspace_projects,
159+
no_open=parsed_args.no_open,
160+
max_datasets_per_chart=parsed_args.max_experiments_per_chart,
161+
debug=parsed_args.debug,
162+
)
122163
except Exception as e:
123164
print("ERROR: " + str(e))
124165
return
125-
else:
126-
print(
127-
"Unknown action %r; should be one of these: 'chargeback-report', 'usage-report'"
128-
% parsed_args.ACTION
129-
)
130166

131167
except KeyboardInterrupt:
132168
if parsed_args.debug:

0 commit comments

Comments
 (0)