models

package
v0.9.1 Latest Latest
Warning

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

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

Documentation

Overview

Package models defines different models used in stats

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminUser added in v0.6.0

type AdminUser struct {
	User
}

AdminUser table. We use same struct as `User` and where ever we need to use `AdminUser` struct, we must simply use `User` struct. The struct is defined here only for consistency across structs to DB table names.

func (AdminUser) TableName added in v0.6.0

func (AdminUser) TableName() string

TableName returns the table which admin users list is stored into.

type Allocation

type Allocation = Generic

Allocation is a type alias to Generic that stores allocation data of compute units.

type CLIConfig

type CLIConfig struct {
	Path    string            `yaml:"path"`
	EnvVars map[string]string `yaml:"environment_variables"`
}

CLIConfig contains the configuration of CLI client.

type Cluster

type Cluster struct {
	ID       string    `json:"id"      sql:"cluster_id"       yaml:"id"`
	Manager  string    `json:"manager" sql:"resource_manager" yaml:"manager"`
	Web      WebConfig `json:"-"       yaml:"web"`
	CLI      CLIConfig `json:"-"       yaml:"cli"`
	Updaters []string  `json:"-"       yaml:"updaters"`
	Extra    yaml.Node `json:"-"       yaml:"extra_config"`
}

Cluster contains the configuration of the given resource manager.

type ClusterProjects

type ClusterProjects struct {
	Cluster  Cluster
	Projects []Project
}

ClusterProjects is the container for the projects for a given cluster.

type ClusterUnits

type ClusterUnits struct {
	Cluster Cluster
	Units   []Unit
}

ClusterUnits is the container for the units and config of a given cluster.

type ClusterUsers

type ClusterUsers struct {
	Cluster Cluster
	Users   []User
}

ClusterUsers is the container for the users for a given cluster.

type DailyUsage added in v0.2.0

type DailyUsage struct {
	Usage
}

DailyUsage statistics of each project/tenant/namespace.

func (DailyUsage) TableName added in v0.2.0

func (DailyUsage) TableName() string

TableName returns the table which usage stats are stored into.

type Generic

type Generic map[string]interface{}

Generic is map to store any mixed data types. Only string and int are supported. Any number will be converted into int64. Ref: https://go.dev/play/p/89ra6QgcZba, https://husobee.github.io/golang/database/2015/06/12/scanner-valuer.html, https://gist.github.com/jmoiron/6979540

func (*Generic) Scan

func (g *Generic) Scan(v interface{}) error

Scan implements Scanner interface.

func (Generic) Value

func (g Generic) Value() (driver.Value, error)

Value implements Valuer interface.

type JSONFloat

type JSONFloat float64

JSONFloat is a custom float64 that can handle Inf and NaN during JSON (un)marshalling.

func (JSONFloat) MarshalJSON

func (j JSONFloat) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSONFloat into byte array The custom marshal interface will truncate the float64 to 8 decimals as storing all decimals will bring a very low added value and high DB storage.

func (*JSONFloat) Scan

func (j *JSONFloat) Scan(v interface{}) error

Scan implements Scanner interface.

func (*JSONFloat) UnmarshalJSON

func (j *JSONFloat) UnmarshalJSON(v []byte) error

UnmarshalJSON unmarshals byte array into JSONFloat.

func (JSONFloat) Value

func (j JSONFloat) Value() (driver.Value, error)

Value implements Valuer interface.

type Key added in v0.2.0

type Key struct {
	Name string `json:"name" sql:"name" sqlitetype:"text"` // Name of the metric key
}

Key represents arbritrary keys used in metric maps.

func (Key) TagMap added in v0.2.0

func (k Key) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (Key) TagNames added in v0.2.0

func (k Key) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type List

type List []interface{}

List is a generic type to store slices. Only string and int slices are supported. Any number will be converted into int64.

func (*List) Scan

func (l *List) Scan(v interface{}) error

Scan implements Scanner interface.

func (List) Value

func (l List) Value() (driver.Value, error)

Value implements Valuer interface.

type MetricMap

type MetricMap map[string]JSONFloat //nolint:recvcheck

MetricMap is a type alias to Generic that stores arbritrary metrics as a map.

func (MetricMap) Keys added in v0.7.0

