mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 12:51:40 +02:00
slight change to job structure
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Common subset of Job and JobMeta. Use one of those, not
|
||||
// this type directly.
|
||||
type BaseJob struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
JobID int64 `json:"jobId" db:"job_id"`
|
||||
@@ -25,23 +27,32 @@ type BaseJob struct {
|
||||
State JobState `json:"jobState" db:"job_state"`
|
||||
Duration int32 `json:"duration" db:"duration"`
|
||||
Tags []*Tag `json:"tags"`
|
||||
RawResources []byte `json:"-" db:"resources"`
|
||||
Resources []Resource `json:"resources"`
|
||||
Resources []*Resource `json:"resources"`
|
||||
MetaData interface{} `json:"metaData" db:"meta_data"`
|
||||
|
||||
MemUsedMax float64 `json:"-" db:"mem_used_max"`
|
||||
FlopsAnyAvg float64 `json:"-" db:"flops_any_avg"`
|
||||
MemBwAvg float64 `json:"-" db:"mem_bw_avg"`
|
||||
LoadAvg float64 `json:"-" db:"load_avg"`
|
||||
NetBwAvg float64 `json:"-" db:"net_bw_avg"`
|
||||
NetDataVolTotal float64 `json:"-" db:"net_data_vol_total"`
|
||||
FileBwAvg float64 `json:"-" db:"file_bw_avg"`
|
||||
FileDataVolTotal float64 `json:"-" db:"file_data_vol_total"`
|
||||
}
|
||||
|
||||
// This type is used as the GraphQL interface and using sqlx as a table row.
|
||||
type Job struct {
|
||||
BaseJob
|
||||
RawResources []byte `json:"-" db:"resources"`
|
||||
StartTime time.Time `json:"startTime" db:"start_time"`
|
||||
MemUsedMax float64 `json:"-" db:"mem_used_max"`
|
||||
FlopsAnyAvg float64 `json:"-" db:"flops_any_avg"`
|
||||
MemBwAvg float64 `json:"-" db:"mem_bw_avg"`
|
||||
LoadAvg float64 `json:"-" db:"load_avg"`
|
||||
NetBwAvg float64 `json:"-" db:"net_bw_avg"`
|
||||
NetDataVolTotal float64 `json:"-" db:"net_data_vol_total"`
|
||||
FileBwAvg float64 `json:"-" db:"file_bw_avg"`
|
||||
FileDataVolTotal float64 `json:"-" db:"file_data_vol_total"`
|
||||
}
|
||||
|
||||
// When reading from the database or sending data via GraphQL, the start time can be in the much more
|
||||
// convenient time.Time type. In the `meta.json` files, the start time is encoded as a unix epoch timestamp.
|
||||
// This is why there is this struct, which contains all fields from the regular job struct, but "overwrites"
|
||||
// the StartTime field with one of type int64.
|
||||
type JobMeta struct {
|
||||
BaseJob
|
||||
StartTime int64 `json:"startTime" db:"start_time"`
|
||||
StartTime int64 `json:"startTime"`
|
||||
Statistics map[string]JobStatistics `json:"statistics,omitempty"`
|
||||
}
|
||||
|
||||
@@ -52,9 +63,9 @@ var JobDefaults BaseJob = BaseJob{
|
||||
}
|
||||
|
||||
var JobColumns []string = []string{
|
||||
"id", "job_id", "user", "project", "cluster", "partition", "array_job_id", "num_nodes",
|
||||
"num_hwthreads", "num_acc", "exclusive", "monitoring_status", "smt", "job_state",
|
||||
"duration", "resources", "meta_data",
|
||||
"job.id", "job.job_id", "job.user", "job.project", "job.cluster", "job.start_time", "job.partition", "job.array_job_id", "job.num_nodes",
|
||||
"job.num_hwthreads", "job.num_acc", "job.exclusive", "job.monitoring_status", "job.smt", "job.job_state",
|
||||
"job.duration", "job.resources", "job.meta_data",
|
||||
}
|
||||
|
||||
const JobInsertStmt string = `INSERT INTO job (
|
||||
@@ -67,11 +78,6 @@ const JobInsertStmt string = `INSERT INTO job (
|
||||
:mem_used_max, :flops_any_avg, :mem_bw_avg, :load_avg, :net_bw_avg, :net_data_vol_total, :file_bw_avg, :file_data_vol_total
|
||||
);`
|
||||
|
||||
type Job struct {
|
||||
BaseJob
|
||||
StartTime time.Time `json:"startTime" db:"start_time"`
|
||||
}
|
||||
|
||||
type Scannable interface {
|
||||
StructScan(dest interface{}) error
|
||||
}
|
||||
|
@@ -5,14 +5,14 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
type JobData map[string]map[string]*JobMetric
|
||||
type JobData map[string]map[MetricScope]*JobMetric
|
||||
|
||||
type JobMetric struct {
|
||||
Unit string `json:"unit"`
|
||||
Scope MetricScope `json:"scope"`
|
||||
Timestep int `json:"timestep"`
|
||||
Series []Series `json:"series"`
|
||||
StatsSeries *StatsSeries `json:"statisticsSeries,omitempty"`
|
||||
Unit string `json:"unit"`
|
||||
Scope MetricScope `json:"scope"`
|
||||
Timestep int `json:"timestep"`
|
||||
Series []Series `json:"series"`
|
||||
StatisticsSeries *StatsSeries `json:"statisticsSeries"`
|
||||
}
|
||||
|
||||
type Series struct {
|
||||
@@ -29,20 +29,37 @@ type MetricStatistics struct {
|
||||
}
|
||||
|
||||
type StatsSeries struct {
|
||||
Mean []Float `json:"mean,omitempty"`
|
||||
Min []Float `json:"min,omitempty"`
|
||||
Max []Float `json:"max,omitempty"`
|
||||
Mean []Float `json:"mean"`
|
||||
Min []Float `json:"min"`
|
||||
Max []Float `json:"max"`
|
||||
Percentiles map[int][]Float `json:"percentiles,omitempty"`
|
||||
}
|
||||
|
||||
type MetricScope string
|
||||
|
||||
const (
|
||||
MetricScopeNode MetricScope = "node"
|
||||
MetricScopeSocket MetricScope = "socket"
|
||||
MetricScopeCpu MetricScope = "cpu"
|
||||
MetricScopeNode MetricScope = "node"
|
||||
MetricScopeSocket MetricScope = "socket"
|
||||
MetricScopeCpu MetricScope = "cpu"
|
||||
MetricScopeHWThread MetricScope = "hwthread"
|
||||
)
|
||||
|
||||
var metricScopeGranularity map[MetricScope]int = map[MetricScope]int{
|
||||
MetricScopeNode: 1,
|
||||
MetricScopeSocket: 2,
|
||||
MetricScopeCpu: 3,
|
||||
MetricScopeHWThread: 4,
|
||||
}
|
||||
|
||||
func (e *MetricScope) MaxGranularity(other MetricScope) MetricScope {
|
||||
a := metricScopeGranularity[*e]
|
||||
b := metricScopeGranularity[other]
|
||||
if a < b {
|
||||
return *e
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func (e *MetricScope) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
@@ -50,7 +67,7 @@ func (e *MetricScope) UnmarshalGQL(v interface{}) error {
|
||||
}
|
||||
|
||||
*e = MetricScope(str)
|
||||
if *e != "node" && *e != "socket" && *e != "cpu" {
|
||||
if _, ok := metricScopeGranularity[*e]; !ok {
|
||||
return fmt.Errorf("%s is not a valid MetricScope", str)
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user