Make jobAvailableMetricsById more flexible

There are more different metrics than I thought. With this
change, the query mentioned above does not care about the
name of the Metric or whether it is part of the JobData type.
This commit is contained in:
Lou Knauer 2021-04-07 14:46:02 +02:00
parent a52445086b
commit b7186cb1cd

View File

@ -87,6 +87,24 @@ func buildQueryConditions(filterList *model.JobFilterList) string {
return strings.Join(conditions, " AND ")
}
func readJobDataFile(jobId string) ([]byte, error) {
// TODO: What to do with the suffix?
jobId = strings.Split(jobId, ".")[0]
id, err := strconv.Atoi(jobId)
if err != nil {
return nil, err
}
lvl1, lvl2 := id / 1000, id % 1000
filepath := fmt.Sprintf("./job-data/%d/%03d/data.json", lvl1, lvl2)
f, err := os.ReadFile(filepath)
if err != nil {
return nil, err
}
return f, nil
}
// Queries
func (r *queryResolver) JobByID(
@ -249,16 +267,7 @@ func (r *queryResolver) JobsStatistics(
func (r *queryResolver) JobDataByID(
ctx context.Context, jobId string) (*model.JobData, error) {
// TODO: What to do with the suffix?
jobId = strings.Split(jobId, ".")[0]
id, err := strconv.Atoi(jobId)
if err != nil {
return nil, err
}
lvl1, lvl2 := id / 1000, id % 1000
filepath := fmt.Sprintf("./job-data/%d/%03d/data.json", lvl1, lvl2)
f, err := os.ReadFile(filepath)
f, err := readJobDataFile(jobId)
if err != nil {
return nil, err
}
@ -275,94 +284,26 @@ func (r *queryResolver) JobDataByID(
func (r *queryResolver) JobAvailableMetricsByID(
ctx context.Context, jobId string) ([]*model.JobMetricWithName, error) {
jobData, err := r.JobDataByID(ctx, jobId)
f, err := readJobDataFile(jobId)
if err != nil {
return nil, err
}
var list []*model.JobMetricWithName
/*
* GraphQL has no Map-Type, so
* this is the best i could come up with.
* This is only for testing anyways?
*/
var list []*model.JobMetricWithName
var metricMap map[string]*model.JobMetric
if jobData.LoadOne != nil {
list = append(list, &model.JobMetricWithName {
"load_one", jobData.LoadOne })
err = json.Unmarshal(f, &metricMap)
if err != nil {
return nil, err
}
if jobData.MemUsed != nil {
list = append(list, &model.JobMetricWithName {
"mem_used", jobData.MemUsed })
}
if jobData.MemBw != nil {
list = append(list, &model.JobMetricWithName {
"mem_bw", jobData.MemBw })
}
if jobData.FlopsAny != nil {
list = append(list, &model.JobMetricWithName {
"flops_any", jobData.FlopsAny })
}
if jobData.FlopsDp != nil {
list = append(list, &model.JobMetricWithName {
"flops_dp", jobData.FlopsDp })
}
if jobData.FlopsSp != nil {
list = append(list, &model.JobMetricWithName {
"flops_sp", jobData.FlopsSp })
}
if jobData.CpiAvg != nil {
list = append(list, &model.JobMetricWithName {
"cpi_avg", jobData.CpiAvg })
}
if jobData.ClockSpeed != nil {
list = append(list, &model.JobMetricWithName {
"clock_speed", jobData.ClockSpeed })
}
if jobData.TotalPower != nil {
list = append(list, &model.JobMetricWithName {
"total_power", jobData.TotalPower })
}
if jobData.TrafficReadEth != nil {
list = append(list, &model.JobMetricWithName {
"traffic_read_eth", jobData.TrafficReadEth })
}
if jobData.TrafficWriteEth != nil {
list = append(list, &model.JobMetricWithName {
"traffic_write_eth", jobData.TrafficWriteEth })
}
if jobData.TrafficReadLustre != nil {
list = append(list, &model.JobMetricWithName {
"traffic_read_lustre", jobData.TrafficReadLustre })
}
if jobData.TrafficWriteLustre != nil {
list = append(list, &model.JobMetricWithName {
"traffic_write_lustre", jobData.TrafficWriteLustre })
}
if jobData.RegReadLustre != nil {
list = append(list, &model.JobMetricWithName {
"reg_read_lustre", jobData.RegReadLustre })
}
if jobData.RegWriteLustre != nil {
list = append(list, &model.JobMetricWithName {
"reg_write_lustre", jobData.RegWriteLustre })
}
if jobData.InodesLustre != nil {
list = append(list, &model.JobMetricWithName {
"inodes_lustre", jobData.InodesLustre })
}
if jobData.PkgRateReadIb != nil {
list = append(list, &model.JobMetricWithName {
"pkg_rate_read_ib", jobData.PkgRateReadIb })
}
if jobData.PkgRateWriteIb != nil {
list = append(list, &model.JobMetricWithName {
"pkg_rate_write_ib", jobData.PkgRateWriteIb })
}
if jobData.CongestionIb != nil {
list = append(list, &model.JobMetricWithName {
"congestion_ib", jobData.CongestionIb })
for name, metric := range metricMap {
list = append(list, &model.JobMetricWithName{ name, metric })
}
return list, nil