context

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 56 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CelEnvFuncs = make(map[string]func(Context) cel.EnvOption)
View Source
var (
	ErrNotFound = errors.New("NOT_FOUND")
)
View Source
var LatencyBuckets = []float64{
	float64(10 * time.Millisecond),
	float64(100 * time.Millisecond),
	float64(500 * time.Millisecond),
	float64(1 * time.Second),
	float64(10 * time.Second),
}
View Source
var LongLatencyBuckets = []float64{
	float64(1 * time.Second),
	float64(10 * time.Second),
	float64(100 * time.Second),
	float64(1000 * time.Second),
}
View Source
var MetricsLogLevel = 5
View Source
var ShortLatencyBuckets = []float64{
	float64(10 * time.Millisecond),
	float64(100 * time.Millisecond),
	float64(500 * time.Millisecond),
}
View Source
var TemplateFuncs = make(map[string]func(Context) any)

Functions

func FindConnection

func FindConnection(ctx Context, name, namespace string) (*models.Connection, error)

FindConnection returns the connection with the given type and name

func FindConnectionByURL

func FindConnectionByURL(ctx Context, connectionString string) (*models.Connection, error)

FindConnectionByURL retrieves a connection from the given connection string. The connection string is expected to be in one of the following forms:

  • connection://<namespace>/<name> or connection://<name>
  • the UUID of the connection.

func GetConfigMapFromCache

func GetConfigMapFromCache(ctx Context, namespace, name, key string) (string, error)

func GetConnection

func GetConnection(ctx Context, name, namespace string) (*models.Connection, error)

func GetEnvStringFromCache

func GetEnvStringFromCache(ctx Context, env string, namespace string) (string, error)

func GetEnvValueFromCache

func GetEnvValueFromCache(ctx Context, input types.EnvVar, namespace string) (value string, err error)

func GetHelmValueFromCache

func GetHelmValueFromCache(ctx Context, namespace, releaseName, key string) (string, error)

func GetHelmValuesFromCache added in v0.1.1

func GetHelmValuesFromCache(ctx Context, namespace, releaseName string) (map[string]any, error)

func GetSecretFromCache

func GetSecretFromCache(ctx Context, namespace, name, key string) (string, error)

func GetServiceAccountTokenFromCache

func GetServiceAccountTokenFromCache(ctx Context, namespace, serviceAccount string) (string, error)

func HydrateConnection

func HydrateConnection(ctx Context, connection *models.Connection) (*models.Connection, error)

Create a cache with a default expiration time of 5 minutes, and which purges expired items every 10 minutes var connectionCache = cache.New(5*time.Minute, 10*time.Minute)

func HydrateConnectionByURL

func HydrateConnectionByURL(ctx Context, connectionString string) (*models.Connection, error)

HydrateConnectionByURL retrieves a connection from the given connection string. The connection string is expected to be in one of the following forms:

  • connection://<namespace>/<name> or connection://<name>
  • the UUID of the connection.

func IsValidConnectionURL

func IsValidConnectionURL(connectionString string) bool

func Objects

func Objects(k gocontext.Context) []any

func UpdateProperties

func UpdateProperties(ctx Context, props map[string]string) error

func UpdateProperty

func UpdateProperty(ctx Context, key, value string) error

Types

type AnnotationsAccessor

type AnnotationsAccessor interface {
	GetAnnotations() map[string]string
}

type Context

type Context struct {
	commons.Context
}

func New

func New(opts ...commons.ContextOptions) Context

func NewContext

func NewContext(baseCtx gocontext.Context, opts ...commons.ContextOptions) Context

func (Context) ClearCache

func (k Context) ClearCache()

func (Context) ConnectionString

func (k Context) ConnectionString() string

ConnectionString returns the connection string for the database

func (Context) Counter

func (k Context) Counter(name string, labels ...string) Counter

func (Context) DB

func (k Context) DB() *gorm.DB

func (Context) Fast

func (k Context) Fast(name ...string) Context

Fast with limiting tracing and db logging

func (Context) FastDB

func (k Context) FastDB(name ...string) *gorm.DB

FastDB returns a db suitable for high-performance usage, with limited logging and tracing

func (Context) Gauge

func (k Context) Gauge(name string, labels ...string) Gauge

func (Context) GetAnnotations

func (k Context) GetAnnotations() map[string]string

func (Context) GetConfigMapFromCache

func (k Context) GetConfigMapFromCache(namespace, name, key string) (string, error)

func (Context) GetConnection

func (ctx Context) GetConnection(name, namespace string) (*models.Connection, error)

func (Context) GetEnvStringFromCache

func (k Context) GetEnvStringFromCache(env string, namespace string) (string, error)

func (Context) GetEnvValueFromCache

func (k Context) GetEnvValueFromCache(input types.EnvVar, namespace string) (string, error)

func (Context) GetLabels

func (k Context) GetLabels() map[string]string

