db

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2025 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package db creates DB tables, call resource manager interfaces and populates the DB with compute units

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBackupInt = errors.New("backup_interval of less than 1 day is not supported")
	ErrUpdateInt = errors.New("update_interval and/or max_update_interval must be more than 0s")
)

Custom errors.

View Source
var (

	// For estimating average values, we do weighted average method using following
	// values as weight for each DB column
	// For CPU and GPU, we use CPU time and GPU time as weights
	// For memory usage, we use Walltime * Mem for CPU as weight and just walltime
	// for GPU.
	Weights = map[string]string{
		"avg_cpu_usage":     "alloc_cputime",
		"avg_gpu_usage":     "alloc_gputime",
		"avg_cpu_mem_usage": "alloc_cpumemtime",
		"avg_gpu_mem_usage": "alloc_gpumemtime",
	}

	// Admin users sources.
	AdminUsersSources = []string{"ceems", "grafana"}
)
View Source
var MigrationsFS embed.FS
View Source
var StatementsFS embed.FS

Functions

func New

func New(c *Config) (*stats, error)

New returns a new instance of stats struct.

Types

type AdminConfig

type AdminConfig struct {
	Users   []string                `yaml:"users"`
	Grafana common.GrafanaWebConfig `yaml:"grafana"`
}

AdminConfig is the container for the admin users related config.

func (*AdminConfig) SetDirectory

func (c *AdminConfig) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*AdminConfig) UnmarshalYAML

func (c *AdminConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*AdminConfig) Validate

func (c *AdminConfig) Validate() error

Validate validates the config.

type Config

type Config struct {
	Logger          *slog.Logger
	Data            DataConfig
	Admin           AdminConfig
	ResourceManager func(*slog.Logger) (*resource.Manager, error)
	Updater         func(*slog.Logger) (*updater.UnitUpdater, error)
}

Config makes a DB config from config file.

type DataConfig

type DataConfig struct {
	Path               string         `yaml:"path"`
	BackupPath         string         `yaml:"backup_path"`
	RetentionPeriod    model.Duration `yaml:"retention_period"`
	UpdateInterval     model.Duration `yaml:"update_interval"`
	MaxUpdateInterval  model.Duration `yaml:"max_update_interval"`
	BackupInterval     model.Duration `yaml:"backup_interval"`
	LastUpdate         DateTime       `yaml:"update_from"`
	Timezone           Timezone       `yaml:"time_zone"`
	SkipDeleteOldUnits bool
}

DataConfig is the container for the data related config.

func (*DataConfig) UnmarshalYAML

func (c *DataConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*DataConfig) Validate

func (c *DataConfig) Validate() error

Validate validates the config.

type DateTime

type DateTime struct {
	time.Time
}

func (*DateTime) UnmarshalYAML

func (t *DateTime) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Timezone

type Timezone struct {
	*time.Location
}

func (*Timezone) UnmarshalYAML

func (t *Timezone) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Directories

Path Synopsis
Package migrator implements database migrations
Package migrator implements database migrations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL