mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-22 20:41:40 +02:00
Port to cc-lib. Extend legal header.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"maps"
|
||||
"sync"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/lrucache"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
"github.com/ClusterCockpit/cc-lib/lrucache"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
)
|
||||
|
||||
const Version uint64 = 2
|
||||
@@ -75,7 +75,7 @@ func Init(rawConfig json.RawMessage, disableArchive bool) error {
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(rawConfig, &cfg); err != nil {
|
||||
log.Warn("Error while unmarshaling raw config json")
|
||||
cclog.Warn("Error while unmarshaling raw config json")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ func Init(rawConfig json.RawMessage, disableArchive bool) error {
|
||||
var version uint64
|
||||
version, err = ar.Init(rawConfig)
|
||||
if err != nil {
|
||||
log.Errorf("Error while initializing archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while initializing archiveBackend: %s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Infof("Load archive version %d", version)
|
||||
cclog.Infof("Load archive version %d", version)
|
||||
|
||||
err = initClusterConfig()
|
||||
})
|
||||
@@ -114,7 +114,7 @@ func LoadAveragesFromArchive(
|
||||
) error {
|
||||
metaFile, err := ar.LoadJobMeta(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func LoadStatsFromArchive(
|
||||
data := make(map[string]schema.MetricStatistics, len(metrics))
|
||||
metaFile, err := ar.LoadJobMeta(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
return data, err
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ func LoadScopedStatsFromArchive(
|
||||
) (schema.ScopedJobStats, error) {
|
||||
data, err := ar.LoadJobStats(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job stats from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job stats from archiveBackend: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func LoadScopedStatsFromArchive(
|
||||
func GetStatistics(job *schema.Job) (map[string]schema.JobStatistics, error) {
|
||||
metaFile, err := ar.LoadJobMeta(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func UpdateMetadata(job *schema.Job, metadata map[string]string) error {
|
||||
|
||||
jobMeta, err := ar.LoadJobMeta(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ func UpdateTags(job *schema.Job, tags []*schema.Tag) error {
|
||||
|
||||
jobMeta, err := ar.LoadJobMeta(job)
|
||||
if err != nil {
|
||||
log.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
cclog.Errorf("Error while loading job metadata from archiveBackend: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive_test
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/util"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/archive"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
"github.com/ClusterCockpit/cc-lib/util"
|
||||
)
|
||||
|
||||
var jobs []*schema.Job
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,7 +27,7 @@ func initClusterConfig() error {
|
||||
|
||||
cluster, err := ar.LoadClusterCfg(c)
|
||||
if err != nil {
|
||||
log.Warnf("Error while loading cluster config for cluster '%v'", c)
|
||||
cclog.Warnf("Error while loading cluster config for cluster '%v'", c)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive_test
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -21,9 +21,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/config"
|
||||
"github.com/ClusterCockpit/cc-backend/internal/util"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
"github.com/ClusterCockpit/cc-lib/util"
|
||||
"github.com/santhosh-tekuri/jsonschema/v5"
|
||||
)
|
||||
|
||||
@@ -68,7 +68,7 @@ func getPath(
|
||||
func loadJobMeta(filename string) (*schema.Job, error) {
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Errorf("loadJobMeta() > open file error: %v", err)
|
||||
cclog.Errorf("loadJobMeta() > open file error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
if config.Keys.Validate {
|
||||
@@ -83,7 +83,7 @@ func loadJobMeta(filename string) (*schema.Job, error) {
|
||||
func loadJobData(filename string, isCompressed bool) (schema.JobData, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Errorf("fsBackend LoadJobData()- %v", err)
|
||||
cclog.Errorf("fsBackend LoadJobData()- %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
@@ -91,7 +91,7 @@ func loadJobData(filename string, isCompressed bool) (schema.JobData, error) {
|
||||
if isCompressed {
|
||||
r, err := gzip.NewReader(f)
|
||||
if err != nil {
|
||||
log.Errorf(" %v", err)
|
||||
cclog.Errorf(" %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
@@ -116,7 +116,7 @@ func loadJobData(filename string, isCompressed bool) (schema.JobData, error) {
|
||||
func loadJobStats(filename string, isCompressed bool) (schema.ScopedJobStats, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Errorf("fsBackend LoadJobStats()- %v", err)
|
||||
cclog.Errorf("fsBackend LoadJobStats()- %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
@@ -124,7 +124,7 @@ func loadJobStats(filename string, isCompressed bool) (schema.ScopedJobStats, er
|
||||
if isCompressed {
|
||||
r, err := gzip.NewReader(f)
|
||||
if err != nil {
|
||||
log.Errorf(" %v", err)
|
||||
cclog.Errorf(" %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
@@ -149,25 +149,25 @@ func loadJobStats(filename string, isCompressed bool) (schema.ScopedJobStats, er
|
||||
func (fsa *FsArchive) Init(rawConfig json.RawMessage) (uint64, error) {
|
||||
var config FsArchiveConfig
|
||||
if err := json.Unmarshal(rawConfig, &config); err != nil {
|
||||
log.Warnf("Init() > Unmarshal error: %#v", err)
|
||||
cclog.Warnf("Init() > Unmarshal error: %#v", err)
|
||||
return 0, err
|
||||
}
|
||||
if config.Path == "" {
|
||||
err := fmt.Errorf("Init() : empty config.Path")
|
||||
log.Errorf("Init() > config.Path error: %v", err)
|
||||
cclog.Errorf("Init() > config.Path error: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
fsa.path = config.Path
|
||||
|
||||
b, err := os.ReadFile(filepath.Join(fsa.path, "version.txt"))
|
||||
if err != nil {
|
||||
log.Warnf("fsBackend Init() - %v", err)
|
||||
cclog.Warnf("fsBackend Init() - %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
version, err := strconv.ParseUint(strings.TrimSuffix(string(b), "\n"), 10, 64)
|
||||
if err != nil {
|
||||
log.Errorf("fsBackend Init()- %v", err)
|
||||
cclog.Errorf("fsBackend Init()- %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (fsa *FsArchive) Init(rawConfig json.RawMessage) (uint64, error) {
|
||||
|
||||
entries, err := os.ReadDir(fsa.path)
|
||||
if err != nil {
|
||||
log.Errorf("Init() > ReadDir() error: %v", err)
|
||||
cclog.Errorf("Init() > ReadDir() error: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func (fsa *FsArchive) Info() {
|
||||
fmt.Printf("Job archive %s\n", fsa.path)
|
||||
clusters, err := os.ReadDir(fsa.path)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading clusters failed: %s", err.Error())
|
||||
cclog.Fatalf("Reading clusters failed: %s", err.Error())
|
||||
}
|
||||
|
||||
ci := make(map[string]*clusterInfo)
|
||||
@@ -209,7 +209,7 @@ func (fsa *FsArchive) Info() {
|
||||
ci[cc] = &clusterInfo{dateFirst: time.Now().Unix()}
|
||||
lvl1Dirs, err := os.ReadDir(filepath.Join(fsa.path, cluster.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl1Dir := range lvl1Dirs {
|
||||
@@ -218,14 +218,14 @@ func (fsa *FsArchive) Info() {
|
||||
}
|
||||
lvl2Dirs, err := os.ReadDir(filepath.Join(fsa.path, cluster.Name(), lvl1Dir.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl2Dir := range lvl2Dirs {
|
||||
dirpath := filepath.Join(fsa.path, cluster.Name(), lvl1Dir.Name(), lvl2Dir.Name())
|
||||
startTimeDirs, err := os.ReadDir(dirpath)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, startTimeDir := range startTimeDirs {
|
||||
@@ -233,7 +233,7 @@ func (fsa *FsArchive) Info() {
|
||||
ci[cc].numJobs++
|
||||
startTime, err := strconv.ParseInt(startTimeDir.Name(), 10, 64)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot parse starttime: %s", err.Error())
|
||||
cclog.Fatalf("Cannot parse starttime: %s", err.Error())
|
||||
}
|
||||
ci[cc].dateFirst = util.Min(ci[cc].dateFirst, startTime)
|
||||
ci[cc].dateLast = util.Max(ci[cc].dateLast, startTime)
|
||||
@@ -278,7 +278,7 @@ func (fsa *FsArchive) Clean(before int64, after int64) {
|
||||
|
||||
clusters, err := os.ReadDir(fsa.path)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading clusters failed: %s", err.Error())
|
||||
cclog.Fatalf("Reading clusters failed: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, cluster := range clusters {
|
||||
@@ -288,7 +288,7 @@ func (fsa *FsArchive) Clean(before int64, after int64) {
|
||||
|
||||
lvl1Dirs, err := os.ReadDir(filepath.Join(fsa.path, cluster.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl1Dir := range lvl1Dirs {
|
||||
@@ -297,33 +297,33 @@ func (fsa *FsArchive) Clean(before int64, after int64) {
|
||||
}
|
||||
lvl2Dirs, err := os.ReadDir(filepath.Join(fsa.path, cluster.Name(), lvl1Dir.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl2Dir := range lvl2Dirs {
|
||||
dirpath := filepath.Join(fsa.path, cluster.Name(), lvl1Dir.Name(), lvl2Dir.Name())
|
||||
startTimeDirs, err := os.ReadDir(dirpath)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, startTimeDir := range startTimeDirs {
|
||||
if startTimeDir.IsDir() {
|
||||
startTime, err := strconv.ParseInt(startTimeDir.Name(), 10, 64)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot parse starttime: %s", err.Error())
|
||||
cclog.Fatalf("Cannot parse starttime: %s", err.Error())
|
||||
}
|
||||
|
||||
if startTime < before || startTime > after {
|
||||
if err := os.RemoveAll(filepath.Join(dirpath, startTimeDir.Name())); err != nil {
|
||||
log.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
cclog.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if util.GetFilecount(dirpath) == 0 {
|
||||
if err := os.Remove(dirpath); err != nil {
|
||||
log.Errorf("JobArchive Clean() error: %v", err)
|
||||
cclog.Errorf("JobArchive Clean() error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,16 +337,16 @@ func (fsa *FsArchive) Move(jobs []*schema.Job, path string) {
|
||||
target := getDirectory(job, path)
|
||||
|
||||
if err := os.MkdirAll(filepath.Clean(filepath.Join(target, "..")), 0777); err != nil {
|
||||
log.Errorf("JobArchive Move MkDir error: %v", err)
|
||||
cclog.Errorf("JobArchive Move MkDir error: %v", err)
|
||||
}
|
||||
if err := os.Rename(source, target); err != nil {
|
||||
log.Errorf("JobArchive Move() error: %v", err)
|
||||
cclog.Errorf("JobArchive Move() error: %v", err)
|
||||
}
|
||||
|
||||
parent := filepath.Clean(filepath.Join(source, ".."))
|
||||
if util.GetFilecount(parent) == 0 {
|
||||
if err := os.Remove(parent); err != nil {
|
||||
log.Errorf("JobArchive Move() error: %v", err)
|
||||
cclog.Errorf("JobArchive Move() error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,18 +357,18 @@ func (fsa *FsArchive) CleanUp(jobs []*schema.Job) {
|
||||
for _, job := range jobs {
|
||||
dir := getDirectory(job, fsa.path)
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
log.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
cclog.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
}
|
||||
|
||||
parent := filepath.Clean(filepath.Join(dir, ".."))
|
||||
if util.GetFilecount(parent) == 0 {
|
||||
if err := os.Remove(parent); err != nil {
|
||||
log.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
cclog.Errorf("JobArchive Cleanup() error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Retention Service - Remove %d files in %s", len(jobs), time.Since(start))
|
||||
cclog.Infof("Retention Service - Remove %d files in %s", len(jobs), time.Since(start))
|
||||
}
|
||||
|
||||
func (fsa *FsArchive) Compress(jobs []*schema.Job) {
|
||||
@@ -383,24 +383,24 @@ func (fsa *FsArchive) Compress(jobs []*schema.Job) {
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Compression Service - %d files took %s", cnt, time.Since(start))
|
||||
cclog.Infof("Compression Service - %d files took %s", cnt, time.Since(start))
|
||||
}
|
||||
|
||||
func (fsa *FsArchive) CompressLast(starttime int64) int64 {
|
||||
filename := filepath.Join(fsa.path, "compress.txt")
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Errorf("fsBackend Compress - %v", err)
|
||||
cclog.Errorf("fsBackend Compress - %v", err)
|
||||
os.WriteFile(filename, []byte(fmt.Sprintf("%d", starttime)), 0644)
|
||||
return starttime
|
||||
}
|
||||
last, err := strconv.ParseInt(strings.TrimSuffix(string(b), "\n"), 10, 64)
|
||||
if err != nil {
|
||||
log.Errorf("fsBackend Compress - %v", err)
|
||||
cclog.Errorf("fsBackend Compress - %v", err)
|
||||
return starttime
|
||||
}
|
||||
|
||||
log.Infof("fsBackend Compress - start %d last %d", starttime, last)
|
||||
cclog.Infof("fsBackend Compress - start %d last %d", starttime, last)
|
||||
os.WriteFile(filename, []byte(fmt.Sprintf("%d", starttime)), 0644)
|
||||
return last
|
||||
}
|
||||
@@ -437,10 +437,10 @@ func (fsa *FsArchive) LoadJobMeta(job *schema.Job) (*schema.Job, error) {
|
||||
func (fsa *FsArchive) LoadClusterCfg(name string) (*schema.Cluster, error) {
|
||||
b, err := os.ReadFile(filepath.Join(fsa.path, name, "cluster.json"))
|
||||
if err != nil {
|
||||
log.Errorf("LoadClusterCfg() > open file error: %v", err)
|
||||
cclog.Errorf("LoadClusterCfg() > open file error: %v", err)
|
||||
// if config.Keys.Validate {
|
||||
if err := schema.Validate(schema.ClusterCfg, bytes.NewReader(b)); err != nil {
|
||||
log.Warnf("Validate cluster config: %v\n", err)
|
||||
cclog.Warnf("Validate cluster config: %v\n", err)
|
||||
return &schema.Cluster{}, fmt.Errorf("validate cluster config: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -453,7 +453,7 @@ func (fsa *FsArchive) Iter(loadMetricData bool) <-chan JobContainer {
|
||||
go func() {
|
||||
clustersDir, err := os.ReadDir(fsa.path)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading clusters failed @ cluster dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading clusters failed @ cluster dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, clusterDir := range clustersDir {
|
||||
@@ -462,7 +462,7 @@ func (fsa *FsArchive) Iter(loadMetricData bool) <-chan JobContainer {
|
||||
}
|
||||
lvl1Dirs, err := os.ReadDir(filepath.Join(fsa.path, clusterDir.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl1 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl1Dir := range lvl1Dirs {
|
||||
@@ -473,21 +473,21 @@ func (fsa *FsArchive) Iter(loadMetricData bool) <-chan JobContainer {
|
||||
|
||||
lvl2Dirs, err := os.ReadDir(filepath.Join(fsa.path, clusterDir.Name(), lvl1Dir.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ lvl2 dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, lvl2Dir := range lvl2Dirs {
|
||||
dirpath := filepath.Join(fsa.path, clusterDir.Name(), lvl1Dir.Name(), lvl2Dir.Name())
|
||||
startTimeDirs, err := os.ReadDir(dirpath)
|
||||
if err != nil {
|
||||
log.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
cclog.Fatalf("Reading jobs failed @ starttime dirs: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, startTimeDir := range startTimeDirs {
|
||||
if startTimeDir.IsDir() {
|
||||
job, err := loadJobMeta(filepath.Join(dirpath, startTimeDir.Name(), "meta.json"))
|
||||
if err != nil && !errors.Is(err, &jsonschema.ValidationError{}) {
|
||||
log.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
cclog.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
}
|
||||
|
||||
if loadMetricData {
|
||||
@@ -501,10 +501,10 @@ func (fsa *FsArchive) Iter(loadMetricData bool) <-chan JobContainer {
|
||||
|
||||
data, err := loadJobData(filename, isCompressed)
|
||||
if err != nil && !errors.Is(err, &jsonschema.ValidationError{}) {
|
||||
log.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
cclog.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
}
|
||||
ch <- JobContainer{Meta: job, Data: &data}
|
||||
log.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
cclog.Errorf("in %s: %s", filepath.Join(dirpath, startTimeDir.Name()), err.Error())
|
||||
} else {
|
||||
ch <- JobContainer{Meta: job, Data: nil}
|
||||
}
|
||||
@@ -521,15 +521,15 @@ func (fsa *FsArchive) Iter(loadMetricData bool) <-chan JobContainer {
|
||||
func (fsa *FsArchive) StoreJobMeta(job *schema.Job) error {
|
||||
f, err := os.Create(getPath(job, fsa.path, "meta.json"))
|
||||
if err != nil {
|
||||
log.Error("Error while creating filepath for meta.json")
|
||||
cclog.Error("Error while creating filepath for meta.json")
|
||||
return err
|
||||
}
|
||||
if err := EncodeJobMeta(f, job); err != nil {
|
||||
log.Error("Error while encoding job metadata to meta.json file")
|
||||
cclog.Error("Error while encoding job metadata to meta.json file")
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Warn("Error while closing meta.json file")
|
||||
cclog.Warn("Error while closing meta.json file")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -546,35 +546,35 @@ func (fsa *FsArchive) ImportJob(
|
||||
) error {
|
||||
dir := getPath(jobMeta, fsa.path, "")
|
||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||
log.Error("Error while creating job archive path")
|
||||
cclog.Error("Error while creating job archive path")
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(path.Join(dir, "meta.json"))
|
||||
if err != nil {
|
||||
log.Error("Error while creating filepath for meta.json")
|
||||
cclog.Error("Error while creating filepath for meta.json")
|
||||
return err
|
||||
}
|
||||
if err := EncodeJobMeta(f, jobMeta); err != nil {
|
||||
log.Error("Error while encoding job metadata to meta.json file")
|
||||
cclog.Error("Error while encoding job metadata to meta.json file")
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Warn("Error while closing meta.json file")
|
||||
cclog.Warn("Error while closing meta.json file")
|
||||
return err
|
||||
}
|
||||
|
||||
f, err = os.Create(path.Join(dir, "data.json"))
|
||||
if err != nil {
|
||||
log.Error("Error while creating filepath for data.json")
|
||||
cclog.Error("Error while creating filepath for data.json")
|
||||
return err
|
||||
}
|
||||
if err := EncodeJobData(f, jobData); err != nil {
|
||||
log.Error("Error while encoding job metricdata to data.json file")
|
||||
cclog.Error("Error while encoding job metricdata to data.json file")
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Warn("Error while closing data.json file")
|
||||
cclog.Warn("Error while closing data.json file")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/util"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
"github.com/ClusterCockpit/cc-lib/util"
|
||||
)
|
||||
|
||||
func TestInitEmptyPath(t *testing.T) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -9,15 +9,15 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
"github.com/ClusterCockpit/cc-lib/schema"
|
||||
)
|
||||
|
||||
func DecodeJobData(r io.Reader, k string) (schema.JobData, error) {
|
||||
data := cache.Get(k, func() (value interface{}, ttl time.Duration, size int) {
|
||||
var d schema.JobData
|
||||
if err := json.NewDecoder(r).Decode(&d); err != nil {
|
||||
log.Warn("Error while decoding raw job data json")
|
||||
cclog.Warn("Error while decoding raw job data json")
|
||||
return err, 0, 1000
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func DecodeJobData(r io.Reader, k string) (schema.JobData, error) {
|
||||
})
|
||||
|
||||
if err, ok := data.(error); ok {
|
||||
log.Warn("Error in decoded job data set")
|
||||
cclog.Warn("Error in decoded job data set")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func DecodeJobStats(r io.Reader, k string) (schema.ScopedJobStats, error) {
|
||||
func DecodeJobMeta(r io.Reader) (*schema.Job, error) {
|
||||
var d schema.Job
|
||||
if err := json.NewDecoder(r).Decode(&d); err != nil {
|
||||
log.Warn("Error while decoding raw job meta json")
|
||||
cclog.Warn("Error while decoding raw job meta json")
|
||||
return &d, err
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func DecodeJobMeta(r io.Reader) (*schema.Job, error) {
|
||||
func DecodeCluster(r io.Reader) (*schema.Cluster, error) {
|
||||
var c schema.Cluster
|
||||
if err := json.NewDecoder(r).Decode(&c); err != nil {
|
||||
log.Warn("Error while decoding raw cluster json")
|
||||
cclog.Warn("Error while decoding raw cluster json")
|
||||
return &c, err
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func DecodeCluster(r io.Reader) (*schema.Cluster, error) {
|
||||
func EncodeJobData(w io.Writer, d *schema.JobData) error {
|
||||
// Sanitize parameters
|
||||
if err := json.NewEncoder(w).Encode(d); err != nil {
|
||||
log.Warn("Error while encoding new job data json")
|
||||
cclog.Warn("Error while encoding new job data json")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func EncodeJobData(w io.Writer, d *schema.JobData) error {
|
||||
func EncodeJobMeta(w io.Writer, d *schema.Job) error {
|
||||
// Sanitize parameters
|
||||
if err := json.NewEncoder(w).Encode(d); err != nil {
|
||||
log.Warn("Error while encoding new job meta json")
|
||||
cclog.Warn("Error while encoding new job meta json")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
)
|
||||
|
||||
type NodeList [][]interface {
|
||||
@@ -51,7 +51,7 @@ func (nl *NodeList) PrintList() []string {
|
||||
if inner["zeroPadded"] == 1 {
|
||||
out = append(out, fmt.Sprintf("%s%0*d", prefix, inner["digits"], i))
|
||||
} else {
|
||||
log.Error("node list: only zero-padded ranges are allowed")
|
||||
cclog.Error("node list: only zero-padded ranges are allowed")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ type NLExprIntRange struct {
|
||||
|
||||
func (nle NLExprIntRange) consume(input string) (next string, ok bool) {
|
||||
if !nle.zeroPadded || nle.digits < 1 {
|
||||
log.Error("only zero-padded ranges are allowed")
|
||||
cclog.Error("only zero-padded ranges are allowed")
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package archive
|
||||
|
220
pkg/log/log.go
220
pkg/log/log.go
@@ -1,220 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Provides a simple way of logging with different levels.
|
||||
// Time/Date are not logged because systemd adds
|
||||
// them for us (Default, can be changed by flag '--logdate true').
|
||||
//
|
||||
// Uses these prefixes: https://www.freedesktop.org/software/systemd/man/sd-daemon.html
|
||||
|
||||
var (
|
||||
DebugWriter io.Writer = os.Stderr
|
||||
InfoWriter io.Writer = os.Stderr
|
||||
WarnWriter io.Writer = os.Stderr
|
||||
ErrWriter io.Writer = os.Stderr
|
||||
CritWriter io.Writer = os.Stderr
|
||||
)
|
||||
|
||||
var (
|
||||
DebugPrefix string = "<7>[DEBUG] "
|
||||
InfoPrefix string = "<6>[INFO] "
|
||||
WarnPrefix string = "<4>[WARNING] "
|
||||
ErrPrefix string = "<3>[ERROR] "
|
||||
CritPrefix string = "<2>[CRITICAL] "
|
||||
)
|
||||
|
||||
var (
|
||||
DebugLog *log.Logger = log.New(DebugWriter, DebugPrefix, log.LstdFlags)
|
||||
InfoLog *log.Logger = log.New(InfoWriter, InfoPrefix, log.LstdFlags|log.Lshortfile)
|
||||
WarnLog *log.Logger = log.New(WarnWriter, WarnPrefix, log.LstdFlags|log.Lshortfile)
|
||||
ErrLog *log.Logger = log.New(ErrWriter, ErrPrefix, log.LstdFlags|log.Llongfile)
|
||||
CritLog *log.Logger = log.New(CritWriter, CritPrefix, log.LstdFlags|log.Llongfile)
|
||||
)
|
||||
|
||||
var loglevel string = "info"
|
||||
|
||||
/* CONFIG */
|
||||
|
||||
func Init(lvl string, logdate bool) {
|
||||
// Discard I/O for all writers below selected loglevel; <CRITICAL> is always written.
|
||||
switch lvl {
|
||||
case "crit":
|
||||
ErrWriter = io.Discard
|
||||
fallthrough
|
||||
case "err":
|
||||
WarnWriter = io.Discard
|
||||
fallthrough
|
||||
case "warn":
|
||||
InfoWriter = io.Discard
|
||||
fallthrough
|
||||
case "info":
|
||||
DebugWriter = io.Discard
|
||||
case "debug":
|
||||
// Nothing to do...
|
||||
break
|
||||
default:
|
||||
fmt.Printf("pkg/log: Flag 'loglevel' has invalid value %#v\npkg/log: Will use default loglevel '%s'\n", lvl, loglevel)
|
||||
}
|
||||
|
||||
if !logdate {
|
||||
DebugLog = log.New(DebugWriter, DebugPrefix, 0)
|
||||
InfoLog = log.New(InfoWriter, InfoPrefix, log.Lshortfile)
|
||||
WarnLog = log.New(WarnWriter, WarnPrefix, log.Lshortfile)
|
||||
ErrLog = log.New(ErrWriter, ErrPrefix, log.Llongfile)
|
||||
CritLog = log.New(CritWriter, CritPrefix, log.Llongfile)
|
||||
} else {
|
||||
DebugLog = log.New(DebugWriter, DebugPrefix, log.LstdFlags)
|
||||
InfoLog = log.New(InfoWriter, InfoPrefix, log.LstdFlags|log.Lshortfile)
|
||||
WarnLog = log.New(WarnWriter, WarnPrefix, log.LstdFlags|log.Lshortfile)
|
||||
ErrLog = log.New(ErrWriter, ErrPrefix, log.LstdFlags|log.Llongfile)
|
||||
CritLog = log.New(CritWriter, CritPrefix, log.LstdFlags|log.Llongfile)
|
||||
}
|
||||
|
||||
loglevel = lvl
|
||||
}
|
||||
|
||||
/* HELPER */
|
||||
|
||||
func Loglevel() string {
|
||||
return loglevel
|
||||
}
|
||||
|
||||
/* PRIVATE HELPER */
|
||||
|
||||
// Return unformatted string
|
||||
func printStr(v ...interface{}) string {
|
||||
return fmt.Sprint(v...)
|
||||
}
|
||||
|
||||
// Return formatted string
|
||||
func printfStr(format string, v ...interface{}) string {
|
||||
return fmt.Sprintf(format, v...)
|
||||
}
|
||||
|
||||
/* PRINT */
|
||||
|
||||
// Prints to STDOUT without string formatting; application continues.
|
||||
// Used for special cases not requiring log information like date or location.
|
||||
func Print(v ...interface{}) {
|
||||
fmt.Fprintln(os.Stdout, v...)
|
||||
}
|
||||
|
||||
// Prints to STDOUT without string formatting; application exits with error code 0.
|
||||
// Used for exiting succesfully with message after expected outcome, e.g. successful single-call application runs.
|
||||
func Exit(v ...interface{}) {
|
||||
fmt.Fprintln(os.Stdout, v...)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Prints to STDOUT without string formatting; application exits with error code 1.
|
||||
// Used for terminating with message after to be expected errors, e.g. wrong arguments or during init().
|
||||
func Abort(v ...interface{}) {
|
||||
fmt.Fprintln(os.Stdout, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prints to DEBUG writer without string formatting; application continues.
|
||||
// Used for logging additional information, primarily for development.
|
||||
func Debug(v ...interface{}) {
|
||||
DebugLog.Output(2, printStr(v...))
|
||||
}
|
||||
|
||||
// Prints to INFO writer without string formatting; application continues.
|
||||
// Used for logging additional information, e.g. notable returns or common fail-cases.
|
||||
func Info(v ...interface{}) {
|
||||
InfoLog.Output(2, printStr(v...))
|
||||
}
|
||||
|
||||
// Prints to WARNING writer without string formatting; application continues.
|
||||
// Used for logging important information, e.g. uncommon edge-cases or administration related information.
|
||||
func Warn(v ...interface{}) {
|
||||
WarnLog.Output(2, printStr(v...))
|
||||
}
|
||||
|
||||
// Prints to ERROR writer without string formatting; application continues.
|
||||
// Used for logging errors, but code still can return default(s) or nil.
|
||||
func Error(v ...interface{}) {
|
||||
ErrLog.Output(2, printStr(v...))
|
||||
}
|
||||
|
||||
// Prints to CRITICAL writer without string formatting; application exits with error code 1.
|
||||
// Used for terminating on unexpected errors with date and code location.
|
||||
func Fatal(v ...interface{}) {
|
||||
CritLog.Output(2, printStr(v...))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prints to PANIC function without string formatting; application exits with panic.
|
||||
// Used for terminating on unexpected errors with stacktrace.
|
||||
func Panic(v ...interface{}) {
|
||||
panic(printStr(v...))
|
||||
}
|
||||
|
||||
/* PRINT FORMAT*/
|
||||
|
||||
// Prints to STDOUT with string formatting; application continues.
|
||||
// Used for special cases not requiring log information like date or location.
|
||||
func Printf(format string, v ...interface{}) {
|
||||
fmt.Fprintf(os.Stdout, format, v...)
|
||||
}
|
||||
|
||||
// Prints to STDOUT with string formatting; application exits with error code 0.
|
||||
// Used for exiting succesfully with message after expected outcome, e.g. successful single-call application runs.
|
||||
func Exitf(format string, v ...interface{}) {
|
||||
fmt.Fprintf(os.Stdout, format, v...)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Prints to STDOUT with string formatting; application exits with error code 1.
|
||||
// Used for terminating with message after to be expected errors, e.g. wrong arguments or during init().
|
||||
func Abortf(format string, v ...interface{}) {
|
||||
fmt.Fprintf(os.Stdout, format, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prints to DEBUG writer with string formatting; application continues.
|
||||
// Used for logging additional information, primarily for development.
|
||||
func Debugf(format string, v ...interface{}) {
|
||||
DebugLog.Output(2, printfStr(format, v...))
|
||||
}
|
||||
|
||||
// Prints to INFO writer with string formatting; application continues.
|
||||
// Used for logging additional information, e.g. notable returns or common fail-cases.
|
||||
func Infof(format string, v ...interface{}) {
|
||||
InfoLog.Output(2, printfStr(format, v...))
|
||||
}
|
||||
|
||||
// Prints to WARNING writer with string formatting; application continues.
|
||||
// Used for logging important information, e.g. uncommon edge-cases or administration related information.
|
||||
func Warnf(format string, v ...interface{}) {
|
||||
WarnLog.Output(2, printfStr(format, v...))
|
||||
}
|
||||
|
||||
// Prints to ERROR writer with string formatting; application continues.
|
||||
// Used for logging errors, but code still can return default(s) or nil.
|
||||
func Errorf(format string, v ...interface{}) {
|
||||
ErrLog.Output(2, printfStr(format, v...))
|
||||
}
|
||||
|
||||
// Prints to CRITICAL writer with string formatting; application exits with error code 1.
|
||||
// Used for terminating on unexpected errors with date and code location.
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
CritLog.Output(2, printfStr(format, v...))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prints to PANIC function with string formatting; application exits with panic.
|
||||
// Used for terminating on unexpected errors with stacktrace.
|
||||
func Panicf(format string, v ...interface{}) {
|
||||
panic(printfStr(format, v...))
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
# In-Memory LRU Cache for Golang Applications
|
||||
|
||||
This library can be embedded into your existing go applications
|
||||
and play the role *Memcached* or *Redis* might play for others.
|
||||
It is inspired by [PHP Symfony's Cache Components](https://symfony.com/doc/current/components/cache/adapters/array_cache_adapter.html),
|
||||
having a similar API. This library can not be used for persistance,
|
||||
is not properly tested yet and a bit special in a few ways described
|
||||
below (Especially with regards to the memory usage/`size`).
|
||||
|
||||
In addition to the interface described below, a `http.Handler` that can be used as middleware is provided as well.
|
||||
|
||||
- Advantages:
|
||||
- Anything (`interface{}`) can be stored as value
|
||||
- As it lives in the application itself, no serialization or de-serialization is needed
|
||||
- As it lives in the application itself, no memory moving/networking is needed
|
||||
- The computation of a new value for a key does __not__ block the full cache (only the key)
|
||||
- Disadvantages:
|
||||
- You have to provide a size estimate for every value
|
||||
- __This size estimate should not change (i.e. values should not mutate)__
|
||||
- The cache can only be accessed by one application
|
||||
|
||||
## Example
|
||||
|
||||
```go
|
||||
// Go look at the godocs and ./cache_test.go for more documentation and examples
|
||||
|
||||
maxMemory := 1000
|
||||
cache := lrucache.New(maxMemory)
|
||||
|
||||
bar = cache.Get("foo", func () (value interface{}, ttl time.Duration, size int) {
|
||||
return "bar", 10 * time.Second, len("bar")
|
||||
}).(string)
|
||||
|
||||
// bar == "bar"
|
||||
|
||||
bar = cache.Get("foo", func () (value interface{}, ttl time.Duration, size int) {
|
||||
panic("will not be called")
|
||||
}).(string)
|
||||
```
|
||||
|
||||
## Why does `cache.Get` take a function as argument?
|
||||
|
||||
*Using the mechanism described below is optional, the second argument to `Get` can be `nil` and there is a `Put` function as well.*
|
||||
|
||||
Because this library is meant to be used by multi threaded applications and the following would
|
||||
result in the same data being fetched twice if both goroutines run in parallel:
|
||||
|
||||
```go
|
||||
// This code shows what could happen with other cache libraries
|
||||
c := lrucache.New(MAX_CACHE_ENTRIES)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
go func(){
|
||||
// This code will run twice in different goroutines,
|
||||
// it could overlap. As `fetchData` probably does some
|
||||
// I/O and takes a long time, the probability of both
|
||||
// goroutines calling `fetchData` is very high!
|
||||
url := "http://example.com/foo"
|
||||
contents := c.Get(url)
|
||||
if contents == nil {
|
||||
contents = fetchData(url)
|
||||
c.Set(url, contents)
|
||||
}
|
||||
|
||||
handleData(contents.([]byte))
|
||||
}()
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Here, if one wanted to make sure that only one of both goroutines fetches the data,
|
||||
the programmer would need to build his own synchronization. That would suck!
|
||||
|
||||
```go
|
||||
c := lrucache.New(MAX_CACHE_SIZE)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
go func(){
|
||||
url := "http://example.com/foo"
|
||||
contents := c.Get(url, func()(interface{}, time.Time, int) {
|
||||
// This closure will only be called once!
|
||||
// If another goroutine calls `c.Get` while this closure
|
||||
// is still being executed, it will wait.
|
||||
buf := fetchData(url)
|
||||
return buf, 100 * time.Second, len(buf)
|
||||
})
|
||||
|
||||
handleData(contents.([]byte))
|
||||
}()
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
This is much better as less resources are wasted and synchronization is handled by
|
||||
the library. If it gets called, the call to the closure happens synchronously. While
|
||||
it is being executed, all other cache keys can still be accessed without having to wait
|
||||
for the execution to be done.
|
||||
|
||||
## How `Get` works
|
||||
|
||||
The closure passed to `Get` will be called if the value asked for is not cached or
|
||||
expired. It should return the following values:
|
||||
|
||||
- The value corresponding to that key and to be stored in the cache
|
||||
- The time to live for that value (how long until it expires and needs to be recomputed)
|
||||
- A size estimate
|
||||
|
||||
When `maxMemory` is reached, cache entries need to be evicted. Theoretically,
|
||||
it would be possible to use reflection on every value placed in the cache
|
||||
to get its exact size in bytes. This would be very expansive and slow though.
|
||||
Also, size can change. Instead of this library calculating the size in bytes, you, the user,
|
||||
have to provide a size for every value in whatever unit you like (as long as it is the same unit everywhere).
|
||||
|
||||
Suggestions on what to use as size: `len(str)` for strings, `len(slice) * size_of_slice_type`, etc.. It is possible
|
||||
to use `1` as size for every entry, in that case at most `maxMemory` entries will be in the cache at the same time.
|
||||
|
||||
## Affects on GC
|
||||
|
||||
Because of the way a garbage collector decides when to run ([explained in the
|
||||
runtime package](https://pkg.go.dev/runtime)), having large amounts of data
|
||||
sitting in your cache might increase the memory consumption of your process by
|
||||
two times the maximum size of the cache. You can decrease the *target
|
||||
percentage* to reduce the effect, but then you might have negative performance
|
||||
effects when your cache is not filled.
|
@@ -1,292 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package lrucache
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Type of the closure that must be passed to `Get` to
|
||||
// compute the value in case it is not cached.
|
||||
//
|
||||
// returned values are the computed value to be stored in the cache,
|
||||
// the duration until this value will expire and a size estimate.
|
||||
type ComputeValue func() (value interface{}, ttl time.Duration, size int)
|
||||
|
||||
type cacheEntry struct {
|
||||
key string
|
||||
value interface{}
|
||||
|
||||
expiration time.Time
|
||||
size int
|
||||
waitingForComputation int
|
||||
|
||||
next, prev *cacheEntry
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
mutex sync.Mutex
|
||||
cond *sync.Cond
|
||||
maxmemory, usedmemory int
|
||||
entries map[string]*cacheEntry
|
||||
head, tail *cacheEntry
|
||||
}
|
||||
|
||||
// Return a new instance of a LRU In-Memory Cache.
|
||||
// Read [the README](./README.md) for more information
|
||||
// on what is going on with `maxmemory`.
|
||||
func New(maxmemory int) *Cache {
|
||||
cache := &Cache{
|
||||
maxmemory: maxmemory,
|
||||
entries: map[string]*cacheEntry{},
|
||||
}
|
||||
cache.cond = sync.NewCond(&cache.mutex)
|
||||
return cache
|
||||
}
|
||||
|
||||
// Return the cached value for key `key` or call `computeValue` and
|
||||
// store its return value in the cache. If called, the closure will be
|
||||
// called synchronous and __shall not call methods on the same cache__
|
||||
// or a deadlock might ocure. If `computeValue` is nil, the cache is checked
|
||||
// and if no entry was found, nil is returned. If another goroutine is currently
|
||||
// computing that value, the result is waited for.
|
||||
func (c *Cache) Get(key string, computeValue ComputeValue) interface{} {
|
||||
now := time.Now()
|
||||
|
||||
c.mutex.Lock()
|
||||
if entry, ok := c.entries[key]; ok {
|
||||
// The expiration not being set is what shows us that
|
||||
// the computation of that value is still ongoing.
|
||||
for entry.expiration.IsZero() {
|
||||
entry.waitingForComputation += 1
|
||||
c.cond.Wait()
|
||||
entry.waitingForComputation -= 1
|
||||
}
|
||||
|
||||
if now.After(entry.expiration) {
|
||||
if !c.evictEntry(entry) {
|
||||
if entry.expiration.IsZero() {
|
||||
panic("LRUCACHE/CACHE > cache entry that shoud have been waited for could not be evicted.")
|
||||
}
|
||||
c.mutex.Unlock()
|
||||
return entry.value
|
||||
}
|
||||
} else {
|
||||
if entry != c.head {
|
||||
c.unlinkEntry(entry)
|
||||
c.insertFront(entry)
|
||||
}
|
||||
c.mutex.Unlock()
|
||||
return entry.value
|
||||
}
|
||||
}
|
||||
|
||||
if computeValue == nil {
|
||||
c.mutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
entry := &cacheEntry{
|
||||
key: key,
|
||||
waitingForComputation: 1,
|
||||
}
|
||||
|
||||
c.entries[key] = entry
|
||||
|
||||
hasPaniced := true
|
||||
defer func() {
|
||||
if hasPaniced {
|
||||
c.mutex.Lock()
|
||||
delete(c.entries, key)
|
||||
entry.expiration = now
|
||||
entry.waitingForComputation -= 1
|
||||
}
|
||||
c.mutex.Unlock()
|
||||
}()
|
||||
|
||||
c.mutex.Unlock()
|
||||
value, ttl, size := computeValue()
|
||||
c.mutex.Lock()
|
||||
hasPaniced = false
|
||||
|
||||
entry.value = value
|
||||
entry.expiration = now.Add(ttl)
|
||||
entry.size = size
|
||||
entry.waitingForComputation -= 1
|
||||
|
||||
// Only broadcast if other goroutines are actually waiting
|
||||
// for a result.
|
||||
if entry.waitingForComputation > 0 {
|
||||
// TODO: Have more than one condition variable so that there are
|
||||
// less unnecessary wakeups.
|
||||
c.cond.Broadcast()
|
||||
}
|
||||
|
||||
c.usedmemory += size
|
||||
c.insertFront(entry)
|
||||
|
||||
// Evict only entries with a size of more than zero.
|
||||
// This is the only loop in the implementation outside of the `Keys`
|
||||
// method.
|
||||
evictionCandidate := c.tail
|
||||
for c.usedmemory > c.maxmemory && evictionCandidate != nil {
|
||||
nextCandidate := evictionCandidate.prev
|
||||
if (evictionCandidate.size > 0 || now.After(evictionCandidate.expiration)) &&
|
||||
evictionCandidate.waitingForComputation == 0 {
|
||||
c.evictEntry(evictionCandidate)
|
||||
}
|
||||
evictionCandidate = nextCandidate
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// Put a new value in the cache. If another goroutine is calling `Get` and
|
||||
// computing the value, this function waits for the computation to be done
|
||||
// before it overwrites the value.
|
||||
func (c *Cache) Put(key string, value interface{}, size int, ttl time.Duration) {
|
||||
now := time.Now()
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
if entry, ok := c.entries[key]; ok {
|
||||
for entry.expiration.IsZero() {
|
||||
entry.waitingForComputation += 1
|
||||
c.cond.Wait()
|
||||
entry.waitingForComputation -= 1
|
||||
}
|
||||
|
||||
c.usedmemory -= entry.size
|
||||
entry.expiration = now.Add(ttl)
|
||||
entry.size = size
|
||||
entry.value = value
|
||||
c.usedmemory += entry.size
|
||||
|
||||
c.unlinkEntry(entry)
|
||||
c.insertFront(entry)
|
||||
return
|
||||
}
|
||||
|
||||
entry := &cacheEntry{
|
||||
key: key,
|
||||
value: value,
|
||||
expiration: now.Add(ttl),
|
||||
}
|
||||
c.entries[key] = entry
|
||||
c.insertFront(entry)
|
||||
}
|
||||
|
||||
// Remove the value at key `key` from the cache.
|
||||
// Return true if the key was in the cache and false
|
||||
// otherwise. It is possible that true is returned even
|
||||
// though the value already expired.
|
||||
// It is possible that false is returned even though the value
|
||||
// will show up in the cache if this function is called on a key
|
||||
// while that key is beeing computed.
|
||||
func (c *Cache) Del(key string) bool {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
if entry, ok := c.entries[key]; ok {
|
||||
return c.evictEntry(entry)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Call f for every entry in the cache. Some sanity checks
|
||||
// and eviction of expired keys are done as well.
|
||||
// The cache is fully locked for the complete duration of this call!
|
||||
func (c *Cache) Keys(f func(key string, val interface{})) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
|
||||
size := 0
|
||||
for key, e := range c.entries {
|
||||
if key != e.key {
|
||||
panic("LRUCACHE/CACHE > key mismatch")
|
||||
}
|
||||
|
||||
if now.After(e.expiration) {
|
||||
if c.evictEntry(e) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if e.prev != nil {
|
||||
if e.prev.next != e {
|
||||
panic("LRUCACHE/CACHE > list corrupted")
|
||||
}
|
||||
}
|
||||
|
||||
if e.next != nil {
|
||||
if e.next.prev != e {
|
||||
panic("LRUCACHE/CACHE > list corrupted")
|
||||
}
|
||||
}
|
||||
|
||||
size += e.size
|
||||
f(key, e.value)
|
||||
}
|
||||
|
||||
if size != c.usedmemory {
|
||||
panic("LRUCACHE/CACHE > size calculations failed")
|
||||
}
|
||||
|
||||
if c.head != nil {
|
||||
if c.tail == nil || c.head.prev != nil {
|
||||
panic("LRUCACHE/CACHE > head/tail corrupted")
|
||||
}
|
||||
}
|
||||
|
||||
if c.tail != nil {
|
||||
if c.head == nil || c.tail.next != nil {
|
||||
panic("LRUCACHE/CACHE > head/tail corrupted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) insertFront(e *cacheEntry) {
|
||||
e.next = c.head
|
||||
c.head = e
|
||||
|
||||
e.prev = nil
|
||||
if e.next != nil {
|
||||
e.next.prev = e
|
||||
}
|
||||
|
||||
if c.tail == nil {
|
||||
c.tail = e
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) unlinkEntry(e *cacheEntry) {
|
||||
if e == c.head {
|
||||
c.head = e.next
|
||||
}
|
||||
if e.prev != nil {
|
||||
e.prev.next = e.next
|
||||
}
|
||||
if e.next != nil {
|
||||
e.next.prev = e.prev
|
||||
}
|
||||
if e == c.tail {
|
||||
c.tail = e.prev
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) evictEntry(e *cacheEntry) bool {
|
||||
if e.waitingForComputation != 0 {
|
||||
// panic("LRUCACHE/CACHE > cannot evict this entry as other goroutines need the value")
|
||||
return false
|
||||
}
|
||||
|
||||
c.unlinkEntry(e)
|
||||
c.usedmemory -= e.size
|
||||
delete(c.entries, e.key)
|
||||
return true
|
||||
}
|
@@ -1,223 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package lrucache
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBasics(t *testing.T) {
|
||||
cache := New(123)
|
||||
|
||||
value1 := cache.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "bar", 1 * time.Second, 0
|
||||
})
|
||||
|
||||
if value1.(string) != "bar" {
|
||||
t.Error("cache returned wrong value")
|
||||
}
|
||||
|
||||
value2 := cache.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
t.Error("value should be cached")
|
||||
return "", 0, 0
|
||||
})
|
||||
|
||||
if value2.(string) != "bar" {
|
||||
t.Error("cache returned wrong value")
|
||||
}
|
||||
|
||||
existed := cache.Del("foo")
|
||||
if !existed {
|
||||
t.Error("delete did not work as expected")
|
||||
}
|
||||
|
||||
value3 := cache.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "baz", 1 * time.Second, 0
|
||||
})
|
||||
|
||||
if value3.(string) != "baz" {
|
||||
t.Error("cache returned wrong value")
|
||||
}
|
||||
|
||||
cache.Keys(func(key string, value interface{}) {
|
||||
if key != "foo" || value.(string) != "baz" {
|
||||
t.Error("cache corrupted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestExpiration(t *testing.T) {
|
||||
cache := New(123)
|
||||
|
||||
failIfCalled := func() (interface{}, time.Duration, int) {
|
||||
t.Error("Value should be cached!")
|
||||
return "", 0, 0
|
||||
}
|
||||
|
||||
val1 := cache.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "bar", 5 * time.Millisecond, 0
|
||||
})
|
||||
val2 := cache.Get("bar", func() (interface{}, time.Duration, int) {
|
||||
return "foo", 20 * time.Millisecond, 0
|
||||
})
|
||||
|
||||
val3 := cache.Get("foo", failIfCalled).(string)
|
||||
val4 := cache.Get("bar", failIfCalled).(string)
|
||||
|
||||
if val1 != val3 || val3 != "bar" || val2 != val4 || val4 != "foo" {
|
||||
t.Error("Wrong values returned")
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
val5 := cache.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "baz", 0, 0
|
||||
})
|
||||
val6 := cache.Get("bar", failIfCalled)
|
||||
|
||||
if val5.(string) != "baz" || val6.(string) != "foo" {
|
||||
t.Error("unexpected values")
|
||||
}
|
||||
|
||||
cache.Keys(func(key string, val interface{}) {
|
||||
if key != "bar" || val.(string) != "foo" {
|
||||
t.Error("wrong value expired")
|
||||
}
|
||||
})
|
||||
|
||||
time.Sleep(15 * time.Millisecond)
|
||||
cache.Keys(func(key string, val interface{}) {
|
||||
t.Error("cache should be empty now")
|
||||
})
|
||||
}
|
||||
|
||||
func TestEviction(t *testing.T) {
|
||||
c := New(100)
|
||||
failIfCalled := func() (interface{}, time.Duration, int) {
|
||||
t.Error("Value should be cached!")
|
||||
return "", 0, 0
|
||||
}
|
||||
|
||||
v1 := c.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "bar", 1 * time.Second, 1000
|
||||
})
|
||||
|
||||
v2 := c.Get("foo", func() (interface{}, time.Duration, int) {
|
||||
return "baz", 1 * time.Second, 1000
|
||||
})
|
||||
|
||||
if v1.(string) != "bar" || v2.(string) != "baz" {
|
||||
t.Error("wrong values returned")
|
||||
}
|
||||
|
||||
c.Keys(func(key string, val interface{}) {
|
||||
t.Error("cache should be empty now")
|
||||
})
|
||||
|
||||
_ = c.Get("A", func() (interface{}, time.Duration, int) {
|
||||
return "a", 1 * time.Second, 50
|
||||
})
|
||||
|
||||
_ = c.Get("B", func() (interface{}, time.Duration, int) {
|
||||
return "b", 1 * time.Second, 50
|
||||
})
|
||||
|
||||
_ = c.Get("A", failIfCalled)
|
||||
_ = c.Get("B", failIfCalled)
|
||||
_ = c.Get("C", func() (interface{}, time.Duration, int) {
|
||||
return "c", 1 * time.Second, 50
|
||||
})
|
||||
|
||||
_ = c.Get("B", failIfCalled)
|
||||
_ = c.Get("C", failIfCalled)
|
||||
|
||||
v4 := c.Get("A", func() (interface{}, time.Duration, int) {
|
||||
return "evicted", 1 * time.Second, 25
|
||||
})
|
||||
|
||||
if v4.(string) != "evicted" {
|
||||
t.Error("value should have been evicted")
|
||||
}
|
||||
|
||||
c.Keys(func(key string, val interface{}) {
|
||||
if key != "A" && key != "C" {
|
||||
t.Errorf("'%s' was not expected", key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// I know that this is a shity test,
|
||||
// time is relative and unreliable.
|
||||
func TestConcurrency(t *testing.T) {
|
||||
c := New(100)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
numActions := 20000
|
||||
numThreads := 4
|
||||
wg.Add(numThreads)
|
||||
|
||||
var concurrentModifications int32 = 0
|
||||
|
||||
for i := 0; i < numThreads; i++ {
|
||||
go func() {
|
||||
for j := 0; j < numActions; j++ {
|
||||
_ = c.Get("key", func() (interface{}, time.Duration, int) {
|
||||
m := atomic.AddInt32(&concurrentModifications, 1)
|
||||
if m != 1 {
|
||||
t.Error("only one goroutine at a time should calculate a value for the same key")
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
atomic.AddInt32(&concurrentModifications, -1)
|
||||
return "value", 3 * time.Millisecond, 1
|
||||
})
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
c.Keys(func(key string, val interface{}) {})
|
||||
}
|
||||
|
||||
func TestPanic(t *testing.T) {
|
||||
c := New(100)
|
||||
|
||||
c.Put("bar", "baz", 3, 1*time.Minute)
|
||||
|
||||
testpanic := func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if r.(string) != "oops" {
|
||||
t.Fatal("unexpected panic value")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
_ = c.Get("foo", func() (value interface{}, ttl time.Duration, size int) {
|
||||
panic("oops")
|
||||
})
|
||||
|
||||
t.Fatal("should have paniced!")
|
||||
}
|
||||
|
||||
testpanic()
|
||||
|
||||
v := c.Get("bar", func() (value interface{}, ttl time.Duration, size int) {
|
||||
t.Fatal("should not be called!")
|
||||
return nil, 0, 0
|
||||
})
|
||||
|
||||
if v.(string) != "baz" {
|
||||
t.Fatal("unexpected value")
|
||||
}
|
||||
|
||||
testpanic()
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package lrucache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// HttpHandler is can be used as HTTP Middleware in order to cache requests,
|
||||
// for example static assets. By default, the request's raw URI is used as key and nothing else.
|
||||
// Results with a status code other than 200 are cached with a TTL of zero seconds,
|
||||
// so basically re-fetched as soon as the current fetch is done and a new request
|
||||
// for that URI is done.
|
||||
type HttpHandler struct {
|
||||
cache *Cache
|
||||
fetcher http.Handler
|
||||
defaultTTL time.Duration
|
||||
|
||||
// Allows overriding the way the cache key is extracted
|
||||
// from the http request. The defailt is to use the RequestURI.
|
||||
CacheKey func(*http.Request) string
|
||||
}
|
||||
|
||||
var _ http.Handler = (*HttpHandler)(nil)
|
||||
|
||||
type cachedResponseWriter struct {
|
||||
w http.ResponseWriter
|
||||
statusCode int
|
||||
buf bytes.Buffer
|
||||
}
|
||||
|
||||
type cachedResponse struct {
|
||||
headers http.Header
|
||||
statusCode int
|
||||
data []byte
|
||||
fetched time.Time
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = (*cachedResponseWriter)(nil)
|
||||
|
||||
func (crw *cachedResponseWriter) Header() http.Header {
|
||||
return crw.w.Header()
|
||||
}
|
||||
|
||||
func (crw *cachedResponseWriter) Write(bytes []byte) (int, error) {
|
||||
return crw.buf.Write(bytes)
|
||||
}
|
||||
|
||||
func (crw *cachedResponseWriter) WriteHeader(statusCode int) {
|
||||
crw.statusCode = statusCode
|
||||
}
|
||||
|
||||
// Returns a new caching HttpHandler. If no entry in the cache is found or it was too old, `fetcher` is called with
|
||||
// a modified http.ResponseWriter and the response is stored in the cache. If `fetcher` sets the "Expires" header,
|
||||
// the ttl is set appropriately (otherwise, the default ttl passed as argument here is used).
|
||||
// `maxmemory` should be in the unit bytes.
|
||||
func NewHttpHandler(maxmemory int, ttl time.Duration, fetcher http.Handler) *HttpHandler {
|
||||
return &HttpHandler{
|
||||
cache: New(maxmemory),
|
||||
defaultTTL: ttl,
|
||||
fetcher: fetcher,
|
||||
CacheKey: func(r *http.Request) string {
|
||||
return r.RequestURI
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// gorilla/mux style middleware:
|
||||
func NewMiddleware(maxmemory int, ttl time.Duration) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return NewHttpHandler(maxmemory, ttl, next)
|
||||
}
|
||||
}
|
||||
|
||||
// Tries to serve a response to r from cache or calls next and stores the response to the cache for the next time.
|
||||
func (h *HttpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
h.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
cr := h.cache.Get(h.CacheKey(r), func() (interface{}, time.Duration, int) {
|
||||
crw := &cachedResponseWriter{
|
||||
w: rw,
|
||||
statusCode: 200,
|
||||
buf: bytes.Buffer{},
|
||||
}
|
||||
|
||||
h.fetcher.ServeHTTP(crw, r)
|
||||
|
||||
cr := &cachedResponse{
|
||||
headers: rw.Header().Clone(),
|
||||
statusCode: crw.statusCode,
|
||||
data: crw.buf.Bytes(),
|
||||
fetched: time.Now(),
|
||||
}
|
||||
cr.headers.Set("Content-Length", strconv.Itoa(len(cr.data)))
|
||||
|
||||
ttl := h.defaultTTL
|
||||
if cr.statusCode != http.StatusOK {
|
||||
ttl = 0
|
||||
} else if cr.headers.Get("Expires") != "" {
|
||||
if expires, err := http.ParseTime(cr.headers.Get("Expires")); err == nil {
|
||||
ttl = time.Until(expires)
|
||||
}
|
||||
}
|
||||
|
||||
return cr, ttl, len(cr.data)
|
||||
}).(*cachedResponse)
|
||||
|
||||
for key, val := range cr.headers {
|
||||
rw.Header()[key] = val
|
||||
}
|
||||
|
||||
cr.headers.Set("Age", strconv.Itoa(int(time.Since(cr.fetched).Seconds())))
|
||||
|
||||
rw.WriteHeader(cr.statusCode)
|
||||
rw.Write(cr.data)
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package lrucache
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHandlerBasics(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodGet, "/test1", nil)
|
||||
rw := httptest.NewRecorder()
|
||||
shouldBeCalled := true
|
||||
|
||||
handler := NewHttpHandler(1000, time.Second, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Write([]byte("Hello World!"))
|
||||
|
||||
if !shouldBeCalled {
|
||||
t.Fatal("fetcher expected to be called")
|
||||
}
|
||||
}))
|
||||
|
||||
handler.ServeHTTP(rw, r)
|
||||
|
||||
if rw.Code != 200 {
|
||||
t.Fatal("unexpected status code")
|
||||
}
|
||||
|
||||
if !bytes.Equal(rw.Body.Bytes(), []byte("Hello World!")) {
|
||||
t.Fatal("unexpected body")
|
||||
}
|
||||
|
||||
rw = httptest.NewRecorder()
|
||||
shouldBeCalled = false
|
||||
handler.ServeHTTP(rw, r)
|
||||
|
||||
if rw.Code != 200 {
|
||||
t.Fatal("unexpected status code")
|
||||
}
|
||||
|
||||
if !bytes.Equal(rw.Body.Bytes(), []byte("Hello World!")) {
|
||||
t.Fatal("unexpected body")
|
||||
}
|
||||
}
|
||||
|
||||
// func TestHandlerExpiration(t *testing.T) {
|
||||
// r := httptest.NewRequest(http.MethodGet, "/test1", nil)
|
||||
// rw := httptest.NewRecorder()
|
||||
// i := 1
|
||||
// now := time.Now()
|
||||
|
||||
// handler := NewHttpHandler(1000, 1*time.Second, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
// rw.Header().Set("Expires", now.Add(10*time.Millisecond).Format(http.TimeFormat))
|
||||
// rw.Write([]byte(strconv.Itoa(i)))
|
||||
// }))
|
||||
|
||||
// handler.ServeHTTP(rw, r)
|
||||
// if !(rw.Body.String() == strconv.Itoa(1)) {
|
||||
// t.Fatal("unexpected body")
|
||||
// }
|
||||
|
||||
// i += 1
|
||||
|
||||
// time.Sleep(11 * time.Millisecond)
|
||||
// rw = httptest.NewRecorder()
|
||||
// handler.ServeHTTP(rw, r)
|
||||
// if !(rw.Body.String() == strconv.Itoa(1)) {
|
||||
// t.Fatal("unexpected body")
|
||||
// }
|
||||
// }
|
@@ -1,123 +0,0 @@
|
||||
package resampler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
)
|
||||
|
||||
func SimpleResampler(data []schema.Float, old_frequency int64, new_frequency int64) ([]schema.Float, int64, error) {
|
||||
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
|
||||
return data, old_frequency, nil
|
||||
}
|
||||
|
||||
if new_frequency%old_frequency != 0 {
|
||||
return nil, 0, errors.New("new sampling frequency should be multiple of the old frequency")
|
||||
}
|
||||
|
||||
var step int = int(new_frequency / old_frequency)
|
||||
var new_data_length = len(data) / step
|
||||
|
||||
if new_data_length == 0 || len(data) < 100 || new_data_length >= len(data) {
|
||||
return data, old_frequency, nil
|
||||
}
|
||||
|
||||
new_data := make([]schema.Float, new_data_length)
|
||||
|
||||
for i := 0; i < new_data_length; i++ {
|
||||
new_data[i] = data[i*step]
|
||||
}
|
||||
|
||||
return new_data, new_frequency, nil
|
||||
}
|
||||
|
||||
// Inspired by one of the algorithms from https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf
|
||||
// Adapted from https://github.com/haoel/downsampling/blob/master/core/lttb.go
|
||||
func LargestTriangleThreeBucket(data []schema.Float, old_frequency int, new_frequency int) ([]schema.Float, int, error) {
|
||||
|
||||
if old_frequency == 0 || new_frequency == 0 || new_frequency <= old_frequency {
|
||||
return data, old_frequency, nil
|
||||
}
|
||||
|
||||
if new_frequency%old_frequency != 0 {
|
||||
return nil, 0, errors.New(fmt.Sprintf("new sampling frequency : %d should be multiple of the old frequency : %d", new_frequency, old_frequency))
|
||||
}
|
||||
|
||||
var step int = int(new_frequency / old_frequency)
|
||||
var new_data_length = len(data) / step
|
||||
|
||||
if new_data_length == 0 || len(data) < 100 || new_data_length >= len(data) {
|
||||
return data, old_frequency, nil
|
||||
}
|
||||
|
||||
new_data := make([]schema.Float, 0, new_data_length)
|
||||
|
||||
// Bucket size. Leave room for start and end data points
|
||||
bucketSize := float64(len(data)-2) / float64(new_data_length-2)
|
||||
|
||||
new_data = append(new_data, data[0]) // Always add the first point
|
||||
|
||||
// We have 3 pointers represent for
|
||||
// > bucketLow - the current bucket's beginning location
|
||||
// > bucketMiddle - the current bucket's ending location,
|
||||
// also the beginning location of next bucket
|
||||
// > bucketHight - the next bucket's ending location.
|
||||
bucketLow := 1
|
||||
bucketMiddle := int(math.Floor(bucketSize)) + 1
|
||||
|
||||
var prevMaxAreaPoint int
|
||||
|
||||
for i := 0; i < new_data_length-2; i++ {
|
||||
|
||||
bucketHigh := int(math.Floor(float64(i+2)*bucketSize)) + 1
|
||||
if bucketHigh >= len(data)-1 {
|
||||
bucketHigh = len(data) - 2
|
||||
}
|
||||
|
||||
// Calculate point average for next bucket (containing c)
|
||||
avgPointX, avgPointY := calculateAverageDataPoint(data[bucketMiddle:bucketHigh+1], int64(bucketMiddle))
|
||||
|
||||
// Get the range for current bucket
|
||||
currBucketStart := bucketLow
|
||||
currBucketEnd := bucketMiddle
|
||||
|
||||
// Point a
|
||||
pointX := prevMaxAreaPoint
|
||||
pointY := data[prevMaxAreaPoint]
|
||||
|
||||
maxArea := -1.0
|
||||
|
||||
var maxAreaPoint int
|
||||
flag_ := 0
|
||||
for ; currBucketStart < currBucketEnd; currBucketStart++ {
|
||||
|
||||
area := calculateTriangleArea(schema.Float(pointX), pointY, avgPointX, avgPointY, schema.Float(currBucketStart), data[currBucketStart])
|
||||
if area > maxArea {
|
||||
maxArea = area
|
||||
maxAreaPoint = currBucketStart
|
||||
}
|
||||
if math.IsNaN(float64(avgPointY)) {
|
||||
flag_ = 1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if flag_ == 1 {
|
||||
new_data = append(new_data, schema.NaN) // Pick this point from the bucket
|
||||
|
||||
} else {
|
||||
new_data = append(new_data, data[maxAreaPoint]) // Pick this point from the bucket
|
||||
}
|
||||
prevMaxAreaPoint = maxAreaPoint // This MaxArea point is the next's prevMAxAreaPoint
|
||||
|
||||
//move to the next window
|
||||
bucketLow = bucketMiddle
|
||||
bucketMiddle = bucketHigh
|
||||
}
|
||||
|
||||
new_data = append(new_data, data[len(data)-1]) // Always add last
|
||||
|
||||
return new_data, new_frequency, nil
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package resampler
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
||||
)
|
||||
|
||||
func calculateTriangleArea(paX, paY, pbX, pbY, pcX, pcY schema.Float) float64 {
|
||||
area := ((paX-pcX)*(pbY-paY) - (paX-pbX)*(pcY-paY)) * 0.5
|
||||
return math.Abs(float64(area))
|
||||
}
|
||||
|
||||
func calculateAverageDataPoint(points []schema.Float, xStart int64) (avgX schema.Float, avgY schema.Float) {
|
||||
flag := 0
|
||||
for _, point := range points {
|
||||
avgX += schema.Float(xStart)
|
||||
avgY += point
|
||||
xStart++
|
||||
if math.IsNaN(float64(point)) {
|
||||
flag = 1
|
||||
}
|
||||
}
|
||||
|
||||
l := schema.Float(len(points))
|
||||
|
||||
avgX /= l
|
||||
avgY /= l
|
||||
|
||||
if flag == 1 {
|
||||
return avgX, schema.NaN
|
||||
} else {
|
||||
return avgX, avgY
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// All rights reserved. This file is part of cc-backend.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package runtimeEnv
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
cclog "github.com/ClusterCockpit/cc-lib/ccLogger"
|
||||
)
|
||||
|
||||
// Changes the processes user and group to that
|
||||
@@ -23,13 +23,13 @@ func DropPrivileges(username string, group string) error {
|
||||
if group != "" {
|
||||
g, err := user.LookupGroup(group)
|
||||
if err != nil {
|
||||
log.Warn("Error while looking up group")
|
||||
cclog.Warn("Error while looking up group")
|
||||
return err
|
||||
}
|
||||
|
||||
gid, _ := strconv.Atoi(g.Gid)
|
||||
if err := syscall.Setgid(gid); err != nil {
|
||||
log.Warn("Error while setting gid")
|
||||
cclog.Warn("Error while setting gid")
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -37,13 +37,13 @@ func DropPrivileges(username string, group string) error {
|
||||
if username != "" {
|
||||
u, err := user.Lookup(username)
|
||||
if err != nil {
|
||||
log.Warn("Error while looking up user")
|
||||
cclog.Warn("Error while looking up user")
|
||||
return err
|
||||
}
|
||||
|
||||
uid, _ := strconv.Atoi(u.Uid)
|
||||
if err := syscall.Setuid(uid); err != nil {
|
||||
log.Warn("Error while setting uid")
|
||||
cclog.Warn("Error while setting uid")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@@ -1,249 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Accelerator struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
type Topology struct {
|
||||
Node []int `json:"node"`
|
||||
Socket [][]int `json:"socket"`
|
||||
MemoryDomain [][]int `json:"memoryDomain"`
|
||||
Die [][]*int `json:"die,omitempty"`
|
||||
Core [][]int `json:"core"`
|
||||
Accelerators []*Accelerator `json:"accelerators,omitempty"`
|
||||
}
|
||||
|
||||
type MetricValue struct {
|
||||
Unit Unit `json:"unit"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
type SubCluster struct {
|
||||
Name string `json:"name"`
|
||||
Nodes string `json:"nodes"`
|
||||
ProcessorType string `json:"processorType"`
|
||||
Topology Topology `json:"topology"`
|
||||
FlopRateScalar MetricValue `json:"flopRateScalar"`
|
||||
FlopRateSimd MetricValue `json:"flopRateSimd"`
|
||||
MemoryBandwidth MetricValue `json:"memoryBandwidth"`
|
||||
MetricConfig []MetricConfig `json:"metricConfig,omitempty"`
|
||||
Footprint []string `json:"footprint,omitempty"`
|
||||
EnergyFootprint []string `json:"energyFootprint,omitempty"`
|
||||
SocketsPerNode int `json:"socketsPerNode"`
|
||||
CoresPerSocket int `json:"coresPerSocket"`
|
||||
ThreadsPerCore int `json:"threadsPerCore"`
|
||||
}
|
||||
|
||||
type Metric struct {
|
||||
Name string `json:"name"`
|
||||
Unit Unit `json:"unit"`
|
||||
Peak float64 `json:"peak"`
|
||||
Normal float64 `json:"normal"`
|
||||
Caution float64 `json:"caution"`
|
||||
Alert float64 `json:"alert"`
|
||||
}
|
||||
|
||||
type SubClusterConfig struct {
|
||||
Metric
|
||||
Footprint string `json:"footprint,omitempty"`
|
||||
Energy string `json:"energy"`
|
||||
Remove bool `json:"remove"`
|
||||
LowerIsBetter bool `json:"lowerIsBetter"`
|
||||
}
|
||||
|
||||
type MetricConfig struct {
|
||||
Metric
|
||||
Energy string `json:"energy"`
|
||||
Scope MetricScope `json:"scope"`
|
||||
Aggregation string `json:"aggregation"`
|
||||
Footprint string `json:"footprint,omitempty"`
|
||||
SubClusters []*SubClusterConfig `json:"subClusters,omitempty"`
|
||||
Timestep int `json:"timestep"`
|
||||
LowerIsBetter bool `json:"lowerIsBetter"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
Name string `json:"name"`
|
||||
MetricConfig []*MetricConfig `json:"metricConfig"`
|
||||
SubClusters []*SubCluster `json:"subClusters"`
|
||||
}
|
||||
|
||||
type ClusterSupport struct {
|
||||
Cluster string `json:"cluster"`
|
||||
SubClusters []string `json:"subclusters"`
|
||||
}
|
||||
|
||||
type GlobalMetricListItem struct {
|
||||
Name string `json:"name"`
|
||||
Unit Unit `json:"unit"`
|
||||
Scope MetricScope `json:"scope"`
|
||||
Footprint string `json:"footprint,omitempty"`
|
||||
Availability []ClusterSupport `json:"availability"`
|
||||
}
|
||||
|
||||
// Return a list of socket IDs given a list of hwthread IDs. Even if just one
|
||||
// hwthread is in that socket, add it to the list. If no hwthreads other than
|
||||
// those in the argument list are assigned to one of the sockets in the first
|
||||
// return value, return true as the second value. TODO: Optimize this, there
|
||||
// must be a more efficient way/algorithm.
|
||||
func (topo *Topology) GetSocketsFromHWThreads(
|
||||
hwthreads []int,
|
||||
) (sockets []int, exclusive bool) {
|
||||
socketsMap := map[int]int{}
|
||||
for _, hwthread := range hwthreads {
|
||||
for socket, hwthreadsInSocket := range topo.Socket {
|
||||
for _, hwthreadInSocket := range hwthreadsInSocket {
|
||||
if hwthread == hwthreadInSocket {
|
||||
socketsMap[socket] += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exclusive = true
|
||||
hwthreadsPerSocket := len(topo.Node) / len(topo.Socket)
|
||||
sockets = make([]int, 0, len(socketsMap))
|
||||
for socket, count := range socketsMap {
|
||||
sockets = append(sockets, socket)
|
||||
exclusive = exclusive && count == hwthreadsPerSocket
|
||||
}
|
||||
|
||||
return sockets, exclusive
|
||||
}
|
||||
|
||||
// Return a list of socket IDs given a list of core IDs. Even if just one
|
||||
// core is in that socket, add it to the list. If no cores other than
|
||||
// those in the argument list are assigned to one of the sockets in the first
|
||||
// return value, return true as the second value. TODO: Optimize this, there
|
||||
// must be a more efficient way/algorithm.
|
||||
func (topo *Topology) GetSocketsFromCores(
|
||||
cores []int,
|
||||
) (sockets []int, exclusive bool) {
|
||||
socketsMap := map[int]int{}
|
||||
for _, core := range cores {
|
||||
for _, hwthreadInCore := range topo.Core[core] {
|
||||
for socket, hwthreadsInSocket := range topo.Socket {
|
||||
for _, hwthreadInSocket := range hwthreadsInSocket {
|
||||
if hwthreadInCore == hwthreadInSocket {
|
||||
socketsMap[socket] += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exclusive = true
|
||||
hwthreadsPerSocket := len(topo.Node) / len(topo.Socket)
|
||||
sockets = make([]int, 0, len(socketsMap))
|
||||
for socket, count := range socketsMap {
|
||||
sockets = append(sockets, socket)
|
||||
exclusive = exclusive && count == hwthreadsPerSocket
|
||||
}
|
||||
|
||||
return sockets, exclusive
|
||||
}
|
||||
|
||||
// Return a list of core IDs given a list of hwthread IDs. Even if just one
|
||||
// hwthread is in that core, add it to the list. If no hwthreads other than
|
||||
// those in the argument list are assigned to one of the cores in the first
|
||||
// return value, return true as the second value. TODO: Optimize this, there
|
||||
// must be a more efficient way/algorithm.
|
||||
func (topo *Topology) GetCoresFromHWThreads(
|
||||
hwthreads []int,
|
||||
) (cores []int, exclusive bool) {
|
||||
coresMap := map[int]int{}
|
||||
for _, hwthread := range hwthreads {
|
||||
for core, hwthreadsInCore := range topo.Core {
|
||||
for _, hwthreadInCore := range hwthreadsInCore {
|
||||
if hwthread == hwthreadInCore {
|
||||
coresMap[core] += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exclusive = true
|
||||
hwthreadsPerCore := len(topo.Node) / len(topo.Core)
|
||||
cores = make([]int, 0, len(coresMap))
|
||||
for core, count := range coresMap {
|
||||
cores = append(cores, core)
|
||||
exclusive = exclusive && count == hwthreadsPerCore
|
||||
}
|
||||
|
||||
return cores, exclusive
|
||||
}
|
||||
|
||||
// Return a list of memory domain IDs given a list of hwthread IDs. Even if
|
||||
// just one hwthread is in that memory domain, add it to the list. If no
|
||||
// hwthreads other than those in the argument list are assigned to one of the
|
||||
// memory domains in the first return value, return true as the second value.
|
||||
// TODO: Optimize this, there must be a more efficient way/algorithm.
|
||||
func (topo *Topology) GetMemoryDomainsFromHWThreads(
|
||||
hwthreads []int,
|
||||
) (memDoms []int, exclusive bool) {
|
||||
memDomsMap := map[int]int{}
|
||||
for _, hwthread := range hwthreads {
|
||||
for memDom, hwthreadsInmemDom := range topo.MemoryDomain {
|
||||
for _, hwthreadInmemDom := range hwthreadsInmemDom {
|
||||
if hwthread == hwthreadInmemDom {
|
||||
memDomsMap[memDom] += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exclusive = true
|
||||
hwthreadsPermemDom := len(topo.Node) / len(topo.MemoryDomain)
|
||||
memDoms = make([]int, 0, len(memDomsMap))
|
||||
for memDom, count := range memDomsMap {
|
||||
memDoms = append(memDoms, memDom)
|
||||
exclusive = exclusive && count == hwthreadsPermemDom
|
||||
}
|
||||
|
||||
return memDoms, exclusive
|
||||
}
|
||||
|
||||
// Temporary fix to convert back from int id to string id for accelerators
|
||||
func (topo *Topology) GetAcceleratorID(id int) (string, error) {
|
||||
if id < 0 {
|
||||
fmt.Printf("ID smaller than 0!\n")
|
||||
return topo.Accelerators[0].ID, nil
|
||||
} else if id < len(topo.Accelerators) {
|
||||
return topo.Accelerators[id].ID, nil
|
||||
} else {
|
||||
return "", fmt.Errorf("index %d out of range", id)
|
||||
}
|
||||
}
|
||||
|
||||
// Return list of hardware (string) accelerator IDs
|
||||
func (topo *Topology) GetAcceleratorIDs() []string {
|
||||
accels := make([]string, 0)
|
||||
for _, accel := range topo.Accelerators {
|
||||
accels = append(accels, accel.ID)
|
||||
}
|
||||
return accels
|
||||
}
|
||||
|
||||
// Outdated? Or: Return indices of accelerators in parent array?
|
||||
func (topo *Topology) GetAcceleratorIDsAsInt() ([]int, error) {
|
||||
accels := make([]int, 0)
|
||||
for _, accel := range topo.Accelerators {
|
||||
id, err := strconv.Atoi(accel.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
accels = append(accels, id)
|
||||
}
|
||||
return accels, nil
|
||||
}
|
@@ -1,180 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LdapConfig struct {
|
||||
Url string `json:"url"`
|
||||
UserBase string `json:"user_base"`
|
||||
SearchDN string `json:"search_dn"`
|
||||
UserBind string `json:"user_bind"`
|
||||
UserFilter string `json:"user_filter"`
|
||||
UserAttr string `json:"username_attr"`
|
||||
SyncInterval string `json:"sync_interval"` // Parsed using time.ParseDuration.
|
||||
SyncDelOldUsers bool `json:"sync_del_old_users"`
|
||||
|
||||
// Should an non-existent user be added to the DB if user exists in ldap directory
|
||||
SyncUserOnLogin bool `json:"syncUserOnLogin"`
|
||||
}
|
||||
|
||||
type OpenIDConfig struct {
|
||||
Provider string `json:"provider"`
|
||||
SyncUserOnLogin bool `json:"syncUserOnLogin"`
|
||||
UpdateUserOnLogin bool `json:"updateUserOnLogin"`
|
||||
}
|
||||
|
||||
type JWTAuthConfig struct {
|
||||
// Specifies for how long a JWT token shall be valid
|
||||
// as a string parsable by time.ParseDuration().
|
||||
MaxAge string `json:"max-age"`
|
||||
|
||||
// Specifies which cookie should be checked for a JWT token (if no authorization header is present)
|
||||
CookieName string `json:"cookieName"`
|
||||
|
||||
// Deny login for users not in database (but defined in JWT).
|
||||
// Ignore user roles defined in JWTs ('roles' claim), get them from db.
|
||||
ValidateUser bool `json:"validateUser"`
|
||||
|
||||
// Specifies which issuer should be accepted when validating external JWTs ('iss' claim)
|
||||
TrustedIssuer string `json:"trustedIssuer"`
|
||||
|
||||
// Should an non-existent user be added to the DB based on the information in the token
|
||||
SyncUserOnLogin bool `json:"syncUserOnLogin"`
|
||||
|
||||
// Should an existent user be updated in the DB based on the information in the token
|
||||
UpdateUserOnLogin bool `json:"updateUserOnLogin"`
|
||||
}
|
||||
|
||||
type IntRange struct {
|
||||
From int `json:"from"`
|
||||
To int `json:"to"`
|
||||
}
|
||||
|
||||
type TimeRange struct {
|
||||
From *time.Time `json:"from"`
|
||||
To *time.Time `json:"to"`
|
||||
Range string `json:"range,omitempty"`
|
||||
}
|
||||
|
||||
type FilterRanges struct {
|
||||
Duration *IntRange `json:"duration"`
|
||||
NumNodes *IntRange `json:"numNodes"`
|
||||
StartTime *TimeRange `json:"startTime"`
|
||||
}
|
||||
|
||||
type ClusterConfig struct {
|
||||
Name string `json:"name"`
|
||||
FilterRanges *FilterRanges `json:"filterRanges"`
|
||||
MetricDataRepository json.RawMessage `json:"metricDataRepository"`
|
||||
}
|
||||
|
||||
type Retention struct {
|
||||
Policy string `json:"policy"`
|
||||
Location string `json:"location"`
|
||||
Age int `json:"age"`
|
||||
IncludeDB bool `json:"includeDB"`
|
||||
}
|
||||
|
||||
type ResampleConfig struct {
|
||||
// Array of resampling target resolutions, in seconds; Example: [600,300,60]
|
||||
Resolutions []int `json:"resolutions"`
|
||||
// Trigger next zoom level at less than this many visible datapoints
|
||||
Trigger int `json:"trigger"`
|
||||
}
|
||||
|
||||
type CronFrequency struct {
|
||||
// Duration Update Worker [Defaults to '2m']
|
||||
CommitJobWorker string `json:"commit-job-worker"`
|
||||
// Duration Update Worker [Defaults to '5m']
|
||||
DurationWorker string `json:"duration-worker"`
|
||||
// Metric-Footprint Update Worker [Defaults to '10m']
|
||||
FootprintWorker string `json:"footprint-worker"`
|
||||
}
|
||||
|
||||
// Format of the configuration (file). See below for the defaults.
|
||||
type ProgramConfig struct {
|
||||
// Address where the http (or https) server will listen on (for example: 'localhost:80').
|
||||
Addr string `json:"addr"`
|
||||
|
||||
// Addresses from which secured admin API endpoints can be reached, can be wildcard "*"
|
||||
ApiAllowedIPs []string `json:"apiAllowedIPs"`
|
||||
|
||||
// Drop root permissions once .env was read and the port was taken.
|
||||
User string `json:"user"`
|
||||
Group string `json:"group"`
|
||||
|
||||
// Disable authentication (for everything: API, Web-UI, ...)
|
||||
DisableAuthentication bool `json:"disable-authentication"`
|
||||
|
||||
// If `embed-static-files` is true (default), the frontend files are directly
|
||||
// embeded into the go binary and expected to be in web/frontend. Only if
|
||||
// it is false the files in `static-files` are served instead.
|
||||
EmbedStaticFiles bool `json:"embed-static-files"`
|
||||
StaticFiles string `json:"static-files"`
|
||||
|
||||
// 'sqlite3' or 'mysql' (mysql will work for mariadb as well)
|
||||
DBDriver string `json:"db-driver"`
|
||||
|
||||
// For sqlite3 a filename, for mysql a DSN in this format: https://github.com/go-sql-driver/mysql#dsn-data-source-name (Without query parameters!).
|
||||
DB string `json:"db"`
|
||||
|
||||
// Config for job archive
|
||||
Archive json.RawMessage `json:"archive"`
|
||||
|
||||
// Keep all metric data in the metric data repositories,
|
||||
// do not write to the job-archive.
|
||||
DisableArchive bool `json:"disable-archive"`
|
||||
|
||||
EnableJobTaggers bool `json:"enable-job-taggers"`
|
||||
|
||||
// Validate json input against schema
|
||||
Validate bool `json:"validate"`
|
||||
|
||||
// For LDAP Authentication and user synchronisation.
|
||||
LdapConfig *LdapConfig `json:"ldap"`
|
||||
JwtConfig *JWTAuthConfig `json:"jwts"`
|
||||
OpenIDConfig *OpenIDConfig `json:"oidc"`
|
||||
|
||||
// If 0 or empty, the session does not expire!
|
||||
SessionMaxAge string `json:"session-max-age"`
|
||||
|
||||
// If both those options are not empty, use HTTPS using those certificates.
|
||||
HttpsCertFile string `json:"https-cert-file"`
|
||||
HttpsKeyFile string `json:"https-key-file"`
|
||||
|
||||
// If not the empty string and `addr` does not end in ":80",
|
||||
// redirect every request incoming at port 80 to that url.
|
||||
RedirectHttpTo string `json:"redirect-http-to"`
|
||||
|
||||
// If overwritten, at least all the options in the defaults below must
|
||||
// be provided! Most options here can be overwritten by the user.
|
||||
UiDefaults map[string]any `json:"ui-defaults"`
|
||||
|
||||
// If exists, will enable dynamic zoom in frontend metric plots using the configured values
|
||||
EnableResampling *ResampleConfig `json:"enable-resampling"`
|
||||
|
||||
// Where to store MachineState files
|
||||
MachineStateDir string `json:"machine-state-dir"`
|
||||
|
||||
// If not zero, automatically mark jobs as stopped running X seconds longer than their walltime.
|
||||
StopJobsExceedingWalltime int `json:"stop-jobs-exceeding-walltime"`
|
||||
|
||||
// Defines time X in seconds in which jobs are considered to be "short" and will be filtered in specific views.
|
||||
ShortRunningJobsDuration int `json:"short-running-jobs-duration"`
|
||||
|
||||
// Energy Mix CO2 Emission Constant [g/kWh]
|
||||
// If entered, displays estimated CO2 emission for job based on jobs totalEnergy
|
||||
EmissionConstant int `json:"emission-constant"`
|
||||
|
||||
// Frequency of cron job workers
|
||||
CronFrequency *CronFrequency `json:"cron-frequency"`
|
||||
|
||||
// Array of Clusters
|
||||
Clusters []*ClusterConfig `json:"clusters"`
|
||||
}
|
@@ -1,131 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
)
|
||||
|
||||
// A custom float type is used so that (Un)MarshalJSON and
|
||||
// (Un)MarshalGQL can be overloaded and NaN/null can be used.
|
||||
// The default behaviour of putting every nullable value behind
|
||||
// a pointer has a bigger overhead.
|
||||
type Float float64
|
||||
|
||||
var NaN Float = Float(math.NaN())
|
||||
var nullAsBytes []byte = []byte("null")
|
||||
|
||||
func (f Float) IsNaN() bool {
|
||||
return math.IsNaN(float64(f))
|
||||
}
|
||||
|
||||
// NaN will be serialized to `null`.
|
||||
func (f Float) MarshalJSON() ([]byte, error) {
|
||||
if f.IsNaN() {
|
||||
return nullAsBytes, nil
|
||||
}
|
||||
|
||||
return strconv.AppendFloat(make([]byte, 0, 10), float64(f), 'f', 2, 64), nil
|
||||
}
|
||||
|
||||
// `null` will be unserialized to NaN.
|
||||
func (f *Float) UnmarshalJSON(input []byte) error {
|
||||
s := string(input)
|
||||
if s == "null" {
|
||||
*f = NaN
|
||||
return nil
|
||||
}
|
||||
|
||||
val, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
log.Warn("Error while parsing custom float")
|
||||
return err
|
||||
}
|
||||
*f = Float(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalGQL implements the graphql.Unmarshaler interface.
|
||||
func (f *Float) UnmarshalGQL(v interface{}) error {
|
||||
f64, ok := v.(float64)
|
||||
if !ok {
|
||||
return errors.New("invalid Float scalar")
|
||||
}
|
||||
|
||||
*f = Float(f64)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalGQL implements the graphql.Marshaler interface.
|
||||
// NaN will be serialized to `null`.
|
||||
func (f Float) MarshalGQL(w io.Writer) {
|
||||
if f.IsNaN() {
|
||||
w.Write(nullAsBytes)
|
||||
} else {
|
||||
w.Write(strconv.AppendFloat(make([]byte, 0, 10), float64(f), 'f', 2, 64))
|
||||
}
|
||||
}
|
||||
|
||||
// Only used via REST-API, not via GraphQL.
|
||||
// This uses a lot less allocations per series,
|
||||
// but it turns out that the performance increase
|
||||
// from using this is not that big.
|
||||
func (s *Series) MarshalJSON() ([]byte, error) {
|
||||
buf := make([]byte, 0, 512+len(s.Data)*8)
|
||||
buf = append(buf, `{"hostname":"`...)
|
||||
buf = append(buf, s.Hostname...)
|
||||
buf = append(buf, '"')
|
||||
if s.Id != nil {
|
||||
buf = append(buf, `,"id":"`...)
|
||||
buf = append(buf, *s.Id...)
|
||||
buf = append(buf, '"')
|
||||
}
|
||||
buf = append(buf, `,"statistics":{"min":`...)
|
||||
buf = strconv.AppendFloat(buf, s.Statistics.Min, 'f', 2, 64)
|
||||
buf = append(buf, `,"avg":`...)
|
||||
buf = strconv.AppendFloat(buf, s.Statistics.Avg, 'f', 2, 64)
|
||||
buf = append(buf, `,"max":`...)
|
||||
buf = strconv.AppendFloat(buf, s.Statistics.Max, 'f', 2, 64)
|
||||
buf = append(buf, '}')
|
||||
buf = append(buf, `,"data":[`...)
|
||||
for i := 0; i < len(s.Data); i++ {
|
||||
if i != 0 {
|
||||
buf = append(buf, ',')
|
||||
}
|
||||
|
||||
if s.Data[i].IsNaN() {
|
||||
buf = append(buf, `null`...)
|
||||
} else {
|
||||
buf = strconv.AppendFloat(buf, float64(s.Data[i]), 'f', 2, 32)
|
||||
}
|
||||
}
|
||||
buf = append(buf, ']', '}')
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func ConvertFloatToFloat64(s []Float) []float64 {
|
||||
fp := make([]float64, len(s))
|
||||
|
||||
for i, val := range s {
|
||||
fp[i] = float64(val)
|
||||
}
|
||||
|
||||
return fp
|
||||
}
|
||||
|
||||
func GetFloat64ToFloat(s []float64) []Float {
|
||||
fp := make([]Float, len(s))
|
||||
|
||||
for i, val := range s {
|
||||
fp[i] = Float(val)
|
||||
}
|
||||
|
||||
return fp
|
||||
}
|
@@ -1,153 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Job struct type
|
||||
//
|
||||
// This type contains all metadata of a HPC job.
|
||||
//
|
||||
// Job model
|
||||
// @Description Information of a HPC job.
|
||||
|
||||
type Job struct {
|
||||
Cluster string `json:"cluster" db:"cluster" example:"fritz"`
|
||||
SubCluster string `json:"subCluster" db:"subcluster" example:"main"`
|
||||
Partition string `json:"partition,omitempty" db:"cluster_partition" example:"main"`
|
||||
Project string `json:"project" db:"project" example:"abcd200"`
|
||||
User string `json:"user" db:"hpc_user" example:"abcd100h"`
|
||||
State JobState `json:"jobState" db:"job_state" example:"completed" enums:"completed,failed,cancelled,stopped,timeout,out_of_memory"`
|
||||
Tags []*Tag `json:"tags,omitempty"`
|
||||
RawEnergyFootprint []byte `json:"-" db:"energy_footprint"`
|
||||
RawFootprint []byte `json:"-" db:"footprint"`
|
||||
RawMetaData []byte `json:"-" db:"meta_data"`
|
||||
RawResources []byte `json:"-" db:"resources"`
|
||||
Resources []*Resource `json:"resources"`
|
||||
EnergyFootprint map[string]float64 `json:"energyFootprint"`
|
||||
Footprint map[string]float64 `json:"footprint"`
|
||||
MetaData map[string]string `json:"metaData"`
|
||||
ConcurrentJobs JobLinkResultList `json:"concurrentJobs"`
|
||||
Energy float64 `json:"energy" db:"energy"`
|
||||
ArrayJobId int64 `json:"arrayJobId,omitempty" db:"array_job_id" example:"123000"`
|
||||
Walltime int64 `json:"walltime,omitempty" db:"walltime" example:"86400" minimum:"1"`
|
||||
RequestedMemory int64 `json:"requestedMemory,omitempty" db:"requested_memory" example:"128000" minimum:"1"` // in MB
|
||||
JobID int64 `json:"jobId" db:"job_id" example:"123000"`
|
||||
Duration int32 `json:"duration" db:"duration" example:"43200" minimum:"1"`
|
||||
SMT int32 `json:"smt,omitempty" db:"smt" example:"4"`
|
||||
MonitoringStatus int32 `json:"monitoringStatus,omitempty" db:"monitoring_status" example:"1" minimum:"0" maximum:"3"`
|
||||
Exclusive int32 `json:"exclusive" db:"exclusive" example:"1" minimum:"0" maximum:"2"`
|
||||
NumAcc int32 `json:"numAcc,omitempty" db:"num_acc" example:"2" minimum:"1"`
|
||||
NumHWThreads int32 `json:"numHwthreads,omitempty" db:"num_hwthreads" example:"20" minimum:"1"`
|
||||
NumNodes int32 `json:"numNodes" db:"num_nodes" example:"2" minimum:"1"`
|
||||
Statistics map[string]JobStatistics `json:"statistics"`
|
||||
ID *int64 `json:"id,omitempty" db:"id"`
|
||||
StartTime int64 `json:"startTime" db:"start_time" example:"1649723812"`
|
||||
}
|
||||
|
||||
type JobLink struct {
|
||||
ID int64 `json:"id"`
|
||||
JobID int64 `json:"jobId"`
|
||||
}
|
||||
|
||||
type JobLinkResultList struct {
|
||||
Items []*JobLink `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
const (
|
||||
MonitoringStatusDisabled int32 = 0
|
||||
MonitoringStatusRunningOrArchiving int32 = 1
|
||||
MonitoringStatusArchivingFailed int32 = 2
|
||||
MonitoringStatusArchivingSuccessful int32 = 3
|
||||
)
|
||||
|
||||
// var JobDefaults Job = Job{
|
||||
// Exclusive: 1,
|
||||
// MonitoringStatus: MonitoringStatusRunningOrArchiving,
|
||||
// }
|
||||
|
||||
type Unit struct {
|
||||
Base string `json:"base"`
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
}
|
||||
|
||||
// JobStatistics model
|
||||
// @Description Specification for job metric statistics.
|
||||
type JobStatistics struct {
|
||||
Unit Unit `json:"unit"`
|
||||
Avg float64 `json:"avg" example:"2500" minimum:"0"` // Job metric average
|
||||
Min float64 `json:"min" example:"2000" minimum:"0"` // Job metric minimum
|
||||
Max float64 `json:"max" example:"3000" minimum:"0"` // Job metric maximum
|
||||
}
|
||||
|
||||
// Tag model
|
||||
// @Description Defines a tag using name and type.
|
||||
type Tag struct {
|
||||
Type string `json:"type" db:"tag_type" example:"Debug"`
|
||||
Name string `json:"name" db:"tag_name" example:"Testjob"`
|
||||
Scope string `json:"scope" db:"tag_scope" example:"global"`
|
||||
ID int64 `json:"id" db:"id"`
|
||||
}
|
||||
|
||||
// Resource model
|
||||
// @Description A resource used by a job
|
||||
type Resource struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Configuration string `json:"configuration,omitempty"`
|
||||
HWThreads []int `json:"hwthreads,omitempty"`
|
||||
Accelerators []string `json:"accelerators,omitempty"`
|
||||
}
|
||||
|
||||
type JobState string
|
||||
|
||||
const (
|
||||
JobStateRunning JobState = "running"
|
||||
JobStateCompleted JobState = "completed"
|
||||
JobStateFailed JobState = "failed"
|
||||
JobStateCancelled JobState = "cancelled"
|
||||
JobStateStopped JobState = "stopped"
|
||||
JobStateTimeout JobState = "timeout"
|
||||
JobStatePreempted JobState = "preempted"
|
||||
JobStateOutOfMemory JobState = "out_of_memory"
|
||||
)
|
||||
|
||||
func (j Job) GoString() string {
|
||||
return fmt.Sprintf("Job{ID:%d, StartTime:%d, JobID:%v, BaseJob:%v}",
|
||||
j.ID, j.StartTime, j.JobID, j)
|
||||
}
|
||||
|
||||
func (e *JobState) UnmarshalGQL(v any) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("SCHEMA/JOB > enums must be strings")
|
||||
}
|
||||
|
||||
*e = JobState(str)
|
||||
if !e.Valid() {
|
||||
return errors.New("SCHEMA/JOB > invalid job state")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e JobState) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprintf(w, "\"%s\"", e)
|
||||
}
|
||||
|
||||
func (e JobState) Valid() bool {
|
||||
return e == JobStateRunning ||
|
||||
e == JobStateCompleted ||
|
||||
e == JobStateFailed ||
|
||||
e == JobStateCancelled ||
|
||||
e == JobStateStopped ||
|
||||
e == JobStateTimeout ||
|
||||
e == JobStatePreempted ||
|
||||
e == JobStateOutOfMemory
|
||||
}
|
@@ -1,368 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"sort"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/util"
|
||||
)
|
||||
|
||||
type JobData map[string]map[MetricScope]*JobMetric
|
||||
type ScopedJobStats map[string]map[MetricScope][]*ScopedStats
|
||||
|
||||
type JobMetric struct {
|
||||
StatisticsSeries *StatsSeries `json:"statisticsSeries,omitempty"`
|
||||
Unit Unit `json:"unit"`
|
||||
Series []Series `json:"series"`
|
||||
Timestep int `json:"timestep"`
|
||||
}
|
||||
|
||||
type Series struct {
|
||||
Id *string `json:"id,omitempty"`
|
||||
Hostname string `json:"hostname"`
|
||||
Data []Float `json:"data"`
|
||||
Statistics MetricStatistics `json:"statistics"`
|
||||
}
|
||||
|
||||
type ScopedStats struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
Data *MetricStatistics `json:"data"`
|
||||
}
|
||||
|
||||
type MetricStatistics struct {
|
||||
Avg float64 `json:"avg"`
|
||||
Min float64 `json:"min"`
|
||||
Max float64 `json:"max"`
|
||||
}
|
||||
|
||||
type StatsSeries struct {
|
||||
Percentiles map[int][]Float `json:"percentiles,omitempty"`
|
||||
Mean []Float `json:"mean"`
|
||||
Median []Float `json:"median"`
|
||||
Min []Float `json:"min"`
|
||||
Max []Float `json:"max"`
|
||||
}
|
||||
|
||||
type MetricScope string
|
||||
|
||||
const (
|
||||
MetricScopeInvalid MetricScope = "invalid_scope"
|
||||
|
||||
MetricScopeNode MetricScope = "node"
|
||||
MetricScopeSocket MetricScope = "socket"
|
||||
MetricScopeMemoryDomain MetricScope = "memoryDomain"
|
||||
MetricScopeCore MetricScope = "core"
|
||||
MetricScopeHWThread MetricScope = "hwthread"
|
||||
|
||||
MetricScopeAccelerator MetricScope = "accelerator"
|
||||
)
|
||||
|
||||
var metricScopeGranularity map[MetricScope]int = map[MetricScope]int{
|
||||
MetricScopeNode: 10,
|
||||
MetricScopeSocket: 5,
|
||||
MetricScopeMemoryDomain: 4,
|
||||
MetricScopeCore: 3,
|
||||
MetricScopeHWThread: 2,
|
||||
/* Special-Case Accelerator
|
||||
* -> No conversion possible if native scope is HWTHREAD
|
||||
* -> Therefore needs to be less than HWTREAD, else max() would return unhandled case
|
||||
* -> If nativeScope is accelerator, accelerator metrics return correctly
|
||||
*/
|
||||
MetricScopeAccelerator: 1,
|
||||
|
||||
MetricScopeInvalid: -1,
|
||||
}
|
||||
|
||||
func (e *MetricScope) LT(other MetricScope) bool {
|
||||
a := metricScopeGranularity[*e]
|
||||
b := metricScopeGranularity[other]
|
||||
return a < b
|
||||
}
|
||||
|
||||
func (e *MetricScope) LTE(other MetricScope) bool {
|
||||
a := metricScopeGranularity[*e]
|
||||
b := metricScopeGranularity[other]
|
||||
return a <= b
|
||||
}
|
||||
|
||||
func (e *MetricScope) Max(other MetricScope) MetricScope {
|
||||
a := metricScopeGranularity[*e]
|
||||
b := metricScopeGranularity[other]
|
||||
if a > b {
|
||||
return *e
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func (e *MetricScope) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("SCHEMA/METRICS > enums must be strings")
|
||||
}
|
||||
|
||||
*e = MetricScope(str)
|
||||
if !e.Valid() {
|
||||
return fmt.Errorf("SCHEMA/METRICS > %s is not a valid MetricScope", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e MetricScope) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprintf(w, "\"%s\"", e)
|
||||
}
|
||||
|
||||
func (e MetricScope) Valid() bool {
|
||||
gran, ok := metricScopeGranularity[e]
|
||||
return ok && gran > 0
|
||||
}
|
||||
|
||||
func (jd *JobData) Size() int {
|
||||
n := 128
|
||||
for _, scopes := range *jd {
|
||||
for _, metric := range scopes {
|
||||
if metric.StatisticsSeries != nil {
|
||||
n += len(metric.StatisticsSeries.Max)
|
||||
n += len(metric.StatisticsSeries.Mean)
|
||||
n += len(metric.StatisticsSeries.Median)
|
||||
n += len(metric.StatisticsSeries.Min)
|
||||
}
|
||||
|
||||
for _, series := range metric.Series {
|
||||
n += len(series.Data)
|
||||
}
|
||||
}
|
||||
}
|
||||
return n * int(unsafe.Sizeof(Float(0)))
|
||||
}
|
||||
|
||||
const smooth bool = false
|
||||
|
||||
func (jm *JobMetric) AddStatisticsSeries() {
|
||||
if jm.StatisticsSeries != nil || len(jm.Series) < 4 {
|
||||
return
|
||||
}
|
||||
|
||||
n, m := 0, len(jm.Series[0].Data)
|
||||
for _, series := range jm.Series {
|
||||
if len(series.Data) > n {
|
||||
n = len(series.Data)
|
||||
}
|
||||
if len(series.Data) < m {
|
||||
m = len(series.Data)
|
||||
}
|
||||
}
|
||||
|
||||
// mean := make([]Float, n)
|
||||
min, median, max := make([]Float, n), make([]Float, n), make([]Float, n)
|
||||
i := 0
|
||||
for ; i < m; i++ {
|
||||
seriesCount := len(jm.Series)
|
||||
// ssum := 0.0
|
||||
smin, smed, smax := math.MaxFloat32, make([]float64, seriesCount), -math.MaxFloat32
|
||||
notnan := 0
|
||||
for j := 0; j < seriesCount; j++ {
|
||||
x := float64(jm.Series[j].Data[i])
|
||||
if math.IsNaN(x) {
|
||||
continue
|
||||
}
|
||||
|
||||
notnan += 1
|
||||
// ssum += x
|
||||
smed[j] = x
|
||||
smin = math.Min(smin, x)
|
||||
smax = math.Max(smax, x)
|
||||
}
|
||||
|
||||
if notnan < 3 {
|
||||
min[i] = NaN
|
||||
// mean[i] = NaN
|
||||
median[i] = NaN
|
||||
max[i] = NaN
|
||||
} else {
|
||||
min[i] = Float(smin)
|
||||
// mean[i] = Float(ssum / float64(notnan))
|
||||
max[i] = Float(smax)
|
||||
|
||||
medianRaw, err := util.Median(smed)
|
||||
if err != nil {
|
||||
median[i] = NaN
|
||||
} else {
|
||||
median[i] = Float(medianRaw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ; i < n; i++ {
|
||||
min[i] = NaN
|
||||
// mean[i] = NaN
|
||||
median[i] = NaN
|
||||
max[i] = NaN
|
||||
}
|
||||
|
||||
if smooth {
|
||||
for i := 2; i < len(median)-2; i++ {
|
||||
if min[i].IsNaN() {
|
||||
continue
|
||||
}
|
||||
|
||||
min[i] = (min[i-2] + min[i-1] + min[i] + min[i+1] + min[i+2]) / 5
|
||||
max[i] = (max[i-2] + max[i-1] + max[i] + max[i+1] + max[i+2]) / 5
|
||||
// mean[i] = (mean[i-2] + mean[i-1] + mean[i] + mean[i+1] + mean[i+2]) / 5
|
||||
// Reduce Median further
|
||||
smoothRaw := []float64{float64(median[i-2]), float64(median[i-1]), float64(median[i]), float64(median[i+1]), float64(median[i+2])}
|
||||
smoothMedian, err := util.Median(smoothRaw)
|
||||
if err != nil {
|
||||
median[i] = NaN
|
||||
} else {
|
||||
median[i] = Float(smoothMedian)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.StatisticsSeries = &StatsSeries{Median: median, Min: min, Max: max} // Mean: mean
|
||||
}
|
||||
|
||||
func (jd *JobData) AddNodeScope(metric string) bool {
|
||||
scopes, ok := (*jd)[metric]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
maxScope := MetricScopeInvalid
|
||||
for scope := range scopes {
|
||||
maxScope = maxScope.Max(scope)
|
||||
}
|
||||
|
||||
if maxScope == MetricScopeInvalid || maxScope == MetricScopeNode {
|
||||
return false
|
||||
}
|
||||
|
||||
jm := scopes[maxScope]
|
||||
hosts := make(map[string][]Series, 32)
|
||||
for _, series := range jm.Series {
|
||||
hosts[series.Hostname] = append(hosts[series.Hostname], series)
|
||||
}
|
||||
|
||||
nodeJm := &JobMetric{
|
||||
Unit: jm.Unit,
|
||||
Timestep: jm.Timestep,
|
||||
Series: make([]Series, 0, len(hosts)),
|
||||
}
|
||||
for hostname, series := range hosts {
|
||||
min, sum, max := math.MaxFloat32, 0.0, -math.MaxFloat32
|
||||
for _, series := range series {
|
||||
sum += series.Statistics.Avg
|
||||
min = math.Min(min, series.Statistics.Min)
|
||||
max = math.Max(max, series.Statistics.Max)
|
||||
}
|
||||
|
||||
n, m := 0, len(jm.Series[0].Data)
|
||||
for _, series := range jm.Series {
|
||||
if len(series.Data) > n {
|
||||
n = len(series.Data)
|
||||
}
|
||||
if len(series.Data) < m {
|
||||
m = len(series.Data)
|
||||
}
|
||||
}
|
||||
|
||||
i, data := 0, make([]Float, len(series[0].Data))
|
||||
for ; i < m; i++ {
|
||||
x := Float(0.0)
|
||||
for _, series := range jm.Series {
|
||||
x += series.Data[i]
|
||||
}
|
||||
data[i] = x
|
||||
}
|
||||
|
||||
for ; i < n; i++ {
|
||||
data[i] = NaN
|
||||
}
|
||||
|
||||
nodeJm.Series = append(nodeJm.Series, Series{
|
||||
Hostname: hostname,
|
||||
Statistics: MetricStatistics{Min: min, Avg: sum / float64(len(series)), Max: max},
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
scopes[MetricScopeNode] = nodeJm
|
||||
return true
|
||||
}
|
||||
|
||||
func (jd *JobData) RoundMetricStats() {
|
||||
// TODO: Make Digit-Precision Configurable? (Currently: Fixed to 2 Digits)
|
||||
for _, scopes := range *jd {
|
||||
for _, jm := range scopes {
|
||||
for index := range jm.Series {
|
||||
jm.Series[index].Statistics = MetricStatistics{
|
||||
Avg: (math.Round(jm.Series[index].Statistics.Avg*100) / 100),
|
||||
Min: (math.Round(jm.Series[index].Statistics.Min*100) / 100),
|
||||
Max: (math.Round(jm.Series[index].Statistics.Max*100) / 100),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (jm *JobMetric) AddPercentiles(ps []int) bool {
|
||||
if jm.StatisticsSeries == nil {
|
||||
jm.AddStatisticsSeries()
|
||||
}
|
||||
|
||||
if len(jm.Series) < 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
if jm.StatisticsSeries.Percentiles == nil {
|
||||
jm.StatisticsSeries.Percentiles = make(map[int][]Float, len(ps))
|
||||
}
|
||||
|
||||
n := 0
|
||||
for _, series := range jm.Series {
|
||||
if len(series.Data) > n {
|
||||
n = len(series.Data)
|
||||
}
|
||||
}
|
||||
|
||||
data := make([][]float64, n)
|
||||
for i := 0; i < n; i++ {
|
||||
vals := make([]float64, 0, len(jm.Series))
|
||||
for _, series := range jm.Series {
|
||||
if i < len(series.Data) {
|
||||
vals = append(vals, float64(series.Data[i]))
|
||||
}
|
||||
}
|
||||
|
||||
sort.Float64s(vals)
|
||||
data[i] = vals
|
||||
}
|
||||
|
||||
for _, p := range ps {
|
||||
if p < 1 || p > 99 {
|
||||
panic("SCHEMA/METRICS > invalid percentile")
|
||||
}
|
||||
|
||||
if _, ok := jm.StatisticsSeries.Percentiles[p]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
percentiles := make([]Float, n)
|
||||
for i := 0; i < n; i++ {
|
||||
sorted := data[i]
|
||||
percentiles[i] = Float(sorted[(len(sorted)*p)/100])
|
||||
}
|
||||
|
||||
jm.StatisticsSeries.Percentiles[p] = percentiles
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
type NodeState string
|
||||
|
||||
const (
|
||||
NodeStateAllocated NodeState = "allocated"
|
||||
NodeStateReserved NodeState = "reserved"
|
||||
NodeStateIdle NodeState = "idle"
|
||||
NodeStateMixed NodeState = "mixed"
|
||||
NodeStateDown NodeState = "down"
|
||||
NodeStateUnknown NodeState = "unknown"
|
||||
)
|
||||
|
||||
type MonitoringState string
|
||||
|
||||
const (
|
||||
MonitoringStateFull MonitoringState = "full"
|
||||
MonitoringStatePartial MonitoringState = "partial"
|
||||
MonitoringStateFailed MonitoringState = "failed"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
Hostname string `json:"hostname" db:"hostname" example:"fritz"`
|
||||
Cluster string `json:"cluster" db:"cluster" example:"fritz"`
|
||||
SubCluster string `json:"subCluster" db:"subcluster" example:"main"`
|
||||
NodeState NodeState `json:"nodeState" db:"node_state" example:"completed" enums:"completed,failed,cancelled,stopped,timeout,out_of_memory"`
|
||||
HealthState MonitoringState `json:"healthState" db:"health_state" example:"completed" enums:"completed,failed,cancelled,stopped,timeout,out_of_memory"`
|
||||
CpusAllocated int `json:"cpusAllocated" db:"cpus_allocated"`
|
||||
CpusTotal int `json:"cpusTotal" db:"cpus_total"`
|
||||
MemoryAllocated int `json:"memoryAllocated" db:"memory_allocated"`
|
||||
MemoryTotal int `json:"memoryTotal" db:"memory_total"`
|
||||
GpusAllocated int `json:"gpusAllocated" db:"gpus_allocated"`
|
||||
GpusTotal int `json:"gpusTotal" db:"gpus_total"`
|
||||
RawMetaData []byte `json:"-" db:"meta_data"`
|
||||
MetaData map[string]string `json:"metaData"`
|
||||
}
|
@@ -1,339 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://cluster.schema.json",
|
||||
"title": "HPC cluster description",
|
||||
"description": "Meta data information of a HPC cluster",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "The unique identifier of a cluster",
|
||||
"type": "string"
|
||||
},
|
||||
"metricConfig": {
|
||||
"description": "Metric specifications",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Metric name",
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"scope": {
|
||||
"description": "Native measurement resolution",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"node",
|
||||
"socket",
|
||||
"memoryDomain",
|
||||
"core",
|
||||
"hwthread",
|
||||
"accelerator"
|
||||
]
|
||||
},
|
||||
"timestep": {
|
||||
"description": "Frequency of timeseries points in seconds",
|
||||
"type": "integer"
|
||||
},
|
||||
"aggregation": {
|
||||
"description": "How the metric is aggregated",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"sum",
|
||||
"avg"
|
||||
]
|
||||
},
|
||||
"footprint": {
|
||||
"description": "Is it a footprint metric and what type",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"avg",
|
||||
"max",
|
||||
"min"
|
||||
]
|
||||
},
|
||||
"energy": {
|
||||
"description": "Is it used to calculate job energy",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"power",
|
||||
"energy"
|
||||
]
|
||||
},
|
||||
"lowerIsBetter": {
|
||||
"description": "Is lower better.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"peak": {
|
||||
"description": "Metric peak threshold (Upper metric limit)",
|
||||
"type": "number"
|
||||
},
|
||||
"normal": {
|
||||
"description": "Metric normal threshold",
|
||||
"type": "number"
|
||||
},
|
||||
"caution": {
|
||||
"description": "Metric caution threshold (Suspicious but does not require immediate action)",
|
||||
"type": "number"
|
||||
},
|
||||
"alert": {
|
||||
"description": "Metric alert threshold (Requires immediate action)",
|
||||
"type": "number"
|
||||
},
|
||||
"subClusters": {
|
||||
"description": "Array of cluster hardware partition metric thresholds",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Hardware partition name",
|
||||
"type": "string"
|
||||
},
|
||||
"footprint": {
|
||||
"description": "Is it a footprint metric and what type. Overwrite global setting",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"avg",
|
||||
"max",
|
||||
"min"
|
||||
]
|
||||
},
|
||||
"energy": {
|
||||
"description": "Is it used to calculate job energy. Overwrite global",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"power",
|
||||
"energy"
|
||||
]
|
||||
},
|
||||
"lowerIsBetter": {
|
||||
"description": "Is lower better. Overwrite global",
|
||||
"type": "boolean"
|
||||
},
|
||||
"peak": {
|
||||
"description": "The maximum possible metric value",
|
||||
"type": "number"
|
||||
},
|
||||
"normal": {
|
||||
"description": "A common metric value level",
|
||||
"type": "number"
|
||||
},
|
||||
"caution": {
|
||||
"description": "Metric value requires attention",
|
||||
"type": "number"
|
||||
},
|
||||
"alert": {
|
||||
"description": "Metric value requiring immediate attention",
|
||||
"type": "number"
|
||||
},
|
||||
"remove": {
|
||||
"description": "Remove this metric for this subcluster",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"unit",
|
||||
"scope",
|
||||
"timestep",
|
||||
"aggregation",
|
||||
"peak",
|
||||
"normal",
|
||||
"caution",
|
||||
"alert"
|
||||
]
|
||||
},
|
||||
"minItems": 1
|
||||
},
|
||||
"subClusters": {
|
||||
"description": "Array of cluster hardware partitions",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Hardware partition name",
|
||||
"type": "string"
|
||||
},
|
||||
"processorType": {
|
||||
"description": "Processor type",
|
||||
"type": "string"
|
||||
},
|
||||
"socketsPerNode": {
|
||||
"description": "Number of sockets per node",
|
||||
"type": "integer"
|
||||
},
|
||||
"coresPerSocket": {
|
||||
"description": "Number of cores per socket",
|
||||
"type": "integer"
|
||||
},
|
||||
"threadsPerCore": {
|
||||
"description": "Number of SMT threads per core",
|
||||
"type": "integer"
|
||||
},
|
||||
"flopRateScalar": {
|
||||
"description": "Theoretical node peak flop rate for scalar code in GFlops/s",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"value": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"flopRateSimd": {
|
||||
"description": "Theoretical node peak flop rate for SIMD code in GFlops/s",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"value": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"memoryBandwidth": {
|
||||
"description": "Theoretical node peak memory bandwidth in GB/s",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"value": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nodes": {
|
||||
"description": "Node list expression",
|
||||
"type": "string"
|
||||
},
|
||||
"topology": {
|
||||
"description": "Node topology",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"description": "HwTread lists of node",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"socket": {
|
||||
"description": "HwTread lists of sockets",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"memoryDomain": {
|
||||
"description": "HwTread lists of memory domains",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"die": {
|
||||
"description": "HwTread lists of dies",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"core": {
|
||||
"description": "HwTread lists of cores",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"accelerators": {
|
||||
"type": "array",
|
||||
"description": "List of of accelerator devices",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "The unique device id"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The accelerator type",
|
||||
"enum": [
|
||||
"Nvidia GPU",
|
||||
"AMD GPU",
|
||||
"Intel GPU"
|
||||
]
|
||||
},
|
||||
"model": {
|
||||
"type": "string",
|
||||
"description": "The accelerator model"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"type",
|
||||
"model"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node",
|
||||
"socket",
|
||||
"memoryDomain"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"nodes",
|
||||
"topology",
|
||||
"processorType",
|
||||
"socketsPerNode",
|
||||
"coresPerSocket",
|
||||
"threadsPerCore",
|
||||
"flopRateScalar",
|
||||
"flopRateSimd",
|
||||
"memoryBandwidth"
|
||||
]
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"metricConfig",
|
||||
"subClusters"
|
||||
]
|
||||
}
|
@@ -1,446 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://config.schema.json",
|
||||
"title": "cc-backend configuration file schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"addr": {
|
||||
"description": "Address where the http (or https) server will listen on (for example: 'localhost:80').",
|
||||
"type": "string"
|
||||
},
|
||||
"apiAllowedIPs": {
|
||||
"description": "Addresses from which secured API endpoints can be reached",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"description": "Drop root permissions once .env was read and the port was taken. Only applicable if using privileged port.",
|
||||
"type": "string"
|
||||
},
|
||||
"group": {
|
||||
"description": "Drop root permissions once .env was read and the port was taken. Only applicable if using privileged port.",
|
||||
"type": "string"
|
||||
},
|
||||
"disable-authentication": {
|
||||
"description": "Disable authentication (for everything: API, Web-UI, ...).",
|
||||
"type": "boolean"
|
||||
},
|
||||
"embed-static-files": {
|
||||
"description": "If all files in `web/frontend/public` should be served from within the binary itself (they are embedded) or not.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"static-files": {
|
||||
"description": "Folder where static assets can be found, if embed-static-files is false.",
|
||||
"type": "string"
|
||||
},
|
||||
"db-driver": {
|
||||
"description": "sqlite3 or mysql (mysql will work for mariadb as well).",
|
||||
"type": "string",
|
||||
"enum": ["sqlite3", "mysql"]
|
||||
},
|
||||
"db": {
|
||||
"description": "For sqlite3 a filename, for mysql a DSN in this format: https://github.com/go-sql-driver/mysql#dsn-data-source-name (Without query parameters!).",
|
||||
"type": "string"
|
||||
},
|
||||
"archive": {
|
||||
"description": "Configuration keys for job-archive",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"description": "Backend type for job-archive",
|
||||
"type": "string",
|
||||
"enum": ["file", "s3"]
|
||||
},
|
||||
"path": {
|
||||
"description": "Path to job archive for file backend",
|
||||
"type": "string"
|
||||
},
|
||||
"compression": {
|
||||
"description": "Setup automatic compression for jobs older than number of days",
|
||||
"type": "integer"
|
||||
},
|
||||
"retention": {
|
||||
"description": "Configuration keys for retention",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"policy": {
|
||||
"description": "Retention policy",
|
||||
"type": "string",
|
||||
"enum": ["none", "delete", "move"]
|
||||
},
|
||||
"includeDB": {
|
||||
"description": "Also remove jobs from database",
|
||||
"type": "boolean"
|
||||
},
|
||||
"age": {
|
||||
"description": "Act on jobs with startTime older than age (in days)",
|
||||
"type": "integer"
|
||||
},
|
||||
"location": {
|
||||
"description": "The target directory for retention. Only applicable for retention move.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["policy"]
|
||||
}
|
||||
},
|
||||
"required": ["kind"]
|
||||
},
|
||||
"disable-archive": {
|
||||
"description": "Keep all metric data in the metric data repositories, do not write to the job-archive.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable-job-taggers": {
|
||||
"description": "Turn on automatic application and jobclass taggers",
|
||||
"type": "boolean"
|
||||
},
|
||||
"validate": {
|
||||
"description": "Validate all input json documents against json schema.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"session-max-age": {
|
||||
"description": "Specifies for how long a session shall be valid as a string parsable by time.ParseDuration(). If 0 or empty, the session/token does not expire!",
|
||||
"type": "string"
|
||||
},
|
||||
"https-cert-file": {
|
||||
"description": "Filepath to SSL certificate. If also https-key-file is set use HTTPS using those certificates.",
|
||||
"type": "string"
|
||||
},
|
||||
"https-key-file": {
|
||||
"description": "Filepath to SSL key file. If also https-cert-file is set use HTTPS using those certificates.",
|
||||
"type": "string"
|
||||
},
|
||||
"redirect-http-to": {
|
||||
"description": "If not the empty string and addr does not end in :80, redirect every request incoming at port 80 to that url.",
|
||||
"type": "string"
|
||||
},
|
||||
"stop-jobs-exceeding-walltime": {
|
||||
"description": "If not zero, automatically mark jobs as stopped running X seconds longer than their walltime. Only applies if walltime is set for job.",
|
||||
"type": "integer"
|
||||
},
|
||||
"short-running-jobs-duration": {
|
||||
"description": "Do not show running jobs shorter than X seconds.",
|
||||
"type": "integer"
|
||||
},
|
||||
"emission-constant": {
|
||||
"description": ".",
|
||||
"type": "integer"
|
||||
},
|
||||
"cron-frequency": {
|
||||
"description": "Frequency of cron job workers.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"duration-worker": {
|
||||
"description": "Duration Update Worker [Defaults to '5m']",
|
||||
"type": "string"
|
||||
},
|
||||
"footprint-worker": {
|
||||
"description": "Metric-Footprint Update Worker [Defaults to '10m']",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"enable-resampling": {
|
||||
"description": "Enable dynamic zoom in frontend metric plots.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trigger": {
|
||||
"description": "Trigger next zoom level at less than this many visible datapoints.",
|
||||
"type": "integer"
|
||||
},
|
||||
"resolutions": {
|
||||
"description": "Array of resampling target resolutions, in seconds.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["trigger", "resolutions"]
|
||||
},
|
||||
"jwts": {
|
||||
"description": "For JWT token authentication.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"max-age": {
|
||||
"description": "Configure how long a token is valid. As string parsable by time.ParseDuration()",
|
||||
"type": "string"
|
||||
},
|
||||
"cookieName": {
|
||||
"description": "Cookie that should be checked for a JWT token.",
|
||||
"type": "string"
|
||||
},
|
||||
"validateUser": {
|
||||
"description": "Deny login for users not in database (but defined in JWT). Overwrite roles in JWT with database roles.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"trustedIssuer": {
|
||||
"description": "Issuer that should be accepted when validating external JWTs ",
|
||||
"type": "string"
|
||||
},
|
||||
"syncUserOnLogin": {
|
||||
"description": "Add non-existent user to DB at login attempt with values provided in JWT.",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["max-age"]
|
||||
},
|
||||
"oidc": {
|
||||
"provider": {
|
||||
"description": "",
|
||||
"type": "string"
|
||||
},
|
||||
"syncUserOnLogin": {
|
||||
"description": "",
|
||||
"type": "boolean"
|
||||
},
|
||||
"updateUserOnLogin": {
|
||||
"description": "",
|
||||
"type": "boolean"
|
||||
},
|
||||
"required": ["provider"]
|
||||
},
|
||||
"ldap": {
|
||||
"description": "For LDAP Authentication and user synchronisation.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": {
|
||||
"description": "URL of LDAP directory server.",
|
||||
"type": "string"
|
||||
},
|
||||
"user_base": {
|
||||
"description": "Base DN of user tree root.",
|
||||
"type": "string"
|
||||
},
|
||||
"search_dn": {
|
||||
"description": "DN for authenticating LDAP admin account with general read rights.",
|
||||
"type": "string"
|
||||
},
|
||||
"user_bind": {
|
||||
"description": "Expression used to authenticate users via LDAP bind. Must contain uid={username}.",
|
||||
"type": "string"
|
||||
},
|
||||
"user_filter": {
|
||||
"description": "Filter to extract users for syncing.",
|
||||
"type": "string"
|
||||
},
|
||||
"username_attr": {
|
||||
"description": "Attribute with full username. Default: gecos",
|
||||
"type": "string"
|
||||
},
|
||||
"sync_interval": {
|
||||
"description": "Interval used for syncing local user table with LDAP directory. Parsed using time.ParseDuration.",
|
||||
"type": "string"
|
||||
},
|
||||
"sync_del_old_users": {
|
||||
"description": "Delete obsolete users in database.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"syncUserOnLogin": {
|
||||
"description": "Add non-existent user to DB at login attempt if user exists in Ldap directory",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["url", "user_base", "search_dn", "user_bind", "user_filter"]
|
||||
},
|
||||
"clusters": {
|
||||
"description": "Configuration for the clusters to be displayed.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "The name of the cluster.",
|
||||
"type": "string"
|
||||
},
|
||||
"metricDataRepository": {
|
||||
"description": "Type of the metric data repository for this cluster",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"type": "string",
|
||||
"enum": ["influxdb", "prometheus", "cc-metric-store", "test"]
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["kind", "url"]
|
||||
},
|
||||
"filterRanges": {
|
||||
"description": "This option controls the slider ranges for the UI controls of numNodes, duration, and startTime.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"numNodes": {
|
||||
"description": "UI slider range for number of nodes",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"from": {
|
||||
"type": "integer"
|
||||
},
|
||||
"to": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": ["from", "to"]
|
||||
},
|
||||
"duration": {
|
||||
"description": "UI slider range for duration",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"from": {
|
||||
"type": "integer"
|
||||
},
|
||||
"to": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": ["from", "to"]
|
||||
},
|
||||
"startTime": {
|
||||
"description": "UI slider range for start time",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"from": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"to": {
|
||||
"type": "null"
|
||||
}
|
||||
},
|
||||
"required": ["from", "to"]
|
||||
}
|
||||
},
|
||||
"required": ["numNodes", "duration", "startTime"]
|
||||
}
|
||||
},
|
||||
"required": ["name", "metricDataRepository", "filterRanges"],
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"ui-defaults": {
|
||||
"description": "Default configuration for web UI",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"plot_general_colorBackground": {
|
||||
"description": "Color plot background according to job average threshold limits",
|
||||
"type": "boolean"
|
||||
},
|
||||
"plot_general_lineWidth": {
|
||||
"description": "Initial linewidth",
|
||||
"type": "integer"
|
||||
},
|
||||
"plot_list_jobsPerPage": {
|
||||
"description": "Jobs shown per page in job lists",
|
||||
"type": "integer"
|
||||
},
|
||||
"plot_view_plotsPerRow": {
|
||||
"description": "Number of plots per row in single job view",
|
||||
"type": "integer"
|
||||
},
|
||||
"plot_view_showPolarplot": {
|
||||
"description": "Option to toggle polar plot in single job view",
|
||||
"type": "boolean"
|
||||
},
|
||||
"plot_view_showRoofline": {
|
||||
"description": "Option to toggle roofline plot in single job view",
|
||||
"type": "boolean"
|
||||
},
|
||||
"plot_view_showStatTable": {
|
||||
"description": "Option to toggle the node statistic table in single job view",
|
||||
"type": "boolean"
|
||||
},
|
||||
"system_view_selectedMetric": {
|
||||
"description": "Initial metric shown in system view",
|
||||
"type": "string"
|
||||
},
|
||||
"job_view_showFootprint": {
|
||||
"description": "Option to toggle footprint ui in single job view",
|
||||
"type": "boolean"
|
||||
},
|
||||
"job_list_usePaging": {
|
||||
"description": "Option to switch from continous scroll to paging",
|
||||
"type": "boolean"
|
||||
},
|
||||
"analysis_view_histogramMetrics": {
|
||||
"description": "Metrics to show as job count histograms in analysis view",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"analysis_view_scatterPlotMetrics": {
|
||||
"description": "Initial scatter plto configuration in analysis view",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"job_view_nodestats_selectedMetrics": {
|
||||
"description": "Initial metrics shown in node statistics table of single job view",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"job_view_selectedMetrics": {
|
||||
"description": "Initial metrics shown as plots in single job view",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"plot_general_colorscheme": {
|
||||
"description": "Initial color scheme",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"plot_list_selectedMetrics": {
|
||||
"description": "Initial metric plots shown in jobs lists",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"minItems": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"plot_general_colorBackground",
|
||||
"plot_general_lineWidth",
|
||||
"plot_list_jobsPerPage",
|
||||
"plot_view_plotsPerRow",
|
||||
"plot_view_showPolarplot",
|
||||
"plot_view_showRoofline",
|
||||
"plot_view_showStatTable",
|
||||
"system_view_selectedMetric",
|
||||
"job_view_showFootprint",
|
||||
"job_list_usePaging",
|
||||
"analysis_view_histogramMetrics",
|
||||
"analysis_view_scatterPlotMetrics",
|
||||
"job_view_nodestats_selectedMetrics",
|
||||
"job_view_selectedMetrics",
|
||||
"plot_general_colorscheme",
|
||||
"plot_list_selectedMetrics"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["jwts", "clusters", "apiAllowedIPs"]
|
||||
}
|
@@ -1,490 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://job-data.schema.json",
|
||||
"title": "Job metric data list",
|
||||
"description": "Collection of metric data of a HPC job",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"mem_used": {
|
||||
"description": "Memory capacity used",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"flops_any": {
|
||||
"description": "Total flop rate with DP flops scaled up",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"mem_bw": {
|
||||
"description": "Main memory bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"net_bw": {
|
||||
"description": "Total fast interconnect network bandwidth",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"ipc": {
|
||||
"description": "Instructions executed per cycle",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"cpu_user": {
|
||||
"description": "CPU user active core utilization",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"cpu_load": {
|
||||
"description": "CPU requested core utilization (load 1m)",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"flops_dp": {
|
||||
"description": "Double precision flop rate",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"flops_sp": {
|
||||
"description": "Single precision flops rate",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"vectorization_ratio": {
|
||||
"description": "Fraction of arithmetic instructions using SIMD instructions",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"cpu_power": {
|
||||
"description": "CPU power consumption",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"mem_power": {
|
||||
"description": "Memory power consumption",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"acc_utilization": {
|
||||
"description": "GPU utilization",
|
||||
"properties": {
|
||||
"accelerator": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"accelerator"
|
||||
]
|
||||
},
|
||||
"acc_mem_used": {
|
||||
"description": "GPU memory capacity used",
|
||||
"properties": {
|
||||
"accelerator": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"accelerator"
|
||||
]
|
||||
},
|
||||
"acc_power": {
|
||||
"description": "GPU power consumption",
|
||||
"properties": {
|
||||
"accelerator": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"accelerator"
|
||||
]
|
||||
},
|
||||
"clock": {
|
||||
"description": "Average core frequency",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"socket": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"memoryDomain": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"core": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
},
|
||||
"hwthread": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
"eth_read_bw": {
|
||||
"description": "Ethernet read bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"eth_write_bw": {
|
||||
"description": "Ethernet write bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"filesystems": {
|
||||
"description": "Array of filesystems",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"nfs",
|
||||
"lustre",
|
||||
"gpfs",
|
||||
"nvme",
|
||||
"ssd",
|
||||
"hdd",
|
||||
"beegfs"
|
||||
]
|
||||
},
|
||||
"read_bw": {
|
||||
"description": "File system read bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"write_bw": {
|
||||
"description": "File system write bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"read_req": {
|
||||
"description": "File system read requests",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"write_req": {
|
||||
"description": "File system write requests",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"inodes": {
|
||||
"description": "File system write requests",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"accesses": {
|
||||
"description": "File system open and close",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"fsync": {
|
||||
"description": "File system fsync",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"create": {
|
||||
"description": "File system create",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"open": {
|
||||
"description": "File system open",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"close": {
|
||||
"description": "File system close",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"seek": {
|
||||
"description": "File system seek",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"type",
|
||||
"read_bw",
|
||||
"write_bw"
|
||||
]
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"ic_rcv_packets": {
|
||||
"description": "Network interconnect read packets",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"ic_send_packets": {
|
||||
"description": "Network interconnect send packet",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"ic_read_bw": {
|
||||
"description": "Network interconnect read bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"ic_write_bw": {
|
||||
"description": "Network interconnect write bandwidth",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$ref": "embedfs://job-metric-data.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"required": [
|
||||
"cpu_user",
|
||||
"cpu_load",
|
||||
"mem_used",
|
||||
"flops_any",
|
||||
"mem_bw",
|
||||
"net_bw",
|
||||
"filesystems"
|
||||
]
|
||||
}
|
@@ -1,351 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://job-meta.schema.json",
|
||||
"title": "Job meta data",
|
||||
"description": "Meta data information of a HPC job",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"jobId": {
|
||||
"description": "The unique identifier of a job",
|
||||
"type": "integer"
|
||||
},
|
||||
"user": {
|
||||
"description": "The unique identifier of a user",
|
||||
"type": "string"
|
||||
},
|
||||
"project": {
|
||||
"description": "The unique identifier of a project",
|
||||
"type": "string"
|
||||
},
|
||||
"cluster": {
|
||||
"description": "The unique identifier of a cluster",
|
||||
"type": "string"
|
||||
},
|
||||
"subCluster": {
|
||||
"description": "The unique identifier of a sub cluster",
|
||||
"type": "string"
|
||||
},
|
||||
"partition": {
|
||||
"description": "The Slurm partition to which the job was submitted",
|
||||
"type": "string"
|
||||
},
|
||||
"arrayJobId": {
|
||||
"description": "The unique identifier of an array job",
|
||||
"type": "integer"
|
||||
},
|
||||
"numNodes": {
|
||||
"description": "Number of nodes used",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"numHwthreads": {
|
||||
"description": "Number of HWThreads used",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"numAcc": {
|
||||
"description": "Number of accelerators used",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"exclusive": {
|
||||
"description": "Specifies how nodes are shared. 0 - Shared among multiple jobs of multiple users, 1 - Job exclusive, 2 - Shared among multiple jobs of same user",
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 2
|
||||
},
|
||||
"monitoringStatus": {
|
||||
"description": "State of monitoring system during job run",
|
||||
"type": "integer"
|
||||
},
|
||||
"smt": {
|
||||
"description": "SMT threads used by job",
|
||||
"type": "integer"
|
||||
},
|
||||
"walltime": {
|
||||
"description": "Requested walltime of job in seconds",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"jobState": {
|
||||
"description": "Final state of job",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"completed",
|
||||
"failed",
|
||||
"cancelled",
|
||||
"stopped",
|
||||
"out_of_memory",
|
||||
"timeout"
|
||||
]
|
||||
},
|
||||
"startTime": {
|
||||
"description": "Start epoch time stamp in seconds",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"duration": {
|
||||
"description": "Duration of job in seconds",
|
||||
"type": "integer",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"resources": {
|
||||
"description": "Resources used by job",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hostname": {
|
||||
"type": "string"
|
||||
},
|
||||
"hwthreads": {
|
||||
"type": "array",
|
||||
"description": "List of OS processor ids",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"accelerators": {
|
||||
"type": "array",
|
||||
"description": "List of of accelerator device ids",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"configuration": {
|
||||
"type": "string",
|
||||
"description": "The configuration options of the node"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"hostname"
|
||||
],
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"metaData": {
|
||||
"description": "Additional information about the job",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"jobScript": {
|
||||
"type": "string",
|
||||
"description": "The batch script of the job"
|
||||
},
|
||||
"jobName": {
|
||||
"type": "string",
|
||||
"description": "Slurm Job name"
|
||||
},
|
||||
"slurmInfo": {
|
||||
"type": "string",
|
||||
"description": "Additional slurm infos as show by scontrol show job"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": {
|
||||
"description": "List of tags",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"statistics": {
|
||||
"description": "Job statistic data",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"mem_used": {
|
||||
"description": "Memory capacity used (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"cpu_load": {
|
||||
"description": "CPU requested core utilization (load 1m) (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"flops_any": {
|
||||
"description": "Total flop rate with DP flops scaled up (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"mem_bw": {
|
||||
"description": "Main memory bandwidth (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"net_bw": {
|
||||
"description": "Total fast interconnect network bandwidth (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"file_bw": {
|
||||
"description": "Total file IO bandwidth (required)",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"ipc": {
|
||||
"description": "Instructions executed per cycle",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"cpu_user": {
|
||||
"description": "CPU user active core utilization",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"flops_dp": {
|
||||
"description": "Double precision flop rate",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"flops_sp": {
|
||||
"description": "Single precision flops rate",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"rapl_power": {
|
||||
"description": "CPU power consumption",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"acc_used": {
|
||||
"description": "GPU utilization",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"acc_mem_used": {
|
||||
"description": "GPU memory capacity used",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"acc_power": {
|
||||
"description": "GPU power consumption",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"clock": {
|
||||
"description": "Average core frequency",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"eth_read_bw": {
|
||||
"description": "Ethernet read bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"eth_write_bw": {
|
||||
"description": "Ethernet write bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"ic_rcv_packets": {
|
||||
"description": "Network interconnect read packets",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"ic_send_packets": {
|
||||
"description": "Network interconnect send packet",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"ic_read_bw": {
|
||||
"description": "Network interconnect read bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"ic_write_bw": {
|
||||
"description": "Network interconnect write bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"filesystems": {
|
||||
"description": "Array of filesystems",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"nfs",
|
||||
"lustre",
|
||||
"gpfs",
|
||||
"nvme",
|
||||
"ssd",
|
||||
"hdd",
|
||||
"beegfs"
|
||||
]
|
||||
},
|
||||
"read_bw": {
|
||||
"description": "File system read bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"write_bw": {
|
||||
"description": "File system write bandwidth",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"read_req": {
|
||||
"description": "File system read requests",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"write_req": {
|
||||
"description": "File system write requests",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"inodes": {
|
||||
"description": "File system write requests",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"accesses": {
|
||||
"description": "File system open and close",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"fsync": {
|
||||
"description": "File system fsync",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"create": {
|
||||
"description": "File system create",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"open": {
|
||||
"description": "File system open",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"close": {
|
||||
"description": "File system close",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
},
|
||||
"seek": {
|
||||
"description": "File system seek",
|
||||
"$ref": "embedfs://job-metric-statistics.schema.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"type",
|
||||
"read_bw",
|
||||
"write_bw"
|
||||
]
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"cpu_user",
|
||||
"cpu_load",
|
||||
"mem_used",
|
||||
"flops_any",
|
||||
"mem_bw"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"jobId",
|
||||
"user",
|
||||
"project",
|
||||
"cluster",
|
||||
"subCluster",
|
||||
"numNodes",
|
||||
"exclusive",
|
||||
"startTime",
|
||||
"jobState",
|
||||
"duration",
|
||||
"resources",
|
||||
"statistics"
|
||||
]
|
||||
}
|
@@ -1,216 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://job-metric-data.schema.json",
|
||||
"title": "Job metric data",
|
||||
"description": "Metric data of a HPC job",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"timestep": {
|
||||
"description": "Measurement interval in seconds",
|
||||
"type": "integer"
|
||||
},
|
||||
"thresholds": {
|
||||
"description": "Metric thresholds for specific system",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"peak": {
|
||||
"type": "number"
|
||||
},
|
||||
"normal": {
|
||||
"type": "number"
|
||||
},
|
||||
"caution": {
|
||||
"type": "number"
|
||||
},
|
||||
"alert": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"statisticsSeries": {
|
||||
"type": "object",
|
||||
"description": "Statistics series across topology",
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"max": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"mean": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"percentiles": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"10": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"20": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"30": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"40": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"50": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"60": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"70": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"80": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"90": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"25": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
},
|
||||
"75": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"series": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hostname": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"statistics": {
|
||||
"type": "object",
|
||||
"description": "Statistics across time dimension",
|
||||
"properties": {
|
||||
"avg": {
|
||||
"description": "Series average",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"min": {
|
||||
"description": "Series minimum",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"max": {
|
||||
"description": "Series maximum",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"avg",
|
||||
"min",
|
||||
"max"
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"type": "array",
|
||||
"contains": {
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"hostname",
|
||||
"statistics",
|
||||
"data"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"unit",
|
||||
"timestep",
|
||||
"series"
|
||||
]
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://job-metric-statistics.schema.json",
|
||||
"title": "Job statistics",
|
||||
"description": "Format specification for job metric statistics",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unit": {
|
||||
"description": "Metric unit",
|
||||
"$ref": "embedfs://unit.schema.json"
|
||||
},
|
||||
"avg": {
|
||||
"description": "Job metric average",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"min": {
|
||||
"description": "Job metric minimum",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
},
|
||||
"max": {
|
||||
"description": "Job metric maximum",
|
||||
"type": "number",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"unit",
|
||||
"avg",
|
||||
"min",
|
||||
"max"
|
||||
]
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "embedfs://unit.schema.json",
|
||||
"title": "Metric unit",
|
||||
"description": "Format specification for job metric units",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"base": {
|
||||
"description": "Metric base unit",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"B",
|
||||
"F",
|
||||
"B/s",
|
||||
"F/s",
|
||||
"CPI",
|
||||
"IPC",
|
||||
"Hz",
|
||||
"W",
|
||||
"J",
|
||||
"°C",
|
||||
""
|
||||
]
|
||||
},
|
||||
"prefix": {
|
||||
"description": "Unit prefix",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"K",
|
||||
"M",
|
||||
"G",
|
||||
"T",
|
||||
"P",
|
||||
"E"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"base"
|
||||
]
|
||||
}
|
@@ -1,200 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Role int
|
||||
|
||||
const (
|
||||
RoleAnonymous Role = iota
|
||||
RoleApi
|
||||
RoleUser
|
||||
RoleManager
|
||||
RoleSupport
|
||||
RoleAdmin
|
||||
RoleError
|
||||
)
|
||||
|
||||
type AuthSource int
|
||||
|
||||
const (
|
||||
AuthViaLocalPassword AuthSource = iota
|
||||
AuthViaLDAP
|
||||
AuthViaToken
|
||||
AuthViaOIDC
|
||||
AuthViaAll
|
||||
)
|
||||
|
||||
type AuthType int
|
||||
|
||||
const (
|
||||
AuthToken AuthType = iota
|
||||
AuthSession
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Roles []string `json:"roles"`
|
||||
Projects []string `json:"projects"`
|
||||
AuthType AuthType `json:"authType"`
|
||||
AuthSource AuthSource `json:"authSource"`
|
||||
}
|
||||
|
||||
func (u *User) HasProject(project string) bool {
|
||||
return slices.Contains(u.Projects, project)
|
||||
}
|
||||
|
||||
func GetRoleString(roleInt Role) string {
|
||||
return [6]string{"anonymous", "api", "user", "manager", "support", "admin"}[roleInt]
|
||||
}
|
||||
|
||||
func getRoleEnum(roleStr string) Role {
|
||||
switch strings.ToLower(roleStr) {
|
||||
case "admin":
|
||||
return RoleAdmin
|
||||
case "support":
|
||||
return RoleSupport
|
||||
case "manager":
|
||||
return RoleManager
|
||||
case "user":
|
||||
return RoleUser
|
||||
case "api":
|
||||
return RoleApi
|
||||
case "anonymous":
|
||||
return RoleAnonymous
|
||||
default:
|
||||
return RoleError
|
||||
}
|
||||
}
|
||||
|
||||
func IsValidRole(role string) bool {
|
||||
return getRoleEnum(role) != RoleError
|
||||
}
|
||||
|
||||
// Check if User has SPECIFIED role AND role is VALID
|
||||
func (u *User) HasValidRole(role string) (hasRole bool, isValid bool) {
|
||||
if IsValidRole(role) {
|
||||
for _, r := range u.Roles {
|
||||
if r == role {
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
return false, true
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
|
||||
// Check if User has SPECIFIED role
|
||||
func (u *User) HasRole(role Role) bool {
|
||||
for _, r := range u.Roles {
|
||||
if r == GetRoleString(role) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if User has ANY of the listed roles
|
||||
func (u *User) HasAnyRole(queryroles []Role) bool {
|
||||
for _, ur := range u.Roles {
|
||||
for _, qr := range queryroles {
|
||||
if ur == GetRoleString(qr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if User has ALL of the listed roles
|
||||
func (u *User) HasAllRoles(queryroles []Role) bool {
|
||||
target := len(queryroles)
|
||||
matches := 0
|
||||
for _, ur := range u.Roles {
|
||||
for _, qr := range queryroles {
|
||||
if ur == GetRoleString(qr) {
|
||||
matches += 1
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if matches == target {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check if User has NONE of the listed roles
|
||||
func (u *User) HasNotRoles(queryroles []Role) bool {
|
||||
matches := 0
|
||||
for _, ur := range u.Roles {
|
||||
for _, qr := range queryroles {
|
||||
if ur == GetRoleString(qr) {
|
||||
matches += 1
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if matches == 0 {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Called by API endpoint '/roles/' from frontend: Only required for admin config -> Check Admin Role
|
||||
func GetValidRoles(user *User) ([]string, error) {
|
||||
var vals []string
|
||||
if user.HasRole(RoleAdmin) {
|
||||
for i := RoleApi; i < RoleError; i++ {
|
||||
vals = append(vals, GetRoleString(i))
|
||||
}
|
||||
return vals, nil
|
||||
}
|
||||
|
||||
return vals, fmt.Errorf("%s: only admins are allowed to fetch a list of roles", user.Username)
|
||||
}
|
||||
|
||||
// Called by routerConfig web.page setup in backend: Only requires known user
|
||||
func GetValidRolesMap(user *User) (map[string]Role, error) {
|
||||
named := make(map[string]Role)
|
||||
if user.HasNotRoles([]Role{RoleAnonymous}) {
|
||||
for i := RoleApi; i < RoleError; i++ {
|
||||
named[GetRoleString(i)] = i
|
||||
}
|
||||
return named, nil
|
||||
}
|
||||
return named, fmt.Errorf("only known users are allowed to fetch a list of roles")
|
||||
}
|
||||
|
||||
// Find highest role
|
||||
func (u *User) GetAuthLevel() Role {
|
||||
if u.HasRole(RoleAdmin) {
|
||||
return RoleAdmin
|
||||
} else if u.HasRole(RoleSupport) {
|
||||
return RoleSupport
|
||||
} else if u.HasRole(RoleManager) {
|
||||
return RoleManager
|
||||
} else if u.HasRole(RoleUser) {
|
||||
return RoleUser
|
||||
} else if u.HasRole(RoleApi) {
|
||||
return RoleApi
|
||||
} else if u.HasRole(RoleAnonymous) {
|
||||
return RoleAnonymous
|
||||
} else {
|
||||
return RoleError
|
||||
}
|
||||
}
|
@@ -1,129 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHasValidRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
exists, _ := u.HasValidRole("user")
|
||||
|
||||
if !exists {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasValidRole("user"): EXISTS = %v, expected 'true'.`, exists)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotValidRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
exists, _ := u.HasValidRole("manager")
|
||||
|
||||
if exists {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasValidRole("manager"): EXISTS = %v, expected 'false'.`, exists)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasInvalidRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
_, valid := u.HasValidRole("invalid")
|
||||
|
||||
if valid {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasValidRole("invalid"): VALID = %v, expected 'false'.`, valid)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotInvalidRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
_, valid := u.HasValidRole("user")
|
||||
|
||||
if !valid {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasValidRole("user"): VALID = %v, expected 'true'.`, valid)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
exists := u.HasRole(RoleUser)
|
||||
|
||||
if !exists {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasRole(RoleUser): EXISTS = %v, expected 'true'.`, exists)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user"}}
|
||||
|
||||
exists := u.HasRole(RoleManager)
|
||||
|
||||
if exists {
|
||||
t.Fatalf(`User{Roles: ["user"]} -> HasRole(RoleManager): EXISTS = %v, expected 'false'.`, exists)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasAnyRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager"}}
|
||||
|
||||
result := u.HasAnyRole([]Role{RoleManager, RoleSupport, RoleAdmin})
|
||||
|
||||
if !result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager"]} -> HasAnyRole([]Role{RoleManager, RoleSupport, RoleAdmin}): RESULT = %v, expected 'true'.`, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotAnyRole(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager"}}
|
||||
|
||||
result := u.HasAnyRole([]Role{RoleSupport, RoleAdmin})
|
||||
|
||||
if result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager"]} -> HasAllRoles([]Role{RoleSupport, RoleAdmin}): RESULT = %v, expected 'false'.`, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasAllRoles(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager", "support"}}
|
||||
|
||||
result := u.HasAllRoles([]Role{RoleUser, RoleManager, RoleSupport})
|
||||
|
||||
if !result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager", "support"]} -> HasAllRoles([]Role{RoleUser, RoleManager, RoleSupport}): RESULT = %v, expected 'true'.`, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotAllRoles(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager"}}
|
||||
|
||||
result := u.HasAllRoles([]Role{RoleUser, RoleManager, RoleSupport})
|
||||
|
||||
if result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager"]} -> HasAllRoles([]Role{RoleUser, RoleManager, RoleSupport}): RESULT = %v, expected 'false'.`, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNotRoles(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager"}}
|
||||
|
||||
result := u.HasNotRoles([]Role{RoleSupport, RoleAdmin})
|
||||
|
||||
if !result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager"]} -> HasNotRoles([]Role{RoleSupport, RoleAdmin}): RESULT = %v, expected 'true'.`, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasAllNotRoles(t *testing.T) {
|
||||
u := User{Username: "testuser", Roles: []string{"user", "manager"}}
|
||||
|
||||
result := u.HasNotRoles([]Role{RoleUser, RoleManager})
|
||||
|
||||
if result {
|
||||
t.Fatalf(`User{Roles: ["user", "manager"]} -> HasNotRoles([]Role{RoleUser, RoleManager}): RESULT = %v, expected 'false'.`, result)
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/santhosh-tekuri/jsonschema/v5"
|
||||
)
|
||||
|
||||
type Kind int
|
||||
|
||||
const (
|
||||
Meta Kind = iota + 1
|
||||
Data
|
||||
Config
|
||||
ClusterCfg
|
||||
)
|
||||
|
||||
//go:embed schemas/*
|
||||
var schemaFiles embed.FS
|
||||
|
||||
func Validate(k Kind, r io.Reader) error {
|
||||
jsonschema.Loaders["embedfs"] = func(s string) (io.ReadCloser, error) {
|
||||
f := filepath.Join("schemas", strings.Split(s, "//")[1])
|
||||
return schemaFiles.Open(f)
|
||||
}
|
||||
var s *jsonschema.Schema
|
||||
var err error
|
||||
|
||||
switch k {
|
||||
case Meta:
|
||||
s, err = jsonschema.Compile("embedfs://job-meta.schema.json")
|
||||
case Data:
|
||||
s, err = jsonschema.Compile("embedfs://job-data.schema.json")
|
||||
case ClusterCfg:
|
||||
s, err = jsonschema.Compile("embedfs://cluster.schema.json")
|
||||
case Config:
|
||||
s, err = jsonschema.Compile("embedfs://config.schema.json")
|
||||
default:
|
||||
return fmt.Errorf("SCHEMA/VALIDATE > unkown schema kind: %#v", k)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Error while compiling json schema for kind '%#v'", k)
|
||||
return err
|
||||
}
|
||||
|
||||
var v interface{}
|
||||
if err = json.NewDecoder(r).Decode(&v); err != nil {
|
||||
log.Warnf("Error while decoding raw json schema: %#v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = s.Validate(v); err != nil {
|
||||
return fmt.Errorf("SCHEMA/VALIDATE > %#v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
// All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateConfig(t *testing.T) {
|
||||
json := []byte(`{
|
||||
"jwts": {
|
||||
"max-age": "2m"
|
||||
},
|
||||
"apiAllowedIPs": [
|
||||
"*"
|
||||
],
|
||||
"clusters": [
|
||||
{
|
||||
"name": "testcluster",
|
||||
"metricDataRepository": {
|
||||
"kind": "cc-metric-store",
|
||||
"url": "localhost:8082"},
|
||||
"filterRanges": {
|
||||
"numNodes": { "from": 1, "to": 64 },
|
||||
"duration": { "from": 0, "to": 86400 },
|
||||
"startTime": { "from": "2022-01-01T00:00:00Z", "to": null }
|
||||
}}]
|
||||
}`)
|
||||
|
||||
if err := Validate(Config, bytes.NewReader(json)); err != nil {
|
||||
t.Errorf("Error is not nil! %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateCluster(t *testing.T) {
|
||||
json := []byte(`{
|
||||
"name": "emmy",
|
||||
"subClusters": [
|
||||
{
|
||||
"name": "main",
|
||||
"processorType": "Intel IvyBridge",
|
||||
"socketsPerNode": 2,
|
||||
"coresPerSocket": 10,
|
||||
"threadsPerCore": 2,
|
||||
"flopRateScalar": {
|
||||
"unit": {
|
||||
"prefix": "G",
|
||||
"base": "F/s"
|
||||
},
|
||||
"value": 14
|
||||
},
|
||||
"flopRateSimd": {
|
||||
"unit": {
|
||||
"prefix": "G",
|
||||
"base": "F/s"
|
||||
},
|
||||
"value": 112
|
||||
},
|
||||
"memoryBandwidth": {
|
||||
"unit": {
|
||||
"prefix": "G",
|
||||
"base": "B/s"
|
||||
},
|
||||
"value": 24
|
||||
},
|
||||
"numberOfNodes": 70,
|
||||
"nodes": "w11[27-45,49-63,69-72]",
|
||||
"topology": {
|
||||
"node": [0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29,10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39],
|
||||
"socket": [
|
||||
[0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29],
|
||||
[10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39]
|
||||
],
|
||||
"memoryDomain": [
|
||||
[0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29],
|
||||
[10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39]
|
||||
],
|
||||
"core": [
|
||||
[0,20],[1,21],[2,22],[3,23],[4,24],[5,25],[6,26],[7,27],[8,28],[9,29],[10,30],[11,31],[12,32],[13,33],[14,34],[15,35],[16,36],[17,37],[18,38],[19,39]
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"metricConfig": [
|
||||
{
|
||||
"name": "cpu_load",
|
||||
"scope": "hwthread",
|
||||
"unit": {"base": ""},
|
||||
"aggregation": "avg",
|
||||
"timestep": 60,
|
||||
"peak": 4,
|
||||
"normal": 2,
|
||||
"caution": 1,
|
||||
"alert": 0.25
|
||||
}
|
||||
]
|
||||
}`)
|
||||
|
||||
if err := Validate(ClusterCfg, bytes.NewReader(json)); err != nil {
|
||||
t.Errorf("Error is not nil! %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user