...

Package record

import "k8s.io/client-go/tools/record"
Overview
Index
Subdirectories

Overview ▾

Package record has all client logic for recording and reporting "k8s.io/api/core/v1".Event events.

Index ▾

func EventAggregatorByReasonFunc(event *v1.Event) (string, string)
func EventAggregatorByReasonMessageFunc(event *v1.Event) string
type BroadcasterOption
    func WithContext(ctx context.Context) BroadcasterOption
    func WithCorrelatorOptions(options CorrelatorOptions) BroadcasterOption
    func WithSleepDuration(sleepDuration time.Duration) BroadcasterOption
type CorrelatorOptions
type EventAggregator
    func NewEventAggregator(lruCacheSize int, keyFunc EventAggregatorKeyFunc, messageFunc EventAggregatorMessageFunc, maxEvents int, maxIntervalInSeconds int, clock clock.PassiveClock) *EventAggregator
    func (e *EventAggregator) EventAggregate(newEvent *v1.Event) (*v1.Event, string)
type EventAggregatorKeyFunc
type EventAggregatorMessageFunc
type EventBroadcaster
    func NewBroadcaster(opts ...BroadcasterOption) EventBroadcaster
    func NewBroadcasterForTests(sleepDuration time.Duration) EventBroadcaster
    func NewBroadcasterWithCorrelatorOptions(options CorrelatorOptions) EventBroadcaster
type EventCorrelateResult
type EventCorrelator
    func NewEventCorrelator(clock clock.PassiveClock) *EventCorrelator
    func NewEventCorrelatorWithOptions(options CorrelatorOptions) *EventCorrelator
    func (c *EventCorrelator) EventCorrelate(newEvent *v1.Event) (*EventCorrelateResult, error)
    func (c *EventCorrelator) UpdateState(event *v1.Event)
type EventFilterFunc
type EventRecorder
type EventRecorderAdapter
    func NewEventRecorderAdapter(recorder EventRecorderLogger) *EventRecorderAdapter
    func (a *EventRecorderAdapter) Eventf(regarding, _ runtime.Object, eventtype, reason, action, note string, args ...interface{})
    func (a *EventRecorderAdapter) WithLogger(logger klog.Logger) internalevents.EventRecorderLogger
type EventRecorderLogger
type EventSink
type EventSourceObjectSpamFilter
    func NewEventSourceObjectSpamFilter(lruCacheSize, burst int, qps float32, clock clock.PassiveClock, spamKeyFunc EventSpamKeyFunc) *EventSourceObjectSpamFilter
    func (f *EventSourceObjectSpamFilter) Filter(event *v1.Event) bool
type EventSpamKeyFunc
type FakeRecorder
    func NewFakeRecorder(bufferSize int) *FakeRecorder
    func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{})
    func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string)
    func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})
    func (f *FakeRecorder) WithLogger(logger klog.Logger) EventRecorderLogger

Package files

doc.go event.go events_cache.go fake.go

func EventAggregatorByReasonFunc

func EventAggregatorByReasonFunc(event *v1.Event) (string, string)

EventAggregatorByReasonFunc aggregates events by exact match on event.Source, event.InvolvedObject, event.Type, event.Reason, event.ReportingController and event.ReportingInstance

func EventAggregatorByReasonMessageFunc

func EventAggregatorByReasonMessageFunc(event *v1.Event) string

EventAggregatorByReasonMessageFunc returns an aggregate message by prefixing the incoming message

type BroadcasterOption

type BroadcasterOption func(*config)

func WithContext

func WithContext(ctx context.Context) BroadcasterOption

WithContext sets a context for the broadcaster. Canceling the context will shut down the broadcaster, Shutdown doesn't need to be called. The context can also be used to provide a logger.

func WithCorrelatorOptions

func WithCorrelatorOptions(options CorrelatorOptions) BroadcasterOption

func WithSleepDuration

func WithSleepDuration(sleepDuration time.Duration) BroadcasterOption

type CorrelatorOptions

CorrelatorOptions allows you to change the default of the EventSourceObjectSpamFilter and EventAggregator in EventCorrelator

