parsers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

Glaukos time-elapsed parser flow:

  1. Event type check: Whenever glaukos gets an event, check that it is a fully-manageable event. If not, do not continue
  2. Get relevant events: Get the history of events from codex and run through the list to find events related to the last reboot-cycle (all events with the second most recent boot-time up to events with a birthdate less than the incoming fully-manageable event). While doing this, also perform the following Comparator checks:
    • Make sure that the boot-time of the fully-manageable event is the newest boot-time. If it isn’t, add the NewerBootTimeFound tag to metrics and do not continue.
  3. Run through each event in the list of relevant events (adding the incoming fully-manageable event to the list). For the entire list, perform the following checks.
    • Checks that, upon failure, will result in cycle-tags (tags that are applied to an entire boot-cycle). These tags will be added to a counter. For each tag, a counter is incremented with the tag as a label value.
      • Specific metadata fields are the same for all events in the past cycle.
      • Transaction_uuid between events in this list are different.
      • An online and offline event exists for each session id in this list.
      • Among events with the same boot-time: the metadata/fw-name, metadata/hw-last-reboot-reason, metadata/webpa-protocol are all the same.
    • Checks that, upon failure, result in individual tags for each event in the list. For each tag per event, a counter is incremented with the tag as label value.
      • Event-type matches one of the possible outcomes.
      • Boot-time is present and within the configured time frame.
      • Birthdate is present and within the configured time frame.
      • Boot-time is present and after the same date in 2015.
      • All device-id occurrences within the source, destination, and metadata of the event are consistent. The first device ID found is considered the correct one.
      • All time values in the destination are at least 10s after the boot-time.
      • Timestamps in the destination are within 60s of the birthdate.
  4. If there are no error tags:
    • Subtract the birthdate of the fully-manageable event from the boot-time and calculate the time elapsed. If no errors arise during the calculation, add the time duration to the proper histogram.
    • Find the reboot-pending event (if it exists) and calculate the time elapsed. If no errors arise during the calculation, add the time duration to the proper histogram.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCycleError

func AddCycleError(counter *prometheus.CounterVec, event interpreter.Event, errorTag string)

AddCycleError adds a cycle error tag to the cycle error counter.

func AddDuration

func AddDuration(histogram prometheus.ObserverVec, duration float64, event interpreter.Event)

AddDuration adds the duration to the specific histogram.

func AddEventError

func AddEventError(counter *prometheus.CounterVec, event interpreter.Event, errorTag string)

AddEventError adds a error tag to the event error counter.

func NewParserValidator

func NewParserValidator(cycleValidator cycleValidation, eventValidator eventValidation, activateFunc func([]interpreter.Event, interpreter.Event) bool) *parserValidator

NewParserValidator creates a new parserValidator.

func ParseTime

func ParseTime(e interpreter.Event, location TimeLocation) time.Time

ParseTime gets the time from the proper location of an Event

func Provide

func Provide() fx.Option

Provide bundles everything needed for setting up all of the event objects for easier wiring into an uber fx application.

func ProvideEventMetrics

func ProvideEventMetrics() fx.Option

ProvideEventMetrics builds the event-related metrics and makes them available to the container.

Types

type CalculatorFunc

type CalculatorFunc func([]interpreter.Event, interpreter.Event) error

CalculatorFunc is a function that calculates a duration and returns an error if there is a problem while performing the calculations.

func BootDurationCalculator

func BootDurationCalculator(logger *zap.Logger, successCallback func(interpreter.Event, float64)) CalculatorFunc

BootDurationCalculator returns a CalculatorFunc that calculates the time between the birthdate and the boot-time of an event, calling the successCallback if a duration is successfully calculated.

func (CalculatorFunc) Calculate

func (cf CalculatorFunc) Calculate(events []interpreter.Event, event interpreter.Event) error

Calculate implements the DurationCalculator interface.

type CycleValidationConfig

type CycleValidationConfig struct {
	Key                enums.CycleValidationType
	CycleType          string // validate reboot events or last cycle events
	MetadataValidators []string
	EventOrder         []string // the cycle will be sorted in descending order by boot-time, then birthdate
}

CycleValidationConfig is the config for a cycle validator.

type DurationCalculator

type DurationCalculator interface {
	Calculate([]interpreter.Event, interpreter.Event) error
}

DurationCalculator calculates the different durations in a boot cycle.

type EventClient

type EventClient interface {
	GetEvents(deviceID string) []interpreter.Event
}

EventClient is an interface that provides a list of events related to a device.

type EventToCurrentCalculator

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

EventToCurrentCalculator calculates the difference between the current event and a previous event.

func NewEventToCurrentCalculator

func NewEventToCurrentCalculator(eventFinder Finder, successCallback func(currentEvent interpreter.Event, foundEvent interpreter.Event, duration float64), logger *zap.Logger) (*EventToCurrentCalculator, error)

NewEventToCurrentCalculator creates a new EventToCurrentCalculator and an error if the finder is nil.

func (*EventToCurrentCalculator) Calculate

func (c *EventToCurrentCalculator) Calculate(events []interpreter.Event, event interpreter.Event) error

Calculate implements the DurationCalculator interface by subtracting the birthdates of the two events.

type EventValidationConfig

type EventValidationConfig struct {
	Key                        enums.EventValidationType
	BootTimeValidator          TimeValidationConfig
	BirthdateValidator         TimeValidationConfig
	ValidEventTypes            []string
	MinBootDuration            time.Duration
	BirthdateAlignmentDuration time.Duration
}

