Skip to content
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ test-e2e: $(PROMTOOL) build pkg/collector/testdata/sys/.unpacked pkg/collector/t
./scripts/e2e-test.sh -s cacct-long-format
./scripts/e2e-test.sh -s cacct-custom-format
./scripts/e2e-test.sh -s cacct-admin-user
./scripts/e2e-test.sh -s cacct-admin-user-all-users
./scripts/e2e-test.sh -s cacct-forbid-query
./scripts/e2e-test.sh -s cacct-invalid-config
./scripts/e2e-test.sh -s cacct-tsdata
Expand Down Expand Up @@ -292,6 +293,7 @@ test-e2e-update: build pkg/collector/testdata/sys/.unpacked pkg/collector/testda
./scripts/e2e-test.sh -s cacct-long-format -u || true
./scripts/e2e-test.sh -s cacct-custom-format -u || true
./scripts/e2e-test.sh -s cacct-admin-user -u || true
./scripts/e2e-test.sh -s cacct-admin-user-all-users -u || true
./scripts/e2e-test.sh -s cacct-forbid-query -u || true
./scripts/e2e-test.sh -s cacct-invalid-config -u || true
./scripts/e2e-test.sh -s cacct-tsdata -u || true
Expand Down
9 changes: 7 additions & 2 deletions cmd/cacct/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ func stats(
var unitsReqURL, usageReqURL string

if len(userNames) > 0 {
for _, user := range userNames {
urlValues.Add("user", user)
// If --user flag does not contain special value "all", add them to the query.
// If "all" is provided in the --user flag, dont add any query parameters so
// that API server returns jobs of all users.
if !slices.Contains(userNames, "all") {
for _, user := range userNames {
urlValues.Add("user", user)
}
}

unitsReqURL = apiURL.JoinPath("/api/v1/units/admin").String()
Expand Down
5 changes: 3 additions & 2 deletions cmd/cacct/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ var (

defaultFields = []string{
"jobid",
"user",
"account",
"elapsed",
"cpuusage",
Expand Down Expand Up @@ -441,7 +442,7 @@ func main() {
"job", "Comma separated list of jobs to display information. Default is all jobs in the period.",
).StringVar(&jobsFlag)
cacctApp.Flag(
"user", "Comma separated list of user names to select jobs to display. By default, the running user is used.",
"user", "Comma separated list of user names to select jobs to display. A special value `all` can be used to fetch jobs of all users when querying user has enough privileges. By default, the running user is used.",
).StringVar(&usersFlag)
cacctApp.Flag(
"format", "Comma separated list of fields (Use --helpformat for list of available fields).",
Expand Down Expand Up @@ -740,7 +741,7 @@ func newTable(currentUser string, users []string, units []models.Unit, usages []
t.AppendSeparator()

for _, usage := range usages {
if usage.User == currentUser || slices.Contains(users, usage.User) {
if usage.User == currentUser || slices.Contains(users, usage.User) || slices.Contains(users, "all") {
// Check if elapsed time in non zero
var totalElapsedTime string
if usage.TotalTime["walltime"] > 0 {
Expand Down
27 changes: 27 additions & 0 deletions cmd/cacct/testdata/output/e2e-test-cacct-admin-user-all-users.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
┌─────────┬─────────┬───────┬──────────┬────────┬────────┬──────────┬─────────────────────────┬────────┬────────┬──────────┬─────────────────────────┐
│ JOB ID │ ACCOUNT │ USER │ ELAPSED │ CPU US │ CPU ME │ HOST ENE │ HOST EMISSIO │ GPU US │ GPU ME │ GPU ENER │ GPU EMISSION │
│ │ │ │ │ AGE(%) │ M. USA │ RGY(KWH) │ NS(GMS) │ AGE(%) │ M. USA │ GY(KWH) │ S(GMS) │
│ │ │ │ │ │ GE(%) │ │ │ │ GE(%) │ │ │
│ │ │ │ │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │
├─────────┼─────────┼───────┼──────────┼────────┼────────┼──────────┼─────────────┼───────────┼────────┼────────┼──────────┼─────────────┼───────────┤
│ 1009248 │ testacc │ testu │ 00:00:17 │ 21.23 │ 21.23 │ 21.23464 │ 21.234647 │ 21.234647 │ 21.23 │ 21.23 │ 21.23464 │ 21.234647 │ 21.234647 │
│ │ │ sr │ │ │ │ 7 │ │ │ │ │ 7 │ │ │
│ 11508 │ acc1 │ usr15 │ 00:08:17 │ 17.80 │ 17.80 │ 17.79969 │ 17.799693 │ 17.799693 │ 17.80 │ 17.80 │ 17.79969 │ 17.799693 │ 17.799693 │
│ │ │ │ │ │ │ 3 │ │ │ │ │ 3 │ │ │
│ 14508 │ acc4 │ usr4 │ 00:08:17 │ 14.03 │ 14.03 │ 14.03205 │ 14.032058 │ 14.032058 │ 14.03 │ 14.03 │ 14.03205 │ 14.032058 │ 14.032058 │
│ │ │ │ │ │ │ 8 │ │ │ │ │ 8 │ │ │
│ 147975 │ acc3 │ usr3 │ 00:49:22 │ 29.72 │ 29.72 │ 29.72084 │ 29.720843 │ 29.720843 │ 29.72 │ 29.72 │ 29.72084 │ 29.720843 │ 29.720843 │
│ │ │ │ │ │ │ 3 │ │ │ │ │ 3 │ │ │
│ 1479763 │ acc1 │ usr1 │ 00:49:22 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │
│ │ │ │ │ │ │ 4 │ │ │ │ │ 4 │ │ │
│ 1479765 │ acc1 │ usr8 │ 00:49:22 │ 20.21 │ 20.21 │ 20.21483 │ 20.214837 │ 20.214837 │ 20.21 │ 20.21 │ 20.21483 │ 20.214837 │ 20.214837 │
│ │ │ │ │ │ │ 7 │ │ │ │ │ 7 │ │ │
│ 1481508 │ acc2 │ usr2 │ 00:08:17 │ 53.48 │ 53.48 │ 53.47701 │ 53.477015 │ 53.477015 │ 53.48 │ 53.48 │ 53.47701 │ 53.477015 │ 53.477015 │
│ │ │ │ │ │ │ 5 │ │ │ │ │ 5 │ │ │
│ 1481510 │ acc3 │ usr3 │ 00:00:17 │ 50.14 │ 50.14 │ 50.13620 │ 50.136201 │ 50.136201 │ 50.14 │ 50.14 │ 50.13620 │ 50.136201 │ 50.136201 │
│ │ │ │ │ │ │ 1 │ │ │ │ │ 1 │ │ │
│ 81510 │ acc1 │ usr15 │ 00:00:17 │ 18.57 │ 18.57 │ 18.57046 │ 18.570466 │ 18.570466 │ 18.57 │ 18.57 │ 18.57046 │ 18.570466 │ 18.570466 │
│ │ │ │ │ │ │ 6 │ │ │ │ │ 6 │ │ │
├─────────┼─────────┴───────┴──────────┴────────┴────────┴──────────┴─────────────┴───────────┴────────┴────────┴──────────┴─────────────┴───────────┤
│ Summary │ │
└─────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
24 changes: 12 additions & 12 deletions cmd/cacct/testdata/output/e2e-test-cacct-admin-user.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
┌─────────┬─────────┬──────────┬────────┬────────┬──────────┬─────────────────────────┬────────┬────────┬──────────┬─────────────────────────┐
│ JOB ID │ ACCOUNT │ ELAPSED │ CPU US │ CPU ME │ HOST ENE │ HOST EMISSIO │ GPU US │ GPU ME │ GPU ENER │ GPU EMISSION │
│ │ │ │ AGE(%) │ M. USA │ RGY(KWH) │ NS(GMS) │ AGE(%) │ M. USA │ GY(KWH) │ S(GMS) │
│ │ │ │ │ GE(%) │ │ │ │ GE(%) │ │ │
├─────────┼─────────┼──────────┼────────┼────────┼──────────┼─────────────┬───────────┼────────┼────────┼──────────┼─────────────┬───────────┤
│ │ │ │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │
├─────────┼─────────┼──────────┼────────┼────────┼──────────┼─────────────┼───────────┼────────┼────────┼──────────┼─────────────┼───────────┤
│ 1479763 │ acc1 │ 00:49:22 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │
│ │ │ │ │ │ 4 │ │ │ │ │ 4 │ │ │
├─────────┼─────────┴──────────┴────────┴────────┴──────────┴─────────────┴───────────┴────────┴────────┴──────────┴─────────────┴───────────┤
│ Summary │ │
└─────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────┬─────────┬───────┬──────────┬────────┬────────┬──────────┬─────────────────────────┬────────┬────────┬──────────┬─────────────────────────┐
│ JOB ID │ ACCOUNT │ USER │ ELAPSED │ CPU US │ CPU ME │ HOST ENE │ HOST EMISSIO │ GPU US │ GPU ME │ GPU ENER │ GPU EMISSION │
│ │ │ │ AGE(%) │ M. USA │ RGY(KWH) │ NS(GMS) │ AGE(%) │ M. USA │ GY(KWH) │ S(GMS) │
│ │ │ │ │ GE(%) │ │ │ │ GE(%) │ │ │
├─────────┼─────────┼───────┼──────────┼────────┼────────┼──────────┼─────────────┬───────────┼────────┼────────┼──────────┼─────────────┬───────────┤
│ │ │ │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │ │ │ │ EMAPS_TOTAL │ RTE_TOTAL │
├─────────┼─────────┼───────┼──────────┼────────┼────────┼──────────┼─────────────┼───────────┼────────┼────────┼──────────┼─────────────┼───────────┤
│ 1479763 │ acc1 │ usr1 │ 00:49:22 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │ 21.22 │ 21.22 │ 21.22149 │ 21.221494 │ 21.221494 │
│ │ │ │ │ │ 4 │ │ │ │ │ 4 │ │ │
├─────────┼─────────┴───────┴──────────┴────────┴────────┴──────────┴─────────────┴───────────┴────────┴────────┴──────────┴─────────────┴───────────┤
│ Summary │
└─────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Loading