func (m MetricMap) Keys() []string

Keys returns a slice of map keys.

func (*MetricMap) Scan

func (m *MetricMap) Scan(v interface{}) error

Scan implements Scanner interface.

func (MetricMap) String added in v0.7.0

func (m MetricMap) String() string

String implements stringer interface.

func (MetricMap) Value

func (m MetricMap) Value() (driver.Value, error)

Value implements Valuer interface.

func (MetricMap) Values added in v0.7.0

func (m MetricMap) Values(format string) []interface{}

Values returns a slice of string representation of map values.

type Project

type Project struct {
	ID              int64  `example:"1"         json:"-"                sql:"id"               sqlitetype:"integer not null primary key"`
	UID             string `example:"1000"      json:"uid,omitempty"    sql:"uid"              sqlitetype:"text"` // Unique identifier of the project provided by cluster
	ClusterID       string `example:"slurm-0"   json:"cluster_id"       sql:"cluster_id"       sqlitetype:"text"` // Identifier of the resource manager that owns project. It is used to differentiate multiple clusters of same resource manager.
	ResourceManager string `example:"slurm"     json:"resource_manager" sql:"resource_manager" sqlitetype:"text"` // Name of the resource manager that owns project. Eg slurm, openstack, kubernetes, etc
	Name            string `example:"prj1"      json:"name"             sql:"name"             sqlitetype:"text"` // Name of the project
	Users           List   ``                                                                                     // List of users of the project
	/* 135-byte string literal not displayed */
	Tags List `` // List of meta data tags of the project
	/* 135-byte string literal not displayed */
	LastUpdatedAt string `json:"-"            sql:"last_updated_at"   sqlitetype:"text"` // Last Updated time
}

Project is the container for a given account/tenant/namespace of cluster.

func (Project) TableName

func (Project) TableName() string

TableName returns the table which admin users list is stored into.

func (Project) TagMap

func (p Project) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (Project) TagNames

func (p Project) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type Stat added in v0.2.0

type Stat struct {
	ClusterID        string `example:"slurm-0" json:"cluster_id"         sql:"cluster_id"         sqlitetype:"text"`    // Identifier of the resource manager that owns compute unit. It is used to differentiate multiple clusters of same resource manager.
	ResourceManager  string `example:"slurm"   json:"resource_manager"   sql:"resource_manager"   sqlitetype:"text"`    // Name of the resource manager that owns project. Eg slurm, openstack, kubernetes, etc
	NumUnits         int64  `example:"1000"    json:"num_units"          sql:"num_units"          sqlitetype:"integer"` // Number of active and terminated units
	NumInActiveUnits int64  `example:"200"     json:"num_inactive_units" sql:"num_inactive_units" sqlitetype:"integer"` // Number of inactive units that are in terminated/cancelled/error state
	NumActiveUnits   int64  `example:"800"     json:"num_active_units"   sql:"num_active_units"   sqlitetype:"integer"` // Number of active units that are in running state
	NumProjects      int64  `example:"200"     json:"num_projects"       sql:"num_projects"       sqlitetype:"integer"` // Number of projects
	NumUsers         int64  `example:"500"     json:"num_users"          sql:"num_users"          sqlitetype:"integer"` // Number of users
}

Stat represents high level statistics of each cluster.

func (Stat) TagMap added in v0.2.0

func (s Stat) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (Stat) TagNames added in v0.2.0

func (s Stat) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type Tag

type Tag = Generic

Tag is a type alias to Generic that stores metadata of compute units.

type Unit

