mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
More URL filter presets; Some tweaks
This commit is contained in:
parent
8ebf00d980
commit
92349708ae
@ -162,9 +162,9 @@ func ArchiveJob(job *schema.Job, ctx context.Context) (*schema.JobMeta, error) {
|
|||||||
allMetrics = append(allMetrics, mc.Name)
|
allMetrics = append(allMetrics, mc.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: For now: Only single-node-jobs get archived in full resolution
|
// TODO: Talk about this! What resolutions to store data at...
|
||||||
scopes := []schema.MetricScope{schema.MetricScopeNode}
|
scopes := []schema.MetricScope{schema.MetricScopeNode}
|
||||||
if job.NumNodes == 1 {
|
if job.NumNodes <= 8 {
|
||||||
scopes = append(scopes, schema.MetricScopeCore)
|
scopes = append(scopes, schema.MetricScopeCore)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ var cache *lrucache.Cache = lrucache.New(512 * 1024 * 1024)
|
|||||||
|
|
||||||
// Fetches the metric data for a job.
|
// Fetches the metric data for a job.
|
||||||
func LoadData(job *schema.Job, metrics []string, scopes []schema.MetricScope, ctx context.Context) (schema.JobData, error) {
|
func LoadData(job *schema.Job, metrics []string, scopes []schema.MetricScope, ctx context.Context) (schema.JobData, error) {
|
||||||
data := cache.Get(cacheKey(job, metrics, scopes), func() (interface{}, time.Duration, int) {
|
data := cache.Get(cacheKey(job, metrics, scopes), func() (_ interface{}, ttl time.Duration, size int) {
|
||||||
var jd schema.JobData
|
var jd schema.JobData
|
||||||
var err error
|
var err error
|
||||||
if job.State == schema.JobStateRunning ||
|
if job.State == schema.JobStateRunning ||
|
||||||
@ -93,30 +93,43 @@ func LoadData(job *schema.Job, metrics []string, scopes []schema.MetricScope, ct
|
|||||||
return err, 0, 0
|
return err, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size = jd.Size()
|
||||||
} else {
|
} else {
|
||||||
jd, err = loadFromArchive(job)
|
jd, err = loadFromArchive(job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, 0, 0
|
return err, 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid sending unrequested data to the client:
|
||||||
if metrics != nil {
|
if metrics != nil {
|
||||||
res := schema.JobData{}
|
res := schema.JobData{}
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
if metricdata, ok := jd[metric]; ok {
|
if perscope, ok := jd[metric]; ok {
|
||||||
res[metric] = metricdata
|
if len(scopes) > 1 {
|
||||||
|
subset := make(map[schema.MetricScope]*schema.JobMetric)
|
||||||
|
for _, scope := range scopes {
|
||||||
|
if jm, ok := perscope[scope]; ok {
|
||||||
|
subset[scope] = jm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
perscope = subset
|
||||||
|
}
|
||||||
|
|
||||||
|
res[metric] = perscope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jd = res
|
jd = res
|
||||||
}
|
}
|
||||||
|
size = 1 // loadFromArchive() caches in the same cache.
|
||||||
}
|
}
|
||||||
|
|
||||||
ttl := 5 * time.Hour
|
ttl = 5 * time.Hour
|
||||||
if job.State == schema.JobStateRunning {
|
if job.State == schema.JobStateRunning {
|
||||||
ttl = 2 * time.Minute
|
ttl = 2 * time.Minute
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareJobData(job, jd, scopes)
|
prepareJobData(job, jd, scopes)
|
||||||
return jd, ttl, jd.Size()
|
return jd, ttl, size
|
||||||
})
|
})
|
||||||
|
|
||||||
if err, ok := data.(error); ok {
|
if err, ok := data.(error); ok {
|
||||||
|
24
routes.go
24
routes.go
@ -174,8 +174,8 @@ func buildFilterPresets(query url.Values) map[string]interface{} {
|
|||||||
filterPresets["user"] = query.Get("user")
|
filterPresets["user"] = query.Get("user")
|
||||||
filterPresets["userMatch"] = "eq"
|
filterPresets["userMatch"] = "eq"
|
||||||
}
|
}
|
||||||
if query.Get("state") != "" && schema.JobState(query.Get("state")).Valid() {
|
if len(query["state"]) != 0 {
|
||||||
filterPresets["state"] = query.Get("state")
|
filterPresets["state"] = query["state"]
|
||||||
}
|
}
|
||||||
if rawtags, ok := query["tag"]; ok {
|
if rawtags, ok := query["tag"]; ok {
|
||||||
tags := make([]int, len(rawtags))
|
tags := make([]int, len(rawtags))
|
||||||
@ -188,6 +188,16 @@ func buildFilterPresets(query url.Values) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
filterPresets["tags"] = tags
|
filterPresets["tags"] = tags
|
||||||
}
|
}
|
||||||
|
if query.Get("duration") != "" {
|
||||||
|
parts := strings.Split(query.Get("duration"), "-")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
a, e1 := strconv.Atoi(parts[0])
|
||||||
|
b, e2 := strconv.Atoi(parts[1])
|
||||||
|
if e1 == nil && e2 == nil {
|
||||||
|
filterPresets["duration"] = map[string]int{"from": a, "to": b}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if query.Get("numNodes") != "" {
|
if query.Get("numNodes") != "" {
|
||||||
parts := strings.Split(query.Get("numNodes"), "-")
|
parts := strings.Split(query.Get("numNodes"), "-")
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
@ -198,6 +208,16 @@ func buildFilterPresets(query url.Values) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if query.Get("numAccelerators") != "" {
|
||||||
|
parts := strings.Split(query.Get("numAccelerators"), "-")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
a, e1 := strconv.Atoi(parts[0])
|
||||||
|
b, e2 := strconv.Atoi(parts[1])
|
||||||
|
if e1 == nil && e2 == nil {
|
||||||
|
filterPresets["numAccelerators"] = map[string]int{"from": a, "to": b}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if query.Get("jobId") != "" {
|
if query.Get("jobId") != "" {
|
||||||
filterPresets["jobId"] = query.Get("jobId")
|
filterPresets["jobId"] = query.Get("jobId")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user