context

package
v1.0.659 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 53 Imported by: 55

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 Local map[string]string
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 added in v1.0.207

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

FindConnection returns the connection with the given type and name

func FindConnectionByURL added in v1.0.207

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

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

func GetConnection added in v1.0.207

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

func GetEnvStringFromCache added in v1.0.207

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

func GetEnvValueFromCache added in v1.0.207

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

func GetHelmValueFromCache added in v1.0.239

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

func GetSecretFromCache added in v1.0.207

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

func GetServiceAccountTokenFromCache added in v1.0.233

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

func HydrateConnection added in v1.0.207

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

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

func IsValidConnectionURL(connectionString string) bool

func Objects added in v1.0.564

func Objects(k gocontext.Context) []any

func SetLocalProperty added in v1.0.310

func SetLocalProperty(property, value string)

func UpdateProperties added in v1.0.259

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

func UpdateProperty added in v1.0.259

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

Types

type AnnotationsAccessor added in v1.0.564

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

type Context

type Context struct {
	commons.Context
}

func New added in v1.0.253

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

func NewContext

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

func (Context) Agent added in v1.0.295

func (k Context) Agent() *models.Agent

func (Context) ClearCache added in v1.0.250

func (k Context) ClearCache()

func (Context) Counter added in v1.0.317

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

func (Context) DB

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

func (Context) Fast added in v1.0.325

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

Fast with limiting tracing and db logging

func (Context) FastDB added in v1.0.254

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

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

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

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

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

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

func (Context) IsTracing added in v1.0.325

func (k Context) IsTracing() bool

func (*Context) Kommons added in v1.0.202

func (k *Context) Kommons() *kommons.Client

func (*Context) Kubernetes

func (k *Context) Kubernetes() kubernetes.Interface

func (*Context) KubernetesDynamicClient added in v1.0.596

func (k *Context) KubernetesDynamicClient() *dutyKubernetes.DynamicClient

func (*Context) KubernetesRestConfig added in v1.0.596

func (k *Context) KubernetesRestConfig() *rest.Config

func (Context) NewStructTemplater added in v1.0.345

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

func (Context) Objects added in v1.0.564

func (k Context) Objects() []any

func (Context) Oops added in v1.0.564

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

func (Context) Pool added in v1.0.197

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

func (Context) Properties added in v1.0.245

func (k Context) Properties() Properties

Properties returns a cached map of properties

func (Context) RunTemplate added in v1.0.343

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

func (Context) StartSpan

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

func (Context) String added in v1.0.564

func (k Context) String() string

func (Context) Topology added in v1.0.276

func (k Context) Topology() any

func (Context) Transaction added in v1.0.564

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

func (Context) User

func (k Context) User() *models.Person

func (Context) Verbose added in v1.0.564

func (k Context) Verbose() logger.Logger

func (Context) WithAgent added in v1.0.295

func (k Context) WithAgent(agent models.Agent) Context

WithAgent sets the current session's agent in the context

func (Context) WithAnyValue added in v1.0.276

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

// Deprecated: use WithValue

func (Context) WithAppendObject added in v1.0.607

func (k Context) WithAppendObject(object any) Context

func (Context) WithDB

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

func (Context) WithDBLogLevel added in v1.0.250

func (k Context) WithDBLogLevel(level any) Context

Changes the minimum log level for db statements

func (Context) WithDBLogger added in v1.0.567

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

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

func (Context) WithDebug added in v1.0.254

func (k Context) WithDebug() Context

func (*Context) WithKubeconfig added in v1.0.596

func (k *Context) WithKubeconfig(input types.EnvVar) (*Context, error)

func (Context) WithKubernetes

func (k Context) WithKubernetes(client kubernetes.Interface, config *rest.Config) Context

func (Context) WithLoggingValues added in v1.0.564

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

func (Context) WithName added in v1.0.307

func (k Context) WithName(name string) Context

func (Context) WithNamespace added in v1.0.197

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) WithTimeout added in v1.0.197

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

func (Context) WithTopology added in v1.0.276

func (k Context) WithTopology(topology any) Context

func (Context) WithTrace added in v1.0.254

func (k Context) WithTrace() Context

func (Context) WithUser

func (k Context) WithUser(user *models.Person) Context

func (Context) WithValue added in v1.0.564

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

func (Context) WithoutName added in v1.0.307

func (k Context) WithoutName() Context

func (Context) WithoutTracing added in v1.0.325

func (k Context) WithoutTracing() Context

func (Context) Wrap added in v1.0.197

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

func (Context) WrapEcho added in v1.0.564

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

type ContextAccessor added in v1.0.564

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

type ContextAccessor2 added in v1.0.577

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

type Counter added in v1.0.317

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

func (Counter) Add added in v1.0.317

func (c Counter) Add(count int)

func (Counter) AddFloat added in v1.0.317

func (c Counter) AddFloat(count float64)

func (*Counter) Label added in v1.0.317

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

type Gauge added in v1.0.419

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

func (Gauge) Add added in v1.0.419

func (g Gauge) Add(count float64)

func (Gauge) Set added in v1.0.419

func (g Gauge) Set(count float64)

func (Gauge) Sub added in v1.0.419

func (g Gauge) Sub(count float64)

type Gormable added in v1.0.227

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

type Histogram added in v1.0.317

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

func (*Histogram) Label added in v1.0.317

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

func (Histogram) Record added in v1.0.317

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

func (Histogram) Since added in v1.0.317

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

type LabelsAccessor added in v1.0.564

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

type NameAccessor added in v1.0.564

type NameAccessor interface {
	GetName() string
}

type NamespaceAccess added in v1.0.564

type NamespaceAccess interface {
	GetNamespace() string
}

type PKAccessor added in v1.0.607

type PKAccessor interface {
	PK() string
}

type Poolable added in v1.0.227

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

type Properties added in v1.0.307

type Properties map[string]string

func (Properties) Duration added in v1.0.317

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

func (Properties) Int added in v1.0.317

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

func (Properties) Off added in v1.0.307

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

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

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

func (Properties) SupportedProperties added in v1.0.548

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

type PropertyType added in v1.0.549

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