duty

package module
v1.0.277 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 28 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

  1. make test will run tests against a new embedded postgres instance

If you set DUTY_DB_URL environment variable to the postgres db, each test will run against a new database called duty_gingko

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultQueryTimeout = 30 * time.Second
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

Functions

func BindFlags added in v1.0.214

func BindFlags(flags *pflag.FlagSet)

func CheckSummary added in v1.0.164

func CheckSummary(ctx DBContext, 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 FindCachedAgent added in v1.0.172

func FindCachedAgent(ctx DBContext, id string) (*models.Agent, error)

func FindCachedCanary added in v1.0.172

func FindCachedCanary(ctx DBContext, id string) (*models.Canary, error)

func FindCachedCheck added in v1.0.172

func FindCachedCheck(ctx DBContext, id string) (*models.Check, error)

func FindCachedComponent added in v1.0.172

func FindCachedComponent(ctx DBContext, id string) (*models.Component, error)

func FindCachedConfig added in v1.0.172

func FindCachedConfig(ctx DBContext, id string) (*models.ConfigItem, error)

func FindCachedIncident added in v1.0.172

func FindCachedIncident(ctx DBContext, id string) (*models.Incident, error)

func FindChecks added in v1.0.253

func FindChecks(ctx context.Context, resourceSelectors types.ResourceSelectors, opts ...FindOption) (components []models.Check, err error)

func FindChecksByLabel added in v1.0.253

func FindChecksByLabel(ctx context.Context, labelSelector string, opts ...FindOption) (components []models.Check, err error)

func FindComponents added in v1.0.253

func FindComponents(ctx context.Context, resourceSelectors types.ResourceSelectors, opts ...FindOption) (components []models.Component, err error)

func FindComponentsByField added in v1.0.253

func FindComponentsByField(ctx context.Context, fieldSelector string, opts ...FindOption) ([]models.Component, error)

func FindComponentsByLabel added in v1.0.253

func FindComponentsByLabel(ctx context.Context, labelSelector string, opts ...FindOption) (components []models.Component, err error)

func FindComponentsByName added in v1.0.269

func FindComponentsByName(ctx context.Context, name string, opts ...FindOption) ([]models.Component, error)

func FindPerson added in v1.0.178

func FindPerson(ctx DBContext, identifier string, opts ...GetterOption) (*models.Person, error)

FindPerson looks up a person by the given identifier which can either be

  • UUID
  • email

func FindTeam added in v1.0.178

func FindTeam(ctx DBContext, identifier string, opts ...GetterOption) (*models.Team, error)

FindTeam looks up a team by the given identifier which can either be

  • UUID
  • team name

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 GetConfigMapFromCache added in v1.0.45

func GetConfigMapFromCache(c kubernetes.Interface, namespace, name, key string) (string, error)

deprecated use the methods in the context package

func GetEnvStringFromCache added in v1.0.45

func GetEnvStringFromCache(c kubernetes.Interface, env string, namespace string) (string, error)

deprecated use the methods in the context package

func GetEnvValueFromCache added in v1.0.45

func GetEnvValueFromCache(c kubernetes.Interface, input types.EnvVar, namespace string) (string, error)

deprecated use the methods in the context package

func GetSecretFromCache added in v1.0.45

func GetSecretFromCache(c kubernetes.Interface, namespace, name, key string) (string, error)

deprecated use the methods in the context package

func InitDB added in v1.0.207

func InitDB(connection string, migrateOpts *migrate.MigrateOptions) (*dutyContext.Context, error)

func LookupComponents added in v1.0.236

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

func LookupConfigs added in v1.0.236

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

func Migrate added in v1.0.10

func Migrate(connection string, opts *migrate.MigrateOptions) 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 gocontext.Context, dbpool *pgxpool.Pool, opts ...query.CheckSummaryOptions) ([]models.CheckSummary, error)

deprecated use query.CheckSummary

func SetupDB added in v1.0.141

func SetupDB(connection string, migrateOpts *migrate.MigrateOptions) (gormDB *gorm.DB, pgxpool *pgxpool.Pool, err error)

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

Types

type DBContext added in v1.0.172

type DBContext interface {
	context.Context
	DB() *gorm.DB
	Pool() *pgxpool.Pool
}

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

type GetterOption added in v1.0.178

type GetterOption uint8
const (
	GetterOptionNoCache GetterOption = iota + 1
)

type GetterOptions added in v1.0.178

type GetterOptions []GetterOption

func (GetterOptions) IsSet added in v1.0.178

func (t GetterOptions) IsSet(option GetterOption) bool

type Lookup added in v1.0.236

type Lookup struct {
	// Expr is a cel-expression.
	Expr string `json:"expr,omitempty" yaml:"expr,omitempty"`
	// Value is the static value to use.
	Value string `json:"value,omitempty" yaml:"value,omitempty"`
	// Label specifies the key to lookup on the label.
	Label string `json:"label,omitempty" yaml:"label,omitempty"`
}

Lookup specifies the type of lookup to perform.

func (*Lookup) Empty added in v1.0.236

func (t *Lookup) Empty() bool

func (*Lookup) Eval added in v1.0.236

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

type LookupEvalResult added in v1.0.236

type LookupEvalResult struct {
	Name      string
	Namespace string
	Type      string
}

LookupEvalResult is the result of evaluation of a LookupSpec.

type LookupSpec added in v1.0.236

type LookupSpec struct {
	Name      Lookup `json:"name,omitempty" yaml:"name,omitempty"`
	Namespace Lookup `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	Type      Lookup `json:"type,omitempty" yaml:"type,omitempty"`
}

LookupSpec defines a tuple of fields to lookup.

func (*LookupSpec) Eval added in v1.0.236

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

Eval evaluates all the fields in the lookup spec based on labels and environment variables. Returns nil if any non-empty lookup evaluates to an empty value.

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
migrate Module
tests

Jump to

Keyboard shortcuts

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