duty

package module
v1.0.635 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 35 Imported by: 19

README

duty

Duty (Database Utility) is a home for common database tools, models and helpers used within the mission control suite of projects.

Duty wraps the awesome atlas library, and copies some of its code to make use of internal functions.

Running Tests

make test will run tests against a new embedded postgres instance

Env Vars
  • DUTY_DB_URL: the postgres db, each test will run against a new database called duty_gingko
  • TEST_DB_PORT: will set the port that the test database will run on.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientOnly = func(config Config) Config {
	config.Postgrest.Disable = true
	config.SkipMigrations = true
	return config
}
View Source
var DefaultQueryTimeout = 30 * time.Second
View Source
var DisableKubernetes = func(config Config) Config {
	config.DisableKubernetes = true
	return config
}
View Source
var DisablePostgrest = func(config Config) Config {
	config.Postgrest.Disable = true
	return config
}
View Source
var EnableMetrics = func(config Config) Config {
	config.Metrics = true
	return config
}
View Source
var LocalFilter = "deleted_at is NULL AND agent_id = '00000000-0000-0000-0000-000000000000' OR agent_id IS NULL"
View Source
var LogLevel string

LogLevel is the log level for gorm logger

View Source
var RunMigrations = func(config Config) Config {
	config.MigrationMode = SkipByDefault
	config.RunMigrations = true
	return config
}
View Source
var SkipChangelogMigration = func(config Config) Config {
	config.SkipMigrationFiles = []string{"007_events.sql", "012_changelog_triggers_others.sql", "012_changelog_triggers_scrapers.sql"}
	return config
}
View Source
var SkipMigrationByDefaultMode = func(config Config) Config {
	config.MigrationMode = SkipByDefault
	return config
}
View Source
var SkipMigrations = func(config Config) Config {
	config.MigrationMode = RunByDefault
	config.RunMigrations = false
	return config
}
View Source
var WithUrl = func(url string) func(config Config) Config {
	return func(config Config) Config {
		config.ConnectionString = url
		return config
	}
}

Functions

func BindGoFlags added in v1.0.310

func BindGoFlags()

func BindPFlags added in v1.0.564

func BindPFlags(flags *pflag.FlagSet, opts ...StartOption)

func CheckSummary added in v1.0.164

func CheckSummary(ctx context.Context, checkID string) (*models.CheckSummary, error)

deprecated use query.CheckSummaryByID

func DefaultGormConfig added in v1.0.6

func DefaultGormConfig() *gorm.Config

func Delete added in v1.0.253

func Delete(ctx dutyContext.Context, model Table) error

func FreePort added in v1.0.580

func FreePort() int

func GetComponent added in v1.0.45

func GetComponent(ctx gocontext.Context, db *gorm.DB, id string) (*models.Component, error)

deprecated use query.GetComponent

func HasMigrationsRun added in v1.0.447

func HasMigrationsRun(ctx dutyContext.Context) (bool, error)

HasMigrationsRun performs a rudimentary check to see if the migrations have run at least once.

func InitDB added in v1.0.207

func InitDB(config api.Config) (*dutyContext.Context, error)

func LookupComponents added in v1.0.236

func LookupComponents(ctx context.Context, lookup RelationshipSelectorTemplate, labels map[string]string, env map[string]any) ([]uuid.UUID, error)

func LookupConfigs added in v1.0.236

func LookupConfigs(ctx context.Context, lookup RelationshipSelectorTemplate, labels map[string]string, env map[string]any) ([]uuid.UUID, error)

func Migrate added in v1.0.10

func Migrate(config api.Config) error

func NewDB

func NewDB(connection string) (*sql.DB, error)

func NewGorm

func NewGorm(connection string, config *gorm.Config) (*gorm.DB, error)

creates a new Gorm DB connection using the global pgx connection pool, must be called after NewPgxPool

func NewPgxPool

func NewPgxPool(connection string) (*pgxpool.Pool, error)

func Now added in v1.0.253

func Now() clause.Expr

func QueryCheckSummary added in v1.0.34

func QueryCheckSummary(ctx context.Context, dbpool *pgxpool.Pool, opts ...query.CheckSummaryOptions) ([]models.CheckSummary, error)

deprecated use query.CheckSummary

func SetupDB added in v1.0.141

func SetupDB(config api.Config) (gormDB *gorm.DB, pgxpool *pgxpool.Pool, err error)

SetupDB runs migrations for the connection and returns a gorm.DB and a pgxpool.Pool

func Start added in v1.0.564

func Start(name string, opts ...StartOption) (context.Context, func(), error)

Types

type FindOption added in v1.0.253