type CorrelatorOptions struct {
    // The lru cache size used for both EventSourceObjectSpamFilter and the EventAggregator
    // If not specified (zero value), the default specified in events_cache.go will be picked
    // This means that the LRUCacheSize has to be greater than 0.
    LRUCacheSize int
    // The burst size used by the token bucket rate filtering in EventSourceObjectSpamFilter
    // If not specified (zero value), the default specified in events_cache.go will be picked
    // This means that the BurstSize has to be greater than 0.
    BurstSize int
    // The fill rate of the token bucket in queries per second in EventSourceObjectSpamFilter
    // If not specified (zero value), the default specified in events_cache.go will be picked
    // This means that the QPS has to be greater than 0.
    QPS float32
    // The func used by the EventAggregator to group event keys for aggregation
    // If not specified (zero value), EventAggregatorByReasonFunc will be used
    KeyFunc EventAggregatorKeyFunc
    // The func used by the EventAggregator to produced aggregated message
    // If not specified (zero value), EventAggregatorByReasonMessageFunc will be used
    MessageFunc EventAggregatorMessageFunc
    // The number of events in an interval before aggregation happens by the EventAggregator
    // If not specified (zero value), the default specified in events_cache.go will be picked
    // This means that the MaxEvents has to be greater than 0
    MaxEvents int
    // The amount of time in seconds that must transpire since the last occurrence of a similar event before it is considered new by the EventAggregator
    // If not specified (zero value), the default specified in events_cache.go will be picked
    // This means that the MaxIntervalInSeconds has to be greater than 0
    MaxIntervalInSeconds int
    // The clock used by the EventAggregator to allow for testing
    // If not specified (zero value), clock.RealClock{} will be used
    Clock clock.PassiveClock
    // The func used by EventFilterFunc, which returns a key for given event, based on which filtering will take place
    // If not specified (zero value), getSpamKey will be used
    SpamKeyFunc EventSpamKeyFunc
}

type EventAggregator

EventAggregator identifies similar events and aggregates them into a single event

type EventAggregator struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewEventAggregator

func NewEventAggregator(lruCacheSize int, keyFunc EventAggregatorKeyFunc, messageFunc EventAggregatorMessageFunc,
    maxEvents int, maxIntervalInSeconds int, clock clock.PassiveClock) *EventAggregator

NewEventAggregator returns a new instance of an EventAggregator

func (*EventAggregator) EventAggregate

func (e *EventAggregator) EventAggregate(newEvent *v1.Event) (*v1.Event, string)

EventAggregate checks if a similar event has been seen according to the aggregation configuration (max events, max interval, etc) and returns:

type EventAggregatorKeyFunc

EventAggregatorKeyFunc is responsible for grouping events for aggregation It returns a tuple of the following: aggregateKey - key the identifies the aggregate group to bucket this event localKey - key that makes this event in the local group

type EventAggregatorKeyFunc func(event *v1.Event) (aggregateKey string, localKey string)

type EventAggregatorMessageFunc

EventAggregatorMessageFunc is responsible for producing an aggregation message

type EventAggregatorMessageFunc func(event *v1.Event) string

type EventBroadcaster

EventBroadcaster knows how to receive events and send them to any EventSink, watcher, or log.

type EventBroadcaster interface {
    // StartEventWatcher starts sending events received from this EventBroadcaster to the given
    // event handler function. The return value can be ignored or used to stop recording, if
    // desired.
    StartEventWatcher(eventHandler func(*v1.Event)) watch.Interface

    // StartRecordingToSink starts sending events received from this EventBroadcaster to the given
    // sink. The return value can be ignored or used to stop recording, if desired.
    StartRecordingToSink(sink EventSink) watch.Interface

    // StartLogging starts sending events received from this EventBroadcaster to the given logging
    // function. The return value can be ignored or used to stop recording, if desired.
    StartLogging(logf func(format string, args ...interface{})) watch.Interface

    // StartStructuredLogging starts sending events received from this EventBroadcaster to the structured
    // logging function. The return value can be ignored or used to stop recording, if desired.
    StartStructuredLogging(verbosity klog.Level) watch.Interface

    // NewRecorder returns an EventRecorder that can be used to send events to this EventBroadcaster
    // with the event source set to the given event source.
    NewRecorder(scheme *runtime.Scheme, source v1.EventSource) EventRecorderLogger

    // Shutdown shuts down the broadcaster. Once the broadcaster is shut
    // down, it will only try to record an event in a sink once before
    // giving up on it with an error message.
    Shutdown()
}

func NewBroadcaster

func NewBroadcaster(opts ...BroadcasterOption) EventBroadcaster

Creates a new event broadcaster.

func NewBroadcasterForTests

func NewBroadcasterForTests(sleepDuration time.Duration) EventBroadcaster

func NewBroadcasterWithCorrelatorOptions

func NewBroadcasterWithCorrelatorOptions(options CorrelatorOptions) EventBroadcaster

type EventCorrelateResult

EventCorrelateResult is the result of a Correlate

type EventCorrelateResult struct {
    // the event after correlation
    Event *v1.Event
    // if provided, perform a strategic patch when updating the record on the server
    Patch []byte
    // if true, do no further processing of the event
    Skip bool
}

type EventCorrelator

EventCorrelator processes all incoming events and performs analysis to avoid overwhelming the system. It can filter all incoming events to see if the event should be filtered from further processing. It can aggregate similar events that occur frequently to protect the system from spamming events that are difficult for users to distinguish. It performs de-duplication to ensure events that are observed multiple times are compacted into a single event with increasing counts.

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

func NewEventCorrelator

func NewEventCorrelator(clock clock.PassiveClock) *EventCorrelator

NewEventCorrelator returns an EventCorrelator configured with default values.

The EventCorrelator is responsible for event filtering, aggregating, and counting prior to interacting with the API server to record the event.

The default behavior is as follows:

func NewEventCorrelatorWithOptions

func NewEventCorrelatorWithOptions(options CorrelatorOptions) *EventCorrelator

