models

package
v0.0.0-...-de09c22 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterTable = "cluster"

	ClusterMaster     = "cluster_master"
	ClusterKubeConfig = "kube_config"
	ClusterDesc       = "cluster_desc"
	ClusterStatus     = "cluster_status"
	ClusterEnv        = "environment"
	ClusterDeleted    = "deleted"
	ClusterUpdateAt   = "last_update_time"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	ClusterBasic
	Id        int       `json:"id"`
	Deleted   bool      `gorm:"default false" json:"deleted"`
	CreatedAt time.Time `gorm:"column:created_time" json:"createdat"`
	UpdateAt  time.Time `gorm:"column:last_update_time" json:"updateat"`
}

func (*Cluster) TableName

func (m *Cluster) TableName() string

func (*Cluster) UpdateCluster

func (m *Cluster) UpdateCluster(current *Cluster) *Cluster

func (*Cluster) WitchCreator

func (m *Cluster) WitchCreator(user string) *Cluster

type ClusterBasic

type ClusterBasic struct {
	Name        string          `gorm:"column:cluster_name" json:"name"`
	CnName      string          `gorm:"column:cn_name" json:"cnname"`
	Master      string          `gorm:"column:cluster_master" json:"master"`
	KubeConfig  string          `gorm:"column:kube_config" json:"kubeconfig"`
	Status      Status          `gorm:"column:cluster_status" json:"status"` // status 1 is up 0 is down
	Desc        string          `gorm:"column:cluster_desc" json:"desc"`
	Creator     string          ` json:"creator"`
	Environment EnvironmentType `json:"environment"`
}

func (*ClusterBasic) Validate

func (i *ClusterBasic) Validate() error

type ComProgStatus

