2021-10-26 10:22:02 +02:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2022-01-07 09:39:00 +01:00
|
|
|
type JobData map[string]map[MetricScope]*JobMetric
|
2021-10-26 10:22:02 +02:00
|
|
|
|
|
|
|
type JobMetric struct {
|
2022-01-07 09:39:00 +01:00
|
|
|
Unit string `json:"unit"`
|
|
|
|
Scope MetricScope `json:"scope"`
|
|
|
|
Timestep int `json:"timestep"`
|
|
|
|
Series []Series `json:"series"`
|
|
|
|
StatisticsSeries *StatsSeries `json:"statisticsSeries"`
|
2021-12-17 15:49:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Series struct {
|
|
|
|
Hostname string `json:"hostname"`
|
|
|
|
Id *int `json:"id,omitempty"`
|
|
|
|
Statistics *MetricStatistics `json:"statistics"`
|
|
|
|
Data []Float `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MetricStatistics struct {
|
|
|
|
Avg float64 `json:"avg"`
|
|
|
|
Min float64 `json:"min"`
|
|
|
|
Max float64 `json:"max"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type StatsSeries struct {
|
2022-01-07 09:39:00 +01:00
|
|
|
Mean []Float `json:"mean"`
|
|
|
|
Min []Float `json:"min"`
|
|
|
|
Max []Float `json:"max"`
|
2021-12-17 15:49:22 +01:00
|
|
|
Percentiles map[int][]Float `json:"percentiles,omitempty"`
|
2021-10-26 10:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type MetricScope string
|
|
|
|
|
|
|
|
const (
|
2022-01-07 09:39:00 +01:00
|
|
|
MetricScopeNode MetricScope = "node"
|
|
|
|
MetricScopeSocket MetricScope = "socket"
|
|
|
|
MetricScopeCpu MetricScope = "cpu"
|
|
|
|
MetricScopeHWThread MetricScope = "hwthread"
|
2022-01-12 13:03:01 +01:00
|
|
|
|
|
|
|
MetricScopeAccelerator MetricScope = "accelerator"
|
2021-10-26 10:22:02 +02:00
|
|
|
)
|
|
|
|
|
2022-01-07 09:39:00 +01:00
|
|
|
var metricScopeGranularity map[MetricScope]int = map[MetricScope]int{
|
2022-01-12 13:03:01 +01:00
|
|
|
MetricScopeNode: 10,
|
|
|
|
MetricScopeSocket: 5,
|
|
|
|
MetricScopeCpu: 2,
|
|
|
|
MetricScopeHWThread: 1,
|
|
|
|
|
|
|
|
MetricScopeAccelerator: 5, // Special/Randomly choosen
|
2022-01-07 09:39:00 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:03:01 +01:00
|
|
|
func (e *MetricScope) LowerThan(other MetricScope) bool {
|
2022-01-07 09:39:00 +01:00
|
|
|
a := metricScopeGranularity[*e]
|
|
|
|
b := metricScopeGranularity[other]
|
2022-01-12 13:03:01 +01:00
|
|
|
return a < b
|
2022-01-07 09:39:00 +01:00
|
|
|
}
|
|
|
|
|
2021-10-26 10:22:02 +02:00
|
|
|
func (e *MetricScope) UnmarshalGQL(v interface{}) error {
|
|
|
|
str, ok := v.(string)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("enums must be strings")
|
|
|
|
}
|
|
|
|
|
|
|
|
*e = MetricScope(str)
|
2022-01-07 09:39:00 +01:00
|
|
|
if _, ok := metricScopeGranularity[*e]; !ok {
|
2021-10-26 10:22:02 +02:00
|
|
|
return fmt.Errorf("%s is not a valid MetricScope", str)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e MetricScope) MarshalGQL(w io.Writer) {
|
|
|
|
fmt.Fprintf(w, "\"%s\"", e)
|
|
|
|
}
|