More URL filter presets; Some tweaks

This commit is contained in:
Lou Knauer
2022-03-21 13:30:19 +01:00
parent 8ebf00d980
commit 92349708ae
3 changed files with 42 additions and 9 deletions

View File

@@ -162,9 +162,9 @@ func ArchiveJob(job *schema.Job, ctx context.Context) (*schema.JobMeta, error) {
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}
if job.NumNodes == 1 {
if job.NumNodes <= 8 {
scopes = append(scopes, schema.MetricScopeCore)
}

View File

@@ -63,7 +63,7 @@ var cache *lrucache.Cache = lrucache.New(512 * 1024 * 1024)
// Fetches the metric data for a job.
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 err error
if job.State == schema.JobStateRunning ||
@@ -93,30 +93,43 @@ func LoadData(job *schema.Job, metrics []string, scopes []schema.MetricScope, ct
return err, 0, 0
}
}
size = jd.Size()
} else {
jd, err = loadFromArchive(job)
if err != nil {
return err, 0, 0
}
// Avoid sending unrequested data to the client:
if metrics != nil {
res := schema.JobData{}
for _, metric := range metrics {
if metricdata, ok := jd[metric]; ok {
res[metric] = metricdata
if perscope, ok := jd[metric]; ok {
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
}
size = 1 // loadFromArchive() caches in the same cache.
}
ttl := 5 * time.Hour
ttl = 5 * time.Hour
if job.State == schema.JobStateRunning {
ttl = 2 * time.Minute
}
prepareJobData(job, jd, scopes)
return jd, ttl, jd.Size()
return jd, ttl, size
})
if err, ok := data.(error); ok {