func (*EventCorrelator) EventCorrelate

func (c *EventCorrelator) EventCorrelate(newEvent *v1.Event) (*EventCorrelateResult, error)

EventCorrelate filters, aggregates, counts, and de-duplicates all incoming events

func (*EventCorrelator) UpdateState

func (c *EventCorrelator) UpdateState(event *v1.Event)

UpdateState based on the latest observed state from server

type EventFilterFunc

EventFilterFunc is a function that returns true if the event should be skipped

type EventFilterFunc func(event *v1.Event) bool

type EventRecorder

EventRecorder knows how to record events on behalf of an EventSource.

type EventRecorder interface {
    // Event constructs an event from the given information and puts it in the queue for sending.
    // 'object' is the object this event is about. Event will make a reference-- or you may also
    // pass a reference to the object directly.
    // 'eventtype' of this event, and can be one of Normal, Warning. New types could be added in future
    // 'reason' is the reason this event is generated. 'reason' should be short and unique; it
    // should be in UpperCamelCase format (starting with a capital letter). "reason" will be used
    // to automate handling of events, so imagine people writing switch statements to handle them.
    // You want to make that easy.
    // 'message' is intended to be human readable.
    //
    // The resulting event will be created in the same namespace as the reference object.
    Event(object runtime.Object, eventtype, reason, message string)

    // Eventf is just like Event, but with Sprintf for the message field.
    Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})

    // AnnotatedEventf is just like eventf, but with annotations attached
    AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{})
}

type EventRecorderAdapter

EventRecorderAdapter is a wrapper around a "k8s.io/client-go/tools/record".EventRecorder implementing the new "k8s.io/client-go/tools/events".EventRecorder interface.

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

func NewEventRecorderAdapter

func NewEventRecorderAdapter(recorder EventRecorderLogger) *EventRecorderAdapter

NewEventRecorderAdapter returns an adapter implementing the new "k8s.io/client-go/tools/events".EventRecorder interface.

func (*EventRecorderAdapter) Eventf

func (a *EventRecorderAdapter) Eventf(regarding, _ runtime.Object, eventtype, reason, action, note string, args ...interface{})

Eventf is a wrapper around v1 Eventf

func (*EventRecorderAdapter) WithLogger

func (a *EventRecorderAdapter) WithLogger(logger klog.Logger) internalevents.EventRecorderLogger

type EventRecorderLogger

EventRecorderLogger extends EventRecorder such that a logger can be set for methods in EventRecorder. Normally, those methods uses the global default logger to record errors and debug messages. If that is not desired, use WithLogger to provide a logger instance.

type EventRecorderLogger interface {
    EventRecorder

    // WithLogger replaces the context used for logging. This is a cheap call
    // and meant to be used for contextual logging:
    //    recorder := ...
    //    logger := klog.FromContext(ctx)
    //    recorder.WithLogger(logger).Eventf(...)
    WithLogger(logger klog.Logger) EventRecorderLogger
}

type EventSink

EventSink knows how to store events (client.Client implements it.) EventSink must respect the namespace that will be embedded in 'event'. It is assumed that EventSink will return the same sorts of errors as pkg/client's REST client.

type EventSink interface {
    Create(event *v1.Event) (*v1.Event, error)
    Update(event *v1.Event) (*v1.Event, error)
    Patch(oldEvent *v1.Event, data []byte) (*v1.Event, error)
}

type EventSourceObjectSpamFilter

EventSourceObjectSpamFilter is responsible for throttling the amount of events a source and object can produce.

type EventSourceObjectSpamFilter struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewEventSourceObjectSpamFilter

func NewEventSourceObjectSpamFilter(lruCacheSize, burst int, qps float32, clock clock.PassiveClock, spamKeyFunc EventSpamKeyFunc) *EventSourceObjectSpamFilter

NewEventSourceObjectSpamFilter allows burst events from a source about an object with the specified qps refill.

func (*EventSourceObjectSpamFilter) Filter

func (f *EventSourceObjectSpamFilter) Filter(event *v1.Event) bool

Filter controls that a given source+object are not exceeding the allowed rate.

type EventSpamKeyFunc

EventSpamKeyFunc is a function that returns unique key based on provided event

type EventSpamKeyFunc func(event *v1.Event) string

type FakeRecorder

FakeRecorder is used as a fake during tests. It is thread safe. It is usable when created manually and not by NewFakeRecorder, however all events may be thrown away in this case.

type FakeRecorder struct {
    Events chan string

    IncludeObject bool
}

func NewFakeRecorder

func NewFakeRecorder(bufferSize int) *FakeRecorder

NewFakeRecorder creates new fake event recorder with event channel with buffer of given size.

func (*FakeRecorder) AnnotatedEventf

func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{})

func (*FakeRecorder) Event

func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string)

func (*FakeRecorder) Eventf

func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})

func (*FakeRecorder) WithLogger

func (f *FakeRecorder) WithLogger(logger klog.Logger) EventRecorderLogger

Subdirectories

Name Synopsis
..
util