func (Context) GetLoggingContext

func (k Context) GetLoggingContext() map[string]any

func (Context) GetName

func (k Context) GetName() string

func (Context) GetNamespace

func (k Context) GetNamespace() string

func (Context) GetObjectMeta

func (k Context) GetObjectMeta() metav1.ObjectMeta

func (Context) GetSecretFromCache

func (k Context) GetSecretFromCache(namespace, name, key string) (string, error)

func (Context) Histogram

func (k Context) Histogram(name string, buckets []float64, labels ...string) Histogram

func (Context) HydrateConnection

func (k Context) HydrateConnection(connection *models.Connection) (*models.Connection, error)

func (Context) HydrateConnectionByURL

func (k Context) HydrateConnectionByURL(connectionString string) (*models.Connection, error)

func (Context) IsTracing

func (k Context) IsTracing() bool

func (Context) KubeAuthFingerprint

func (k Context) KubeAuthFingerprint() string

KubeAuthFingerprint generates a unique SHA-256 hash to identify the Kubernetes API server and client authentication details from the REST configuration.

func (Context) Kubernetes

func (k Context) Kubernetes() (*dutyKubernetes.Client, error)

func (Context) KubernetesConnection

func (k Context) KubernetesConnection() KubernetesConnection

func (Context) LocalKubernetes

func (k Context) LocalKubernetes(kubeconfigPaths ...string) (*dutyKubernetes.Client, error)

func (Context) Lookup

func (ctx Context) Lookup(namespace string) *EnvVarSourceBuilder

func (Context) NewStructTemplater

func (k Context) NewStructTemplater(vals map[string]any, requiredTag string, funcs map[string]any) gomplate.StructTemplater

func (Context) Objects

func (k Context) Objects() []any

func (Context) Oops

func (k Context) Oops(tags ...string) oops.OopsErrorBuilder

func (Context) Pool

func (k Context) Pool() *pgxpool.Pool

func (Context) Properties

func (k Context) Properties() Properties

Properties returns a cached map of properties

func (Context) RunTemplate

func (k Context) RunTemplate(t gomplate.Template, env map[string]any) (string, error)

func (Context) RunTemplateBool

func (k Context) RunTemplateBool(t gomplate.Template, env map[string]any) (bool, error)

func (Context) StartSpan

func (k Context) StartSpan(name string) (Context, trace.Span)

func (Context) String

func (k Context) String() string

func (Context) Subject

func (k Context) Subject() string

func (Context) Topology

func (k Context) Topology() any

func (Context) Transaction

func (k Context) Transaction(fn func(ctx Context, span trace.Span) error, opts ...any) error

func (Context) Verbose

func (k Context) Verbose() logger.Logger

func (Context) WithAnyValue

func (k Context) WithAnyValue(key, val any) Context

// Deprecated: use WithValue

func (Context) WithAppendObject

func (k Context) WithAppendObject(object any) Context

func (Context) WithConnectionString

func (k Context) WithConnectionString(connectionString string) Context

WithConnectionString sets the connection string for the database

func (Context) WithDB

func (k Context) WithDB(db *gorm.DB, pool *pgxpool.Pool) Context

func (Context) WithDBLogLevel

func (k Context) WithDBLogLevel(level any) Context

Changes the minimum log level for db statements

func (Context) WithDBLogger

func (k Context) WithDBLogger(name string, baseLevel any) Context

Returns a new named logger, the default db log level starts at INFO for DDL and then increases to TRACE1 depending on the query type and rows returned set a baseLevel at Debug, will increase all the levels by 1

func (Context) WithDeadline

func (k Context) WithDeadline(deadline time.Time) (Context, gocontext.CancelFunc)

func (Context) WithDebug

func (k Context) WithDebug() Context

func (Context) WithKubernetes

func (k Context) WithKubernetes(conn KubernetesConnection) Context

func (Context) WithLocalKubernetes

func (k Context) WithLocalKubernetes(client *dutyKubernetes.Client) Context

func (Context) WithLoggingValues

func (k Context) WithLoggingValues(args ...interface{}) Context

func (Context) WithName

func (k Context) WithName(name string) Context

func (Context) WithNamespace

func (k Context) WithNamespace(namespace string) Context

func (Context) WithObject

func (k Context) WithObject(object ...any) Context

Order the objects from parent -> child

func (Context) WithSubject

func (k Context) WithSubject(subject string) Context

Rbac subject

func (Context) WithTimeout

func (k Context) WithTimeout(timeout time.Duration) (Context, gocontext.CancelFunc)

func (Context) WithTopology

func (k Context) WithTopology(topology any) Context

func (Context) WithTrace

func (k Context) WithTrace() Context

func (Context) WithValue

func (k Context) WithValue(key, val any) Context

func (Context) WithoutName

func (k Context) WithoutName() Context

func (Context) WithoutTracing