type ComProgStatus struct {
	ID            uint64     `json:"id"`
	TaskID        uint64     `json:"task_id"`
	ComponentID   uint64     `json:"component_id"`
	ComponentName string     `json:"component_name"`
	ProgramID     uint64     `json:"program_id"`
	ProgramName   string     `json:"program_name"`
	AttachID      uint32     `json:"attach_id"`
	Status        TaskStatus `json:"status"`
	Error         string     `json:"error"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

type Component

type Component struct {
	Id         int       `json:"id"`
	Name       string    `json:"name"`
	ClusterId  int64     `json:"cluster_id"`
	BinaryPath string    `json:"binary_path"`
	Programs   []Program `json:"programs"`
	Maps       []Map     `json:"maps"`
}

func (*Component) Validate

func (c *Component) Validate() error

type ComponentDB

type ComponentDB struct {
	ID             uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	Name           string    `gorm:"column:name;uniqueIndex" json:"name"`
	BinaryPath     string    `gorm:"column:binary_path" json:"binary_path"`
	Deleted        uint8     `gorm:"column:deleted;default:0" json:"deleted"`
	Creator        string    `gorm:"column:creator" json:"creator"`
	CreatedTime    time.Time `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`

	ClusterID uint64 `gorm:"column:cluster_id" json:"cluster_id"`

	// 关联关系
	Programs []ProgramDB `gorm:"foreignKey:ComponentID" json:"programs"`
	Maps     []MapDB     `gorm:"foreignKey:ComponentID" json:"maps"`
}

ComponentDB 组件数据库模型

func (ComponentDB) TableName

func (ComponentDB) TableName() string

TableName 指定表名

func (*ComponentDB) ToComponent

func (c *ComponentDB) ToComponent() *Component

ToComponent 将数据库模型转换为业务模型

type EnvironmentType

type EnvironmentType string
const (
	TestEnvironment   EnvironmentType = "test"
	DeployEnvironment EnvironmentType = "dev"
	SitEnvironment    EnvironmentType = "sit"
	ProdEnvironment   EnvironmentType = "prod"
)

测试,开发,验收,生产

type JSONMapProperties

type JSONMapProperties meta.MapProperties

JSONMapProperties 用于存储 MapProperties 的 JSON 类型

func (*JSONMapProperties) Scan

func (j *JSONMapProperties) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口

func (JSONMapProperties) Value

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

Value 实现 driver.Valuer 接口

type JSONProgramProperties

type JSONProgramProperties meta.ProgramProperties

JSONProgramProperties 用于存储 ProgramProperties 的 JSON 类型

func (*JSONProgramProperties) Scan

func (j *JSONProgramProperties) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口

func (JSONProgramProperties) Value

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

Value 实现 driver.Valuer 接口

type Map

type Map struct {
	Id          int                `json:"id"`
	Name        string             `json:"name"`
	Description string             `json:"description"`
	Spec        MapSpec            `json:"spec"`
	Properties  meta.MapProperties `json:"properties"`
}

type MapDB

type MapDB struct {
	ID             uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ComponentID    uint64    `gorm:"column:component_id;index" json:"component_id"`
	Name           string    `gorm:"column:name" json:"name"`
	Description    string    `gorm:"column:description" json:"description"`
	Deleted        uint8     `gorm:"column:deleted;default:0" json:"deleted"`
	Creator        string    `gorm:"column:creator" json:"creator"`
	CreatedTime    time.Time `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`

	// 关联关系
	Spec       MapSpecDB       `gorm:"foreignKey:MapID" json:"spec"`
	Properties MapPropertiesDB `gorm:"foreignKey:MapID" json:"properties"`
}

MapDB Map数据库模型

func (MapDB) TableName

func (MapDB) TableName() string

TableName 指定表名

func (*MapDB) ToMap

func (m *MapDB) ToMap() *Map

ToMap 将数据库模型转换为业务模型

type MapInfoWrapper

type MapInfoWrapper struct {
	// Type of the map.
	Type ebpf.MapType
	// KeySize is the size of the map key in bytes.
	KeySize uint32
	// ValueSize is the size of the map value in bytes.
	ValueSize uint32
	// MaxEntries is the maximum number of entries the map can hold. Its meaning
	// is map-specific.
	MaxEntries uint32
	// Flags used during map creation.
	Flags uint32
	// Name as supplied by user space at load time. Available from 4.15.
	Name string

	ID       ebpf.MapID
	BTF      btf.ID
	MapExtra uint64
	Memlock  uint64
	Frozen   bool
}

type MapPropertiesDB

type MapPropertiesDB struct {
	ID             uint64            `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	MapID          uint64            `gorm:"column:map_id;uniqueIndex" json:"map_id"`
	PropertiesJSON JSONMapProperties `gorm:"column:properties_json" json:"properties_json"`
	Deleted        uint8             `gorm:"column:deleted;default:0" json:"deleted"`
	CreatedTime    time.Time         `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time         `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`
}

MapPropertiesDB Map属性数据库模型

func (MapPropertiesDB) TableName

func (MapPropertiesDB) TableName() string

TableName 指定表名

type MapSpec

type MapSpec struct {

	// Name is passed to the kernel as a debug aid. Must only contain
	// alpha numeric and '_' characters.
	Name       string
	Type       ebpf.MapType
	KeySize    uint32
	ValueSize  uint32
	MaxEntries uint32

	// Flags is passed to the kernel and specifies additional map
	// creation attributes.
	Flags uint32

	// Automatically pin and load a map from MapOptions.PinPath.
	// Generates an error if an existing pinned map is incompatible with the MapSpec.
	Pinning ebpf.PinType
}

type MapSpecDB

type MapSpecDB struct {
	ID             uint64       `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	MapID          uint64       `gorm:"column:map_id;uniqueIndex" json:"map_id"`
	Name           string       `gorm:"column:name" json:"name"`
	Type           ebpf.MapType `gorm:"column:type" json:"type"`
	KeySize        uint32       `gorm:"column:key_size" json:"key_size"`
	ValueSize      uint32       `gorm:"column:value_size" json:"value_size"`
	MaxEntries     uint32       `gorm:"column:max_entries" json:"max_entries"`
	Flags          uint32       `gorm:"column:flags" json:"flags"`
	Pinning        string       `gorm:"column:pinning" json:"pinning"`
	Deleted        uint8        `gorm:"column:deleted;default:0" json:"deleted"`
	CreatedTime    time.Time    `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time    `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`
}

MapSpecDB Map规格数据库模型

func (MapSpecDB) TableName

func (MapSpecDB) TableName() string

TableName 指定表名

func (*MapSpecDB) ToMapSpec

func (ms *MapSpecDB) ToMapSpec() *MapSpec

ToMapSpec 将数据库模型转换为业务模型

type MetricPoint

type MetricPoint struct {
	Timestamp   time.Time `json:"timestamp"`
	Value       float64   `json:"value"`
	ProgramName string    `json:"program_name"`
}

type Program

type Program struct {
	Id          int                    `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Spec        ProgramSpec            `json:"spec"`
	Properties  meta.ProgramProperties `json:"properties"`
}

type ProgramDB

