Documentation
¶
Index ¶
- Constants
- Variables
- func ApplySessionProperties(ctx dutyContext.Context, tx *gorm.DB) error
- func BindGoFlags()
- func BindPFlags(flags *pflag.FlagSet, opts ...StartOption)
- func CheckSummary(ctx context.Context, checkID string) (*models.CheckSummary, error)
- func DefaultGormConfig() *gorm.Config
- func Delete(ctx dutyContext.Context, model Table) error
- func FreePort() int
- func GetComponent(ctx gocontext.Context, db *gorm.DB, id string) (*models.Component, error)
- func GetResourceContext(ctx context.Context, resource types.ResourceSelectable) map[string]any
- func HasMigrationsRun(ctx dutyContext.Context) (bool, error)
- func InitDB(config api.Config) (*dutyContext.Context, error)
- func LookupComponents(ctx context.Context, lookup RelationshipSelectorTemplate, ...) ([]uuid.UUID, error)
- func LookupConfigs(ctx context.Context, lookup RelationshipSelectorTemplate, ...) ([]uuid.UUID, error)
- func Migrate(config api.Config) error
- func NewDB(connection string) (*sql.DB, error)
- func NewGorm(connection string, config *gorm.Config) (*gorm.DB, error)
- func NewGormFromPool(pool *pgxpool.Pool, config *gorm.Config) (*gorm.DB, error)
- func NewPgxPool(connection string) (*pgxpool.Pool, error)
- func Now() clause.Expr
- func SetupDB(config api.Config) (gormDB *gorm.DB, pgxpool *pgxpool.Pool, err error)
- func Start(name string, opts ...StartOption) (context.Context, func(), error)
- type FindOption
- type Lookup
- type RelationshipSelector
- type RelationshipSelectorTemplate
- func (in *RelationshipSelectorTemplate) DeepCopy() *RelationshipSelectorTemplate
- func (in *RelationshipSelectorTemplate) DeepCopyInto(out *RelationshipSelectorTemplate)
- func (t *RelationshipSelectorTemplate) Eval(labels map[string]string, env map[string]any) (*RelationshipSelector, error)
- func (t *RelationshipSelectorTemplate) IsEmpty() bool
- type StartOption
- type Table
- type TopologyOptions
- type TopologyResponse
Constants ¶
const SessionPropertyPrefix = "postgres.session."
SessionPropertyPrefix is the property-name prefix used to route values into Postgres session/transaction-local settings. A property "postgres.session.debug_log.enabled=on" translates to `SET LOCAL debug_log.enabled = 'on'` inside the provided transaction.
Variables ¶
var ClientOnly = func(config api.Config) api.Config { config.Postgrest.Disable = true config.SkipMigrations = true return config }
var DefaultQueryTimeout = 30 * time.Second
var DisableKubernetes = func(config api.Config) api.Config { config.DisableKubernetes = true return config }
var DisablePostgrest = func(config api.Config) api.Config { config.Postgrest.Disable = true return config }
var DisableRLS = func(config api.Config) api.Config { config.DisableRLS = true return config }
var EnableMetrics = func(config api.Config) api.Config { config.Metrics = true return config }
var EnableRLS = func(config api.Config) api.Config { config.EnableRLS = true return config }
var KratosAuth = func(config api.Config) api.Config { config.KratosAuth = true return config }
var LocalFilter = "deleted_at is NULL AND agent_id = '00000000-0000-0000-0000-000000000000' OR agent_id IS NULL"
var LogLevel string
LogLevel is the log level for gorm logger
var RunMigrations = func(config api.Config) api.Config { config.MigrationMode = api.SkipByDefault config.RunMigrations = true return config }
var SkipChangelogMigration = func(config api.Config) api.Config { config.SkipMigrationFiles = []string{"007_events.sql", "012_changelog_triggers_others.sql", "012_changelog_triggers_scrapers.sql"} return config }
var SkipMigrationByDefaultMode = func(config api.Config) api.Config { config.MigrationMode = api.SkipByDefault return config }
var SkipMigrations = func(config api.Config) api.Config { config.MigrationMode = api.RunByDefault config.RunMigrations = false return config }
Functions ¶
func ApplySessionProperties ¶ added in v1.0.1260
func ApplySessionProperties(ctx dutyContext.Context, tx *gorm.DB) error
ApplySessionProperties runs `SET LOCAL <key> = '<value>'` inside the supplied GORM transaction for every property in `ctx.Properties()` whose key starts with SessionPropertyPrefix. The prefix is stripped before the SET is issued. Values are passed as text; Postgres will coerce them as needed by the GUC's type.
The transaction MUST be an open tx (returned by `db.Begin()` or `db.WithContext(...).Begin()`); `SET LOCAL` outside a tx has no effect.
Typical usage:
tx := ctx.DB().Begin()
if err := duty.ApplySessionProperties(ctx, tx); err != nil { ... }
defer tx.Rollback() // or commit
...
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
deprecated use query.CheckSummaryByID
func DefaultGormConfig ¶ added in v1.0.6
func GetComponent ¶ added in v1.0.45
deprecated use query.GetComponent
func GetResourceContext ¶ added in v1.0.829
GetResourceContext returns a common set of variables to be used in templates and expressions
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 LookupComponents ¶ added in v1.0.236
func LookupConfigs ¶ added in v1.0.236
func NewGorm ¶
creates a new Gorm DB connection using the global pgx connection pool, must be called after NewPgxPool
func NewGormFromPool ¶ added in v1.0.1260
NewGormFromPool creates a Gorm DB that reuses an existing *pgxpool.Pool. This is the preferred path for the main application: it shares the same connection pool (and therefore the ConnConfig.OnNotice handler, pgx Tracer, and MaxConns) with any direct pgxpool users on the same context.
In particular, without sharing the pool, RAISE NOTICE / RAISE WARNING messages emitted by server-side functions are invisible to Go callers using ctx.DB() (GORM) because the stdlib driver creates its own pgx config with no notice handler.
stdlib.OpenDBFromPool automatically sets db.SetMaxIdleConns(0), so GORM will not hoard connections from the pool.
Types ¶
type FindOption ¶ added in v1.0.253
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
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Lookup.
func (*Lookup) DeepCopyInto ¶ added in v1.0.532
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
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
func (in *RelationshipSelector) DeepCopy() *RelationshipSelector
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
func (in *RelationshipSelectorTemplate) DeepCopy() *RelationshipSelectorTemplate
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RelationshipSelectorTemplate.
func (*RelationshipSelectorTemplate) DeepCopyInto ¶ added in v1.0.532
func (in *RelationshipSelectorTemplate) DeepCopyInto(out *RelationshipSelectorTemplate)
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
func (t *RelationshipSelectorTemplate) Eval(labels map[string]string, env map[string]any) (*RelationshipSelector, error)
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 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
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
hack
|
|
|
generate-schemas
command
|
|
|
migrate
command
|
|
|
azureloganalytics
ABOUTME: Implements log searching against Azure Monitor Log Analytics workspaces.
|
ABOUTME: Implements log searching against Azure Monitor Log Analytics workspaces. |
|
pkg
|
|
|
kube/auth
Referenced from: https://github.com/kubernetes/client-go/blob/master/plugin/pkg/client/auth/exec/exec.go
|
Referenced from: https://github.com/kubernetes/client-go/blob/master/plugin/pkg/client/auth/exec/exec.go |
|
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. |