func (k Context) WithoutTracing() Context

func (Context) Wrap

func (k Context) Wrap(ctx gocontext.Context) Context

func (Context) WrapEcho

func (k Context) WrapEcho(c echo.Context) Context

type ContextAccessor

type ContextAccessor interface {
	Context() map[string]any
}

type ContextAccessor2

type ContextAccessor2 interface {
	GetContext() map[string]any
}

type Counter

type Counter struct {
	Context Context
	Name    string
	Labels  map[string]string
	Counter *prometheus.CounterVec
}

func (Counter) Add

func (c Counter) Add(count int)

func (Counter) AddFloat

func (c Counter) AddFloat(count float64)

func (*Counter) Label

func (c *Counter) Label(k, v string) Counter

type EnvVarSourceBuilder

type EnvVarSourceBuilder struct {
	// contains filtered or unexported fields
}

func (*EnvVarSourceBuilder) GetString

func (b *EnvVarSourceBuilder) GetString() (string, error)

func (*EnvVarSourceBuilder) MustGetString

func (b *EnvVarSourceBuilder) MustGetString() string

func (*EnvVarSourceBuilder) WithConfigMapKeyRef

func (b *EnvVarSourceBuilder) WithConfigMapKeyRef(name, key string) *EnvVarSourceBuilder

func (*EnvVarSourceBuilder) WithHelmRef

func (b *EnvVarSourceBuilder) WithHelmRef(name, key string) *EnvVarSourceBuilder

func (*EnvVarSourceBuilder) WithSecretKeyRef

func (b *EnvVarSourceBuilder) WithSecretKeyRef(name, key string) *EnvVarSourceBuilder

func (*EnvVarSourceBuilder) WithServiceAccount

func (b *EnvVarSourceBuilder) WithServiceAccount(name string) *EnvVarSourceBuilder

type Gauge

type Gauge struct {
	Context Context
	Name    string
	Labels  map[string]string
	Gauge   *prometheus.GaugeVec
}

func (Gauge) Add

func (g Gauge) Add(count float64)

func (Gauge) Set

func (g Gauge) Set(count float64)

func (Gauge) Sub

func (g Gauge) Sub(count float64)

type Gormable

type Gormable interface {
	DB() *gorm.DB
}

type Histogram

type Histogram struct {
	Context   Context
	Name      string
	Histogram *prometheus.HistogramVec
	Labels    map[string]string
}

func (*Histogram) Label

func (h *Histogram) Label(k, v string) Histogram

func (Histogram) Record

func (h Histogram) Record(duration time.Duration)

func (Histogram) Since

func (h Histogram) Since(s time.Time)

type KubernetesClient

type KubernetesClient struct {
	*dutyKubernetes.Client
	Connection KubernetesConnection
	// contains filtered or unexported fields
}

func NewKubernetesClient

func NewKubernetesClient(ctx Context, conn KubernetesConnection) (*KubernetesClient, error)

func (KubernetesClient) HasExpired

func (c KubernetesClient) HasExpired() bool

func (*KubernetesClient) Refresh

func (c *KubernetesClient) Refresh(ctx Context) (*rest.Config, error)

func (*KubernetesClient) SetExpiry

func (c *KubernetesClient) SetExpiry(def time.Duration)

func (*KubernetesClient) SetLogger

func (c *KubernetesClient) SetLogger(log logger.Logger)

type KubernetesConnection

type KubernetesConnection interface {
	Populate(Context, bool) (kubernetes.Interface, *rest.Config, error)
	Hash() string
	CanExpire() bool
	String() string
}

type LabelsAccessor

type LabelsAccessor interface {
	GetLabels() map[string]string
}

type NameAccessor

type NameAccessor interface {
	GetName() string
}

type NamespaceAccess

type NamespaceAccess interface {
	GetNamespace() string
}

type PKAccessor

type PKAccessor interface {
	PK() string
}

type Poolable

type Poolable interface {
	Pool() *pgxpool.Pool
}

type Properties

type Properties map[string]string

func (Properties) Duration

func (p Properties) Duration(key string, def time.Duration) time.Duration

func (Properties) Int

func (p Properties) Int(key string, def int) int

func (Properties) Off

func (p Properties) Off(key string, def bool) bool

Returns true if the property is false|disabled|off, if there is no property it defaults to true

func (Properties) On

func (p Properties) On(def bool, keys ...string) bool

Returns true if the property is true|enabled|on, if there is no property it defaults to true

func (Properties) String

func (p Properties) String(key string, def string) string

func (Properties) SupportedProperties

func (p Properties) SupportedProperties() map[string]PropertyType

type PropertyType

type PropertyType struct {
	Key     string      `json:"-"`
	Value   interface{} `json:"value,omitempty"`
	Default interface{} `json:"default,omitempty"`
	Type    string      `json:"type,omitempty"`
}

Jump to

Keyboard shortcuts

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