Skip to content

Commit

Permalink
feat: add select to status view pie charts
Browse files Browse the repository at this point in the history
- 'Jobs' as generic default value for top lists
- Prepare histograms for cores and accs in schema
  • Loading branch information
spacehamster87 committed Aug 29, 2023
1 parent 69519ec commit f933cad
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 53 deletions.
4 changes: 3 additions & 1 deletion api/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ type TimeWeights {
}

enum Aggregate { USER, PROJECT, CLUSTER }
enum SortByAggregate { WALLTIME, TOTALNODES, NODEHOURS, TOTALCORES, COREHOURS, TOTALACCS, ACCHOURS }
enum SortByAggregate { WALLTIME, TOTALJOBS, TOTALNODES, NODEHOURS, TOTALCORES, COREHOURS, TOTALACCS, ACCHOURS }

type NodeMetrics {
host: String!
Expand Down Expand Up @@ -301,6 +301,8 @@ type JobsStatistics {
totalAccHours: Int! # Sum of the gpu hours of all matched jobs
histDuration: [HistoPoint!]! # value: hour, count: number of jobs with a rounded duration of value
histNumNodes: [HistoPoint!]! # value: number of nodes, count: number of jobs with that number of nodes
histNumCores: [HistoPoint!]! # value: number of cores, count: number of jobs with that number of cores
histNumAccs: [HistoPoint!]! # value: number of accs, count: number of jobs with that number of accs
}

input PageRequest {
Expand Down
134 changes: 133 additions & 1 deletion internal/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion internal/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions internal/repository/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var groupBy2column = map[model.Aggregate]string{
}

var sortBy2column = map[model.SortByAggregate]string{
model.SortByAggregateTotaljobs: "totalJobs",
model.SortByAggregateWalltime: "totalWalltime",
model.SortByAggregateTotalnodes: "totalNodes",
model.SortByAggregateNodehours: "totalNodeHours",
Expand Down Expand Up @@ -71,7 +72,7 @@ func (r *JobRepository) buildStatsQuery(

if col != "" {
// Scan columns: id, totalJobs, totalWalltime, totalNodes, totalNodeHours, totalCores, totalCoreHours, totalAccs, totalAccHours
query = sq.Select(col, "COUNT(job.id)",
query = sq.Select(col, "COUNT(job.id) as totalJobs",
fmt.Sprintf("CAST(ROUND(SUM(job.duration) / 3600) as %s) as totalWalltime", castType),
fmt.Sprintf("CAST(SUM(job.num_nodes) as %s) as totalNodes", castType),
fmt.Sprintf("CAST(ROUND(SUM(job.duration * job.num_nodes) / 3600) as %s) as totalNodeHours", castType),
Expand Down Expand Up @@ -168,15 +169,25 @@ func (r *JobRepository) JobsStatsGrouped(
}

if id.Valid {
var totalCores, totalCoreHours, totalAccs, totalAccHours int
var totalJobs, totalNodes, totalNodeHours, totalCores, totalCoreHours, totalAccs, totalAccHours int

if jobs.Valid {
totalJobs = int(jobs.Int64)
}

if nodes.Valid {
totalNodes = int(nodes.Int64)
}
if cores.Valid {
totalCores = int(cores.Int64)
}
if accs.Valid {
totalAccs = int(accs.Int64)
}

if nodeHours.Valid {
totalNodeHours = int(nodeHours.Int64)
}
if coreHours.Valid {
totalCoreHours = int(coreHours.Int64)
}
Expand All @@ -190,8 +201,10 @@ func (r *JobRepository) JobsStatsGrouped(
&model.JobsStatistics{
ID: id.String,
Name: name,
TotalJobs: int(jobs.Int64),
TotalJobs: totalJobs,
TotalWalltime: int(walltime.Int64),
TotalNodes: totalNodes,
TotalNodeHours: totalNodeHours,
TotalCores: totalCores,
TotalCoreHours: totalCoreHours,
TotalAccs: totalAccs,
Expand All @@ -202,6 +215,8 @@ func (r *JobRepository) JobsStatsGrouped(
ID: id.String,
TotalJobs: int(jobs.Int64),
TotalWalltime: int(walltime.Int64),
TotalNodes: totalNodes,
TotalNodeHours: totalNodeHours,
TotalCores: totalCores,
TotalCoreHours: totalCoreHours,
TotalAccs: totalAccs,
Expand All @@ -228,16 +243,11 @@ func (r *JobRepository) jobsStats(
}

if jobs.Valid {
var totalCoreHours, totalAccHours int
// var totalCores, totalAccs int

// if cores.Valid {
// totalCores = int(cores.Int64)
// }
// if accs.Valid {
// totalAccs = int(accs.Int64)
// }
var totalNodeHours, totalCoreHours, totalAccHours int

if nodeHours.Valid {
totalNodeHours = int(nodeHours.Int64)
}
if coreHours.Valid {
totalCoreHours = int(coreHours.Int64)
}
Expand All @@ -248,6 +258,7 @@ func (r *JobRepository) jobsStats(
&model.JobsStatistics{
TotalJobs: int(jobs.Int64),
TotalWalltime: int(walltime.Int64),
TotalNodeHours: totalNodeHours,
TotalCoreHours: totalCoreHours,
TotalAccHours: totalAccHours})
}
Expand Down
Loading

0 comments on commit f933cad

Please sign in to comment.