Documentation ¶
Index ¶
- Constants
- Variables
- func HttpHandler() func(http.ResponseWriter, *http.Request)
- func SetupDefaultAuditor(c *Config, stopCh <-chan struct{})
- type Auditor
- type Config
- type Event
- type EventFluentWriter
- type EventHelper
- func (e *EventHelper) Container(name string) *EventHelper
- func (e *EventHelper) Do() error
- func (e *EventHelper) Group(name string) *EventHelper
- func (e *EventHelper) Message(format string, args ...interface{}) *EventHelper
- func (e *EventHelper) Node() *EventHelper
- func (e *EventHelper) Pod(ns string, name string) *EventHelper
- func (e *EventHelper) Reason(reason string) *EventHelper
- func (e *EventHelper) Unknown(name string) *EventHelper
- type EventIterator
- type EventReader
- type EventWriter
- type JsonResponse
- type LogReader
- type LogWriter
Constants ¶
const ( MaxFileSize = 1 << 21 // 2MB DefaultLogDirMode fs.FileMode = 0755 )
Variables ¶
var (
ChunkSize = 4096
)
var ( // Default is the global object to simplify the cost of use, instead of frequently passing objects. Default = NewEmptyAuditor() )
Functions ¶
func HttpHandler ¶
func HttpHandler() func(http.ResponseWriter, *http.Request)
HttpHandler return the http handler to read audit events with the `Default` auditor.
func SetupDefaultAuditor ¶
func SetupDefaultAuditor(c *Config, stopCh <-chan struct{})
SetupDefaultAuditor initialize the `Default` auditor.
Types ¶
type Auditor ¶
type Auditor interface { Run(stopCh <-chan struct{}) error LoggerWriter() EventFluentWriter HttpHandler() func(http.ResponseWriter, *http.Request) }
func NewAuditor ¶
func NewEmptyAuditor ¶
func NewEmptyAuditor() Auditor
type Config ¶
type Config struct { LogDir string Verbose int MaxDiskSpaceMB int MaxConcurrentReaders int ActiveReaderTTL time.Duration DefaultEventsLimit int MaxEventsLimit int TickerDuration time.Duration }
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
type Event ¶
type Event struct { CreatedAt time.Time `json:"createdAt,omitempty"` Type string `json:"type,omitempty"` Level string `json:"level,omitempty"` Namespace string `json:"namespace,omitempty"` Name string `json:"name,omitempty"` Container string `json:"container,omitempty"` Reason string `json:"reason,omitempty"` Message string `json:"message,omitempty"` }
Event captures all the information that can be included in an API audit log.
type EventFluentWriter ¶
type EventFluentWriter interface { // V create an eventHelper with Level verbose V(verbose int) *EventHelper // Flush flush events to the underly storage Flush() error // Close close the underly writer Close() error }
Fluent APIs to support log in one line: logger.V(1).WithNode().WithReason().Do()
func NewFluentEventLogger ¶
func NewFluentEventLogger(dir string, sizeMB int, verbose int) EventFluentWriter
NewFluentEventLogger create an EventFluentWriter to simplify the audit.
type EventHelper ¶
type EventHelper struct { Event // contains filtered or unexported fields }
EventHelper is a helper struct use to support fluent APIs
func V ¶
func V(verbose int) *EventHelper
V create an EventHelper with Level verbose to record audit events with the `Default` auditor.
func (*EventHelper) Container ¶
func (e *EventHelper) Container(name string) *EventHelper
Container set the event container to name
func (*EventHelper) Group ¶
func (e *EventHelper) Group(name string) *EventHelper
Group set the event type to resource
func (*EventHelper) Message ¶
func (e *EventHelper) Message(format string, args ...interface{}) *EventHelper
Message set the message as the inputs
func (*EventHelper) Node ¶
func (e *EventHelper) Node() *EventHelper
Node set the event type to 'node'
func (*EventHelper) Pod ¶
func (e *EventHelper) Pod(ns string, name string) *EventHelper
Pod set the event type to 'pod'
func (*EventHelper) Reason ¶
func (e *EventHelper) Reason(reason string) *EventHelper
Reason set the event reason to reason
func (*EventHelper) Unknown ¶
func (e *EventHelper) Unknown(name string) *EventHelper
Unknown set the event type to unknown object(pod, node or something else)
type EventIterator ¶
EventInterator is an interator to tail the event log
type EventReader ¶
type EventReader interface {
NewReverseInterator() EventIterator
}
EventReader is used to manager the event interators
func NewEventReader ¶
func NewEventReader(dir string) EventReader
type EventWriter ¶
type EventWriter interface { // Log write an event to the underly storage Log(verbose int, event *Event) error // Flush flush events to the underly storage Flush() error // Close close the writer Close() error }
EventWriter is used to record events to audit key changes
func NewEventLogger ¶
func NewEventLogger(dir string, sizeMB int, verbose int) EventWriter
NewEventLogger create an EventWriter, it won't open the underly file until do a log call. verbose=0 means no restrictions on verbose