2021-10-26 10:24:43 +02:00
|
|
|
package metricdata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2021-11-26 10:32:36 +01:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2021-10-26 10:24:43 +02:00
|
|
|
|
|
|
|
"github.com/ClusterCockpit/cc-jobarchive/graph/model"
|
|
|
|
"github.com/ClusterCockpit/cc-jobarchive/schema"
|
|
|
|
)
|
|
|
|
|
2021-11-26 10:32:36 +01:00
|
|
|
var runningJobs *CCMetricStore
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
runningJobs = &CCMetricStore{}
|
|
|
|
if err := runningJobs.Init(); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 10:24:43 +02:00
|
|
|
// Fetches the metric data for a job.
|
|
|
|
func LoadData(job *model.Job, metrics []string, ctx context.Context) (schema.JobData, error) {
|
2021-11-26 10:32:36 +01:00
|
|
|
if job.State == model.JobStateRunning {
|
|
|
|
return runningJobs.LoadData(job, metrics, ctx)
|
|
|
|
}
|
|
|
|
|
2021-10-26 10:24:43 +02:00
|
|
|
if job.State != model.JobStateCompleted {
|
2021-11-26 10:32:36 +01:00
|
|
|
return nil, fmt.Errorf("job of state '%s' is not supported", job.State)
|
2021-10-26 10:24:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err := loadFromArchive(job)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if metrics != nil {
|
|
|
|
res := schema.JobData{}
|
|
|
|
for _, metric := range metrics {
|
|
|
|
if metricdata, ok := data[metric]; ok {
|
|
|
|
res[metric] = metricdata
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for the jobsFootprint GraphQL-Query. TODO: Rename/Generalize.
|
|
|
|
func LoadAverages(job *model.Job, metrics []string, data [][]schema.Float, ctx context.Context) error {
|
|
|
|
if job.State != model.JobStateCompleted {
|
|
|
|
return errors.New("only completed jobs are supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
return loadAveragesFromArchive(job, metrics, data)
|
|
|
|
}
|