EventValidationConfig is the config for each of the validators.

type EventsParser

type EventsParser interface {
	Parse(eventsHistory []interpreter.Event, currentEvent interpreter.Event) ([]interpreter.Event, error)
}

EventsParser parses the relevant events from a device's history of events and returns those events.

type Finder

type Finder interface {
	Find(events []interpreter.Event, incomingEvent interpreter.Event) (interpreter.Event, error)
}

Finder returns a specific event in a list of events.

type Measures

type Measures struct {
	fx.In
	MetadataFields            *prometheus.CounterVec            `name:"metadata_fields"`
	TotalUnparsableCount      *prometheus.CounterVec            `name:"total_unparsable_count"`
	RebootUnparsableCount     *prometheus.CounterVec            `name:"reboot_unparsable_count"`
	EventErrorTags            *prometheus.CounterVec            `name:"event_errors"`
	BootCycleErrorTags        *prometheus.CounterVec            `name:"boot_cycle_errors"`
	RebootCycleErrorTags      *prometheus.CounterVec            `name:"reboot_cycle_errors"`
	BootToManageableHistogram prometheus.ObserverVec            `name:"boot_to_manageable"`
	TimeElapsedHistograms     map[string]prometheus.ObserverVec `name:"time_elapsed_histograms"`
}

Measures tracks the various event-related metrics.

func (*Measures) AddMetadata

func (m *Measures) AddMetadata(metadataKey string)

AddMetadata adds to the metadata parser.

func (*Measures) AddRebootUnparsable

func (m *Measures) AddRebootUnparsable(reason string, event interpreter.Event)

AddRebootUnparsable adds to the RebootUnparsable counter.

func (*Measures) AddTotalUnparsable

func (m *Measures) AddTotalUnparsable(parserName string)

AddTotalUnparsable adds to the total unparsable counter.

type MetadataParser

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

MetadataParser parses messages coming in and counts the various metadata keys of each request.

func (*MetadataParser) Name

func (m *MetadataParser) Name() string

Name returns the name of the parser. Implements the Parser interface.

func (*MetadataParser) Parse

func (m *MetadataParser) Parse(event interpreter.Event)

Parse gathers metrics for each metadata key.

type ParserValidator

type ParserValidator interface {
	Validate(events []interpreter.Event, currentEvent interpreter.Event) (bool, error)
}

ParserValidator parses (if needed) the events from the list of events passed in and runs validation on this subset of events.

type RebootDurationParser

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

RebootDurationParser is triggered whenever glaukos receives a fully-manageable event. Validates the event and the last boot-cycle, calculating the boot and reboot durations.

func (*RebootDurationParser) Name

func (p *RebootDurationParser) Name() string

Name implements the Parser interface.

func (*RebootDurationParser) Parse

func (p *RebootDurationParser) Parse(currentEvent interpreter.Event)

Parse takes an event, validates it, and calculates the time elapsed if everything is valid.

Steps:
1. HW & FW: Get the hardware and firmware values stored in the event's metadata to use as labels in Prometheus metrics.
2. Destination check: check that the incoming event is a fully-manageable event.
3. Basic checks: Check that the boot-time and device id exists.
4. Get events: Get history of events from codex, parse into slice with relevant events.
5. Parse and Validate: Go through parsers and parse and validate as needed.
6. Calculate time elapsed: Go through duration calculators to calculate durations and add to appropriate histograms.

type RebootLoggerIn

type RebootLoggerIn struct {
	fx.In
	Logger *zap.Logger `name:"reboot_parser_logger"`
}

type RebootParserConfig

type RebootParserConfig struct {
	EventValidators         []EventValidationConfig
	CycleValidators         []CycleValidationConfig
	TimeElapsedCalculations []TimeElapsedConfig
}

RebootParserConfig contains the information for which validators should be created.

type RebootParserIn

type RebootParserIn struct {
	fx.In
	Name             string               `name:"reboot_parser_name"`
	Logger           *zap.Logger          `name:"reboot_parser_logger"`
	ParserValidators []ParserValidator    `group:"reboot_parser_validators"`
	Calculators      []DurationCalculator `group:"duration_calculators"`
	Measures         Measures
	CodexClient      *events.CodexClient
}

type RebootParserNameIn

type RebootParserNameIn struct {
	fx.In
	Name string `name:"reboot_parser_name"`
}

type TimeElapsedConfig

type TimeElapsedConfig struct {
	Name        string
	SessionType string
	EventType   string
}

TimeElapsedConfig contains information for calculating the time between a fully-manageable event and another event.

type TimeLocation

type TimeLocation int

TimeLocation is an enum to determine which timestamp should be used in timeElapsed calculations

const (
	Birthdate TimeLocation = iota
	Boottime
)

func ParseTimeLocation

func ParseTimeLocation(location string) TimeLocation

ParseTimeLocation returns the TimeLocation enum when given a string.

type TimeValidationConfig

type TimeValidationConfig struct {
	ValidFrom    time.Duration
	ValidTo      time.Duration
	MinValidYear int
}

TimeValidationConfig is the config used for time validation.

type ValidatorsIn

type ValidatorsIn struct {
	fx.In
	EventValidator       validation.Validator   `name:"event_validator"`
	LastCycleValidator   history.CycleValidator `name:"last_cycle_validator"`
	RebootCycleValidator history.CycleValidator `name:"reboot_cycle_validator"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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