elephantine

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 25 Imported by: 11

README

Elephantine

Shared functionality for Elephant systems. It's most likely not something anyone outside of Elephant would be interested in.

Documentation

Index

Constants

View Source
const (
	LogKeyLogLevel     = "log_level"
	LogKeyError        = "err"
	LogKeyCountMetric  = "count_metric"
	LogKeyDocumentUUID = "document_uuid"
	LogKeyTransaction  = "transaction"
	LogKeyOCSource     = "oc_source"
	LogKeyOCVersion    = "oc_version"
	LogKeyOCEvent      = "oc_event"
	LogKeyChannel      = "channel"
	LogKeyMessage      = "message"
	LogKeyDelay        = "delay"
	LogKeyBucket       = "bucket"
	LogKeyObjectKey    = "object_key"
	LogKeyComponent    = "component"
	LogKeyCount        = "count"
	LogKeyEventID      = "event_id"
	LogKeyEventType    = "event_type"
	LogKeyJobLock      = "job_lock"
	LogKeyJobLockID    = "job_lock_id"
	LogKeyState        = "state"
	LogKeyIndex        = "index"
	LogKeyRoute        = "route"
	LogKeyService      = "service"
	LogKeyMethod       = "method"
)

Log attribute keys used throughout the application.

Variables

This section is empty.

Functions

func IsHTTPErrorWithStatus

func IsHTTPErrorWithStatus(err error, status int) bool

func IsTwirpErrorCode added in v0.4.0

func IsTwirpErrorCode(err error, code twirp.ErrorCode) bool

func ListenAndServeContext

func ListenAndServeContext(ctx context.Context, server *http.Server) error

func NewTwirpMetricsHooks added in v0.4.0

func NewTwirpMetricsHooks(opts ...TwirpMetricOptionFunc) (*twirp.ServerHooks, error)

NewTwirpMetricsHooks creates new twirp hooks enabling prometheus metrics.

func ResolveParameter

func ResolveParameter(
	ctx context.Context, c *cli.Context, src ParameterSource, name string,
) (string, error)

func SetUpLogger

func SetUpLogger(logLevel string, w io.Writer) *slog.Logger

SetUpLogger creates a default JSON logger and sets it as the global logger.

func UnmarshalFile

func UnmarshalFile(path string, o interface{}) error

func UnmarshalHTTPResource

func UnmarshalHTTPResource(resURL string, o interface{}) error

Types

type GracefulShutdown added in v0.4.0

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

func NewGracefulShutdown added in v0.4.0

func NewGracefulShutdown(logger *slog.Logger, timeout time.Duration) *GracefulShutdown

func (*GracefulShutdown) CancelOnQuit added in v0.4.0

func (gs *GracefulShutdown) CancelOnQuit(ctx context.Context) context.Context

func (*GracefulShutdown) CancelOnStop added in v0.4.0

func (gs *GracefulShutdown) CancelOnStop(ctx context.Context) context.Context

func (*GracefulShutdown) ShouldQuit added in v0.4.0

func (gs *GracefulShutdown) ShouldQuit() <-chan struct{}

func (*GracefulShutdown) ShouldStop added in v0.4.0

func (gs *GracefulShutdown) ShouldStop() <-chan struct{}

func (*GracefulShutdown) Stop added in v0.4.0

func (gs *GracefulShutdown) Stop()

type HTTPClientInstrumentation added in v0.4.0

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

func NewHTTPClientIntrumentation added in v0.4.0

func NewHTTPClientIntrumentation(
	registerer prometheus.Registerer,
) (*HTTPClientInstrumentation, error)

func (*HTTPClientInstrumentation) Client added in v0.4.0

func (ci *HTTPClientInstrumentation) Client(name string, client *http.Client) error

type HTTPError

type HTTPError struct {
	Status     string
	StatusCode int
	Header     http.Header
	Body       io.Reader
}

func HTTPErrorFromResponse

func HTTPErrorFromResponse(res *http.Response) *HTTPError

func HTTPErrorf

func HTTPErrorf(statusCode int, format string, a ...any) *HTTPError

func NewHTTPError

func NewHTTPError(statusCode int, message string) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HealthServer

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

HealthServer exposes health endpoints, metrics, and PPROF endpoints.

func NewHealthServer

func NewHealthServer(addr string) *HealthServer

func (*HealthServer) AddReadyFunction

func (s *HealthServer) AddReadyFunction(name string, fn ReadyFunc)

func (*HealthServer) Close

func (s *HealthServer) Close() error

func (*HealthServer) ListenAndServe

func (s *HealthServer) ListenAndServe(ctx context.Context) error

type LazySSM

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

func NewLazySSM

func NewLazySSM() *LazySSM

func (*LazySSM) GetParameterValue

func (l *LazySSM) GetParameterValue(ctx context.Context, name string) (string, error)

type ParameterSource

type ParameterSource interface {
	GetParameterValue(ctx context.Context, name string) (string, error)
}

func GetParameterSource

func GetParameterSource(name string) (ParameterSource, error)

type ReadyFunc

type ReadyFunc func(ctx context.Context) error

type ReadyResult

type ReadyResult struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

type TwirpMetricOptionFunc added in v0.4.0

type TwirpMetricOptionFunc func(opts *TwirpMetricsOptions)

func WithTwirpMetricsRegisterer added in v0.4.0

func WithTwirpMetricsRegisterer(reg prometheus.Registerer) TwirpMetricOptionFunc

WithTwirpMetricsRegisterer uses a custom registerer for Twirp metrics.

func WithTwirpMetricsStaticTestLatency added in v0.4.0

func WithTwirpMetricsStaticTestLatency(latency time.Duration) TwirpMetricOptionFunc

WithTwirpMetricsStaticTestLatency configures the RPC metrics to report a static duration.

type TwirpMetricsOptions added in v0.4.0

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

Directories

Path Synopsis
pg

Jump to

Keyboard shortcuts

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