type ProgramDB struct {
	ID             uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ComponentID    uint64    `gorm:"column:component_id;index" json:"component_id"`
	Name           string    `gorm:"column:name" json:"name"`
	Description    string    `gorm:"column:description" json:"description"`
	Deleted        uint8     `gorm:"column:deleted;default:0" json:"deleted"`
	Creator        string    `gorm:"column:creator" json:"creator"`
	CreatedTime    time.Time `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`

	// 关联关系
	Spec       ProgramSpecDB       `gorm:"foreignKey:ProgramID" json:"spec"`
	Properties ProgramPropertiesDB `gorm:"foreignKey:ProgramID" json:"properties"`
}

ProgramDB 程序数据库模型

func (ProgramDB) TableName

func (ProgramDB) TableName() string

TableName 指定表名

func (*ProgramDB) ToProgram

func (p *ProgramDB) ToProgram() *Program

ToProgram 将数据库模型转换为业务模型

type ProgramDetail

type ProgramDetail struct {
	ProgramInfoWrapper
	MapsDetail []MapInfoWrapper
}

type ProgramInfoWrapper

type ProgramInfoWrapper struct {
	Type ebpf.ProgramType
	ID   ebpf.ProgramID
	// Truncated hash of the BPF bytecode. Available from 4.13.
	Tag string
	// Name as supplied by user space at load time. Available from 4.15.
	Name string

	CreatedByUID     uint32
	HaveCreatedByUID bool
	BTF              btf.ID
	LoadTime         time.Time

	Maps []ebpf.MapID
}

type ProgramPropertiesDB

type ProgramPropertiesDB struct {
	ID             uint64                `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ProgramID      uint64                `gorm:"column:program_id;uniqueIndex" json:"program_id"`
	PropertiesJSON JSONProgramProperties `gorm:"column:properties_json" json:"properties_json"`
	Deleted        uint8                 `gorm:"column:deleted;default:0" json:"deleted"`
	CreatedTime    time.Time             `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time             `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`
}

ProgramPropertiesDB 程序属性数据库模型

func (ProgramPropertiesDB) TableName

func (ProgramPropertiesDB) TableName() string

TableName 指定表名

type ProgramSpec

type ProgramSpec struct {
	// Name is passed to the kernel as a debug aid. Must only contain
	// alpha numeric and '_' characters.
	Name string

	// Type determines at which hook in the kernel a program will run.
	Type ebpf.ProgramType

	// AttachType of the program, needed to differentiate allowed context
	// accesses in some newer program types like CGroupSockAddr.
	//
	// Available on kernels 4.17 and later.
	AttachType ebpf.AttachType

	// Name of a kernel data structure or function to attach to. Its
	// interpretation depends on Type and AttachType.
	AttachTo string

	// The name of the ELF section this program originated from.
	SectionName string

	// Flags is passed to the kernel and specifies additional program
	// load attributes.
	Flags uint32

	// License of the program. Some helpers are only available if
	// the license is deemed compatible with the GPL.
	//
	// See https://www.kernel.org/doc/html/latest/process/license-rules.html#id1
	License string

	// Version used by Kprobe programs.
	//
	// Deprecated on kernels 5.0 and later. Leave empty to let the library
	// detect this value automatically.
	KernelVersion uint32
}

type ProgramSpecDB

type ProgramSpecDB struct {
	ID             uint64           `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	ProgramID      uint64           `gorm:"column:program_id;uniqueIndex" json:"program_id"`
	Name           string           `gorm:"column:name" json:"name"`
	Type           ebpf.ProgramType `gorm:"column:type" json:"type"`
	AttachType     ebpf.AttachType  `gorm:"column:attach_type" json:"attach_type"`
	AttachTo       string           `gorm:"column:attach_to" json:"attach_to"`
	SectionName    string           `gorm:"column:section_name" json:"section_name"`
	Flags          uint32           `gorm:"column:flags" json:"flags"`
	License        string           `gorm:"column:license" json:"license"`
	KernelVersion  uint32           `gorm:"column:kernel_version" json:"kernel_version"`
	Deleted        uint8            `gorm:"column:deleted;default:0" json:"deleted"`
	CreatedTime    time.Time        `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time        `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`
}

ProgramSpecDB 程序规格数据库模型

func (ProgramSpecDB) TableName

func (ProgramSpecDB) TableName() string

TableName 指定表名

func (*ProgramSpecDB) ToProgramSpec

func (ps *ProgramSpecDB) ToProgramSpec() *ProgramSpec

ToProgramSpec 将数据库模型转换为业务模型

