evtlog

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package evtlog provides a client/service which allows asynchronously reporting events to the '/_event' endpoint provided by 'ns_server'.

Index

Constants

View Source
const (
	// MaxEncodedLength is the maximum size of the JSON encoded event.
	MaxEncodedLength = 3 * 1024

	// MaxBufferedEventsPerDispatcher is the default number of events (and minimum) number of events that can be buffered
	// per-goroutine.
	MaxBufferedEventsPerDispatcher = 8
)
View Source
const (
	// EndpointPostEvent is the endpoint used to 'POST' events.
	EndpointPostEvent cbrest.Endpoint = "/_event"
)

Variables

View Source
var ErrTooLarge = errors.New("payload too large")

ErrTooLarge returned if the encoded event payload is larger than 3KiB.

Functions

This section is empty.

Types

type Client

type Client struct {
	*cbrest.Client
}

Client is a wrapper around the 'cbrest' client which implements the required methods to log events.

func NewClient

func NewClient(options ServiceOptions) (*Client, error)

NewClient creates a new client using the given options, the client may communicate using basic/cert auth depending on the auth provider/tls config provided.

func (*Client) PostEvent

func (c *Client) PostEvent(ctx context.Context, event []byte) error

PostEvent posts the given encoded event to the local 'ns_server' instance.

type Component

type Component string

Component represents to component which is reporting this event, for a complete list of supported components see MB-47035 and its parent.

type Event

type Event struct {
	// Required attributes which, if not supplied will result in an error.
	Component   Component `json:"component"`
	Severity    Severity  `json:"severity"`
	EventID     EventID   `json:"event_id"`
	Description string    `json:"description"`

	// Optional attributes which may/or may not be supplied; the general recommendation is to include some additional
	// useful information which describes the event.
	ExtraAttributes any    `json:"extra_attributes"`
	SubComponent    string `json:"sub_component"`
}

Event represents an event, and is the structure which will be used when reporting events using a 'Service'.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON implements the 'json.Marshaller' interface, and fills in any required automatically generated fields.

type EventID

type EventID uint

EventID is the unique identifier of the event type, currently each service is apportioned 1024 event ids.

NOTE: See MB-47035 and its parent for more information about which services are supplied which ids.

type Service

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

Service exposes an interface to report events to the local 'ns_server' instance.

func NewService

func NewService(options ServiceOptions) (*Service, error)

NewService creates a new service using the given options.

func (*Service) Close

func (s *Service) Close()

Close gracefully stops the service, reporting any buffered events then closes the internal pool/client.

NOTE: A service being used after closure has undefined behavior.

func (*Service) Report

func (s *Service) Report(event Event)

Report the given event asynchronously, logging event/error if we fail to do so.

NOTE: To "receive" these logged errors, a 'Logger' implementation should be provided to 'log.SetLogger'.

type ServiceOptions

type ServiceOptions struct {
	ManagementPort uint16
	Provider       aprov.Provider
	TLSConfig      *tls.Config

	// ReqResLogLevel is the level at which HTTP requests/responses will be logged; this directly maps to the 'cbrest'
	// client value.
	ReqResLogLevel log.Level

	// The number of goroutines to create for reporting events.
	Dispatchers int

	// MaxBufferedEventsPerDispatcher directly maps to the 'hofp.BufferMultiplier' value, and dictates the number of events
	// that can be buffered per-goroutine.
	MaxBufferedEventsPerDispatcher int

	// Logger is the passed Logger struct that implements the Log method for logger the user wants to use.
	Logger log.Logger
}

ServiceOptions encapsulates the options available when creating a new event log service.

type Severity

type Severity string

Severity represents the severity of an event.

const (
	// SeverityInfo is the 'info' level, describing something that occurs during normal execution and is therefore
	// expected.
	SeverityInfo Severity = "info"

	// SeverityWarn is the 'warn' level, describing something that's normal (or perhaps rare/unexpected).
	SeverityWarn Severity = "warn"

	// SeverityError is the 'error' level, describing error scenarios where something has failed/occurred that shouldn't
	// happen during normal execution.
	SeverityError Severity = "error"

	// SeverityFatal is the 'fatal' level, describing an error case which is unrecoverable.
	SeverityFatal Severity = "fatal"
)

Jump to

Keyboard shortcuts

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