logtracr

package module
v0.0.0-...-2eabd16 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

Logtracr: a go-logr flight recorder backend

This package implements a log flight recorder backend compatible with the logr interface. Please check the design document for more details

The package is used mostly in conjunction Kubernetes' klog in the kubernetes ecosystem, but is meant to be generic and working with any logr-based solution.

What is a log flight recorder

Let's borrow a great concise description from the go blog:

Suppose you work on a web service and an RPC took a very long time.
You couldn’t start tracing at the point you knew the RPC was already taking a while, because the root cause of the slow request already happened and wasn’t recorded.
[...]
The insight with flight recording is to have tracing on continuously and always keep the most recent trace data around, just in case.
Then, once something interesting happens, the program can just write out whatever it has!

This package wants to offer the same functionality but for logs, to enable (better) review, auditing, support of the program decisions.

Maturity

This is a ALPHA grade implementation.

LICENSE

Apache v2

Documentation

Index

Constants

View Source
const (
	LogTracrDirEnvVar      string = "LOGTRACR_DUMP_DIR"
	LogTracrIntervalEnvVar string = "LOGTRACR_DUMP_INTERVAL"
	LogTracrVerboseEnvVar  string = "LOGTRACR_VERBOSE"
)

Variables

This section is empty.

Functions

func DefaultBackend

func DefaultBackend() *log.Logger

func GetLogIDKey

func GetLogIDKey() string

func New

func New(std stdr.StdLogger, lc *TracrMap, verbose int, opts stdr.Options) logr.Logger

func RunForever

func RunForever(ctx context.Context, logger logr.Logger, interval time.Duration, baseDirectory string, lc *TracrMap)

func SetLogIDKey

func SetLogIDKey(val string)

func SetupWithEnv

func SetupWithEnv(ctx context.Context, backend *log.Logger) (logr.Logger, logr.Logger, error)

func SetupWithParams

func SetupWithParams(ctx context.Context, backend *log.Logger, params Params) (logr.Logger, logr.Logger)

Types

type Config

type Config struct {
	Verbose       int           `json:"verbose"`
	DumpInterval  time.Duration `json:"dumpInterval"`
	DumpDirectory string        `json:"dumpDirectory"`
}

func ConfigFromEnv

func ConfigFromEnv() (Config, error)

type EnvVarMissing

type EnvVarMissing struct {
	Name string
}

func (*EnvVarMissing) Error

func (ev *EnvVarMissing) Error() string

type Params

type Params struct {
	Conf        Config
	MainSink    *logr.Logger // optional, use nil to let the package use its defaults
	Timestamper TimeFunc
}

type SpanBlob

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

func (*SpanBlob) IsExpired

func (ln *SpanBlob) IsExpired(now time.Time, delta time.Duration) bool

type TimeFunc

type TimeFunc func() time.Time

type TracrMap

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

func NewTracrMap

func NewTracrMap(timeFunc TimeFunc) *TracrMap

func (*TracrMap) Get

func (lc *TracrMap) Get(logID string) (string, bool)

Get is (mostly) meant for testing purposes

func (*TracrMap) Len

func (lc *TracrMap) Len() int

Len is (mostly) meant for testing purposes

func (*TracrMap) PopExpired

func (lc *TracrMap) PopExpired(now time.Time, delta time.Duration) []*SpanBlob

func (*TracrMap) Put

func (lc *TracrMap) Put(logID, data string) error

type UnsupportedSetting

type UnsupportedSetting struct {
	Name  string
	Value string
}

func (*UnsupportedSetting) Error

func (us *UnsupportedSetting) Error() string

Jump to

Keyboard shortcuts

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