type Unit struct {
	ID        int64  `` /* 187-byte string literal not displayed */
	ClusterID string `` // Identifier of the resource manager that owns compute unit. It is used to differentiate multiple clusters of same resource manager.
	/* 205-byte string literal not displayed */
	ResourceManager string `` // Name of the resource manager that owns compute unit. Eg slurm, openstack, kubernetes, etc
	/* 205-byte string literal not displayed */
	UUID string `` // Unique identifier of unit. It can be Job ID for batch jobs, UUID for pods in k8s or VMs in Openstack
	/* 205-byte string literal not displayed */
	Name string `` // Name of compute unit
	/* 205-byte string literal not displayed */
	Project string `` // Account in batch systems, Tenant in Openstack, Namespace in k8s
	/* 205-byte string literal not displayed */
	Group string `` // User group
	/* 205-byte string literal not displayed */
	User string `` // Username
	/* 205-byte string literal not displayed */
	CreatedAt string `` // Creation time
	/* 205-byte string literal not displayed */
	StartedAt string `` // Start time
	/* 205-byte string literal not displayed */
	EndedAt string `` // End time
	/* 205-byte string literal not displayed */
	CreatedAtTS int64 `` // Creation timestamp
	/* 208-byte string literal not displayed */
	StartedAtTS int64 `` // Start timestamp
	/* 208-byte string literal not displayed */
	EndedAtTS int64 `` // End timestamp
	/* 208-byte string literal not displayed */
	Elapsed string `` // Human readable total elapsed time string
	/* 205-byte string literal not displayed */
	State string `` // Current state of unit
	/* 205-byte string literal not displayed */
	Allocation Allocation `` // Allocation map of unit. Only string and int64 values are supported in map
	/* 236-byte string literal not displayed */
	TotalTime MetricMap `` // Different types of times in seconds consumed by the unit. This map contains at minimum `walltime`, `alloc_cputime`, `alloc_cpumemtime`, `alloc_gputime` and `alloc_gpumem_time` keys.
	/* 236-byte string literal not displayed */
	AveCPUUsage MetricMap `` // Average CPU usage(s) during lifetime of unit
	/* 236-byte string literal not displayed */
	AveCPUMemUsage MetricMap `` // Average CPU memory usage(s) during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalCPUEnergyUsage MetricMap `` // Total CPU energy usage(s) in kWh during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalCPUEmissions MetricMap `` // Total CPU emissions from source(s) in grams during lifetime of unit
	/* 236-byte string literal not displayed */
	AveGPUUsage MetricMap `` // Average GPU usage(s) during lifetime of unit
	/* 236-byte string literal not displayed */
	AveGPUMemUsage MetricMap `` // Average GPU memory usage(s) during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalGPUEnergyUsage MetricMap `` // Total GPU energy usage(s) in kWh during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalGPUEmissions MetricMap `` // Total GPU emissions from source(s) in grams during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalIOWriteStats MetricMap `` // Total IO write statistics during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalIOReadStats MetricMap `` // Total IO read statistics during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalIngressStats MetricMap `` // Total Ingress statistics of unit
	/* 236-byte string literal not displayed */
	TotalEgressStats MetricMap `` // Total Outgress statistics of unit
	/* 236-byte string literal not displayed */
	Tags Tag `` // A map to store generic info. String and int64 are valid value types of map
	/* 236-byte string literal not displayed */
	Ignore int `` // Whether to ignore unit
	/* 166-byte string literal not displayed */
	NumUpdates int64 `` // Number of updates. This is used internally to update aggregate metrics
	/* 166-byte string literal not displayed */
	LastUpdatedAt string `` // Last updated time. It can be used to clean up DB
	/* 163-byte string literal not displayed */
}

Unit is an abstract compute unit that can mean Job (batchjobs), VM (cloud) or Pod (k8s).

func (Unit) TableName

func (Unit) TableName() string

TableName returns the table which units are stored into.

func (Unit) TagMap

func (u Unit) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (Unit) TagNames

func (u Unit) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type Usage

type Usage struct {
	ID        int64  `` /* 187-byte string literal not displayed */
	ClusterID string `` // Identifier of the resource manager that owns compute unit. It is used to differentiate multiple clusters of same resource manager.
	/* 205-byte string literal not displayed */
	ResourceManager string `` // Name of the resource manager that owns project. Eg slurm, openstack, kubernetes, etc
	/* 205-byte string literal not displayed */
	NumUnits int64 `` // Number of consumed units
	/* 208-byte string literal not displayed */
	Project string `` // Account in batch systems, Tenant in Openstack, Namespace in k8s
	/* 205-byte string literal not displayed */
	Group string `` // User group
	/* 205-byte string literal not displayed */
	User string `` // Username
	/* 205-byte string literal not displayed */
	LastUpdatedAt string `` // Last updated time. It can be used to clean up DB
	/* 163-byte string literal not displayed */
	TotalTime MetricMap `` // Different times in seconds consumed by the unit. This map must contain `walltime`, `alloc_cputime`, `alloc_cpumemtime`, `alloc_gputime` and `alloc_gpumem_time` keys.
	/* 236-byte string literal not displayed */
	AveCPUUsage MetricMap `` // Average CPU usage(s) during lifetime of project
	/* 236-byte string literal not displayed */
	AveCPUMemUsage MetricMap `` // Average CPU memory usage(s) during lifetime of project
	/* 236-byte string literal not displayed */
	TotalCPUEnergyUsage MetricMap `` // Total CPU energy usage(s) in kWh during lifetime of project
	/* 236-byte string literal not displayed */
	TotalCPUEmissions MetricMap `` // Total CPU emissions from source(s) in grams during lifetime of project
	/* 236-byte string literal not displayed */
	AveGPUUsage MetricMap `` // Average GPU usage(s) during lifetime of project
	/* 236-byte string literal not displayed */
	AveGPUMemUsage MetricMap `` // Average GPU memory usage(s) during lifetime of project
	/* 236-byte string literal not displayed */
	TotalGPUEnergyUsage MetricMap `` // Total GPU energy usage(s) in kWh during lifetime of project
	/* 236-byte string literal not displayed */
	TotalGPUEmissions MetricMap `` // Total GPU emissions from source(s) in grams during lifetime of project
	/* 236-byte string literal not displayed */
	TotalIOWriteStats MetricMap `` // Total IO write statistics during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalIOReadStats MetricMap `` // Total IO read statistics during lifetime of unit
	/* 236-byte string literal not displayed */
	TotalIngressStats MetricMap `` // Total Ingress statistics of unit
	/* 236-byte string literal not displayed */
	TotalEgressStats MetricMap `` // Total Egress statistics of unit
	/* 236-byte string literal not displayed */
	NumUpdates int64 `` // Number of updates. This is used internally to update aggregate metrics
	/* 163-byte string literal not displayed */
}

Usage statistics of each project/tenant/namespace.

func (Usage) TableName

func (Usage) TableName() string

TableName returns the table which usage stats are stored into.

func (Usage) TagMap

func (u Usage) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (Usage) TagNames

func (u Usage) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type User

type User struct {
	ID              int64  `example:"1"         json:"-"                          sql:"id"               sqlitetype:"integer not null primary key"`
	UID             string `example:"1000"      json:"uid,omitempty"              sql:"uid"              sqlitetype:"text"` // Unique identifier of the user provided by cluster
	ClusterID       string `example:"slurm-0"   json:"cluster_id"                 sql:"cluster_id"       sqlitetype:"text"` // Identifier of the resource manager that owns user. It is used to differentiate multiple clusters of same resource manager.
	ResourceManager string `example:"slurm"     json:"resource_manager,omitempty" sql:"resource_manager" sqlitetype:"text"` // Name of the resource manager that owns user. Eg slurm, openstack, kubernetes, etc
	Name            string `example:"usr1"      json:"name"                       sql:"name"             sqlitetype:"text"` // Name of the user
	Projects        List   ``                                                                                               // List of projects of the user
	/* 145-byte string literal not displayed */
	Tags List `` // List of meta data tags of the user
	/* 145-byte string literal not displayed */
	LastUpdatedAt string `json:"-"            sql:"last_updated_at"             sqlitetype:"text"` // Last Updated time
}

User is the container for a given user of cluster.

func (User) TableName

func (User) TableName() string

TableName returns the table which admin users list is stored into.

func (User) TagMap

func (u User) TagMap(keyTag string, valueTag string) map[string]string

TagMap returns a map of tags based on keyTag and valueTag. If keyTag is empty, field names are used as map keys.

func (User) TagNames

func (u User) TagNames(tag string) []string

TagNames returns a slice of all tag names.

type WebConfig

type WebConfig struct {
	URL              string                  `yaml:"url"`
	HTTPClientConfig config.HTTPClientConfig `yaml:",inline"`
}

WebConfig contains the client related configuration of a REST API server.

func (*WebConfig) SetDirectory

func (c *WebConfig) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*WebConfig) UnmarshalYAML

func (c *WebConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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