type FindOption func(db *gorm.DB)

func PickColumns added in v1.0.253

func PickColumns(columns ...string) FindOption

func WhereClause added in v1.0.287

func WhereClause(query any, args ...any) FindOption

type Lookup added in v1.0.236

type Lookup struct {
	Expr  string `json:"expr,omitempty"`
	Value string `json:"value,omitempty"`
	Label string `json:"label,omitempty"`
}

Lookup offers different ways to specify a lookup value

+kubebuilder:object:generate=true

func (*Lookup) DeepCopy added in v1.0.532

func (in *Lookup) DeepCopy() *Lookup

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Lookup.

func (*Lookup) DeepCopyInto added in v1.0.532

func (in *Lookup) DeepCopyInto(out *Lookup)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Lookup) Eval added in v1.0.236

func (t *Lookup) Eval(labels map[string]string, envVar map[string]any) (string, error)

func (Lookup) IsEmpty added in v1.0.532

func (t Lookup) IsEmpty() bool

type RelationshipSelector added in v1.0.532

type RelationshipSelector struct {
	ID         string            `json:"id,omitempty"`
	ExternalID string            `json:"external_id,omitempty"`
	Name       string            `json:"name,omitempty"`
	Namespace  string            `json:"namespace,omitempty"`
	Type       string            `json:"type,omitempty"`
	Agent      string            `json:"agent,omitempty"`
	Labels     map[string]string `json:"labels,omitempty"`

	// Scope is the id parent of the resource to select.
	// Example: For config items, the scope is the scraper id
	// - for checks, it's canaries and
	// - for components, it's topology.
	Scope string `json:"scope,omitempty"`
}

+kubebuilder:object:generate=true RelationshipSelector is the evaluated output of RelationshipSelectorTemplate.

func (*RelationshipSelector) DeepCopy added in v1.0.532

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RelationshipSelector.

func (*RelationshipSelector) DeepCopyInto added in v1.0.532

func (in *RelationshipSelector) DeepCopyInto(out *RelationshipSelector)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*RelationshipSelector) IsEmpty added in v1.0.532

func (t *RelationshipSelector) IsEmpty() bool

func (*RelationshipSelector) ToResourceSelector added in v1.0.532

func (t *RelationshipSelector) ToResourceSelector() types.ResourceSelector

type RelationshipSelectorTemplate added in v1.0.532

type RelationshipSelectorTemplate struct {
	ID         Lookup `json:"id,omitempty"`
	ExternalID Lookup `json:"external_id,omitempty"`
	Name       Lookup `json:"name,omitempty"`
	Namespace  Lookup `json:"namespace,omitempty"`
	Type       Lookup `json:"type,omitempty"`

	// Agent can be one of
	//  - agent id
	//  - agent name
	//  - 'self' (no agent)
	Agent Lookup `json:"agent,omitempty"`

	// Scope is the id of the parent of the resource to select.
	// Example: For config items, the scope is the scraper id
	// - for checks, it's canaries and
	// - for components, it's topology.
	// If left empty, the scope is the requester's scope.
	// Use `all` to disregard scope.
	Scope Lookup `json:"scope,omitempty"`

	Labels map[string]string `json:"labels,omitempty"`
}

+kubebuilder:object:generate=true

func (*RelationshipSelectorTemplate) DeepCopy added in v1.0.532

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RelationshipSelectorTemplate.

func (*RelationshipSelectorTemplate) DeepCopyInto added in v1.0.532

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*RelationshipSelectorTemplate) Eval added in v1.0.532

Eval evaluates the template and returns a RelationshipSelector. If any of the filter returns an empty value, the evaluation results to a nil selector. i.e. if a lookup is non-empty, it must return a non-empty value.

func (*RelationshipSelectorTemplate) IsEmpty added in v1.0.532

func (t *RelationshipSelectorTemplate) IsEmpty() bool

type StartOption added in v1.0.564

type StartOption func(config Config) Config

type Table added in v1.0.253

type Table interface {
	TableName() string
}

type TopologyOptions added in v1.0.11

type TopologyOptions = query.TopologyOptions

type TopologyResponse added in v1.0.71

type TopologyResponse = query.TopologyResponse

func QueryTopology added in v1.0.24

func QueryTopology(ctx gocontext.Context, dbpool *pgxpool.Pool, params TopologyOptions) (*TopologyResponse, error)

deprecated use query.Topology

Directories

Path Synopsis
hack
pkg
kube/labels
Package labels implements a simple label system, parsing and matching selectors with sets of labels.
Package labels implements a simple label system, parsing and matching selectors with sets of labels.
pg

Jump to

Keyboard shortcuts

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