Enable caching for job metric data

This commit is contained in:
Jan Eitzinger 2022-09-13 15:21:50 +02:00
parent 520c814e3b
commit 732801548f

View File

@ -77,16 +77,18 @@ 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{}, ttl time.Duration, size int) {
var jd schema.JobData
var err error
if job.State == schema.JobStateRunning ||
job.MonitoringStatus == schema.MonitoringStatusRunningOrArchiving ||
!useArchive {
repo, ok := metricDataRepos[job.Cluster]
if !ok {
return nil, fmt.Errorf("no metric data repository configured for '%s'", job.Cluster)
return fmt.Errorf("no metric data repository configured for '%s'", job.Cluster), 0, 0
}
if scopes == nil {
@ -105,13 +107,14 @@ func LoadData(job *schema.Job,
if len(jd) != 0 {
log.Errorf("partial error: %s", err.Error())
} else {
return nil, err
return err, 0, 0
}
}
size = jd.Size()
} else {
jd, err = archive.GetHandle().LoadJobData(job)
if err != nil {
return nil, err
return err, 0, 0
}
// Avoid sending unrequested data to the client:
@ -144,11 +147,23 @@ func LoadData(job *schema.Job,
}
jd = res
}
size = jd.Size()
}
ttl = 5 * time.Hour
if job.State == schema.JobStateRunning {
ttl = 2 * time.Minute
}
prepareJobData(job, jd, scopes)
return jd, ttl, size
})
return jd, nil
if err, ok := data.(error); ok {
return nil, err
}
return data.(schema.JobData), nil
}
// Used for the jobsFootprint GraphQL-Query. TODO: Rename/Generalize.
@ -323,5 +338,5 @@ func ArchiveJob(job *schema.Job, ctx context.Context) (*schema.JobMeta, error) {
return jobMeta, nil
}
return jobMeta, archive.Import(jobMeta, &jobData)
return jobMeta, archive.GetHandle().ImportJob(jobMeta, &jobData)
}