type RunningTask

type RunningTask struct {
	Task       *Task
	CancelFunc context.CancelFunc
	Logger     *zap.Logger
	BPFLoader  *loader.BPFLoader
}

RunningTask 表示正在运行的任务

type Status

type Status int
const (
	ClusterUp   Status = 1
	ClusterDown Status = 0
)

type Task

type Task struct {
	ID            uint64          `json:"id"`
	Name          string          `json:"name"`
	Description   string          `json:"description"`
	ComponentID   uint64          `json:"component_id"`
	ComponentName string          `json:"component_name"`
	Step          TaskStep        `json:"step"`
	Status        TaskStatus      `json:"status"`
	Error         string          `json:"error"`
	ProgStatus    []ComProgStatus `json:"prog_status"`
	CreatedAt     time.Time       `json:"created_at"`
	UpdatedAt     time.Time       `json:"updated_at"`
}

func (*Task) Validate

func (t *Task) Validate() error

type TaskDB

type TaskDB struct {
	ID             uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	Name           string    `gorm:"column:name" json:"name"`
	Description    string    `gorm:"column:description;type:text" json:"description"`
	ComponentID    uint64    `gorm:"column:component_id;index" json:"component_id"`
	ComponentName  string    `gorm:"column:component_name" json:"component_name"`
	Step           int       `gorm:"column:step;comment:任务步骤" json:"step"`
	Status         int       `gorm:"column:status;comment:任务状态" json:"status"`
	Error          string    `gorm:"column:error;type:text" json:"error"`
	Deleted        uint8     `gorm:"column:deleted;default:0" json:"deleted"`
	Creator        string    `gorm:"column:creator" json:"creator"`
	CreatedTime    time.Time `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`

	// 关联关系
	ProgStatuses []TaskProgStatusDB `gorm:"foreignKey:TaskID" json:"prog_statuses"`
}

TaskDB 任务数据库模型

func TaskDBFromTask

func TaskDBFromTask(task *Task) *TaskDB

FromTask 从业务模型创建数据库模型

func (TaskDB) TableName

func (TaskDB) TableName() string

TableName 指定表名

func (*TaskDB) ToTask

func (t *TaskDB) ToTask() *Task

ToTask 将数据库模型转换为业务模型

type TaskMetrics

type TaskMetrics struct {
	AvgRunTimeNS      []MetricPoint `json:"avg_run_time_ns"`
	CPUUsage          []MetricPoint `json:"cpu_usage"`
	EventsPerSecond   []MetricPoint `json:"events_per_second"`
	PeriodNS          []MetricPoint `json:"period_ns"`
	TotalAvgRunTimeNS []MetricPoint `json:"total_avg_run_time_ns"`
}

type TaskProgStatusDB

type TaskProgStatusDB struct {
	ID             uint64    `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	TaskID         uint64    `gorm:"column:task_id;index" json:"task_id"`
	ComponentID    uint64    `gorm:"column:component_id;index" json:"component_id"`
	ComponentName  string    `gorm:"column:component_name" json:"component_name"`
	ProgramID      uint64    `gorm:"column:program_id;index" json:"program_id"`
	ProgramName    string    `gorm:"column:program_name" json:"program_name"`
	Status         int       `gorm:"column:status;comment:状态" json:"status"`
	Error          string    `gorm:"column:error;type:text" json:"error"`
	Deleted        uint8     `gorm:"column:deleted;default:0" json:"deleted"`
	CreatedTime    time.Time `gorm:"column:created_time;autoCreateTime" json:"created_time"`
	LastUpdateTime time.Time `gorm:"column:last_update_time;autoUpdateTime" json:"last_update_time"`
}

TaskProgStatusDB 任务程序状态数据库模型

func (TaskProgStatusDB) TableName

func (TaskProgStatusDB) TableName() string

TableName 指定表名

func (*TaskProgStatusDB) ToComProgStatus

func (c *TaskProgStatusDB) ToComProgStatus() *ComProgStatus

ToComProgStatus 将数据库模型转换为业务模型

type TaskStatus

type TaskStatus int
const (
	TaskStatusPending TaskStatus = iota
	TaskStatusRunning
	TaskStatusSuccess
	TaskStatusFailed
)

type TaskStep

type TaskStep int
const (
	TaskStepInit TaskStep = iota
	TaskStepLoad
	TaskStepStart
	TaskStepStats
	TaskStepMetrics
	TaskStepStop
)

Jump to

Keyboard shortcuts

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