parsing

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirmwareLabel = "firmware"
	HardwareLabel = "hardware"
	ParserLabel   = "parser_type"
	ReasonLabel   = "reason"
)
View Source
const (
	MetadataKeyLabel = "metadata_key"
)

Variables

This section is empty.

Functions

func GetDeviceID

func GetDeviceID(destinationRegex *regexp.Regexp, destination string) (string, error)

GetDeviceID grabs the device id from a given destination string.

func GetEventBootTime

func GetEventBootTime(msg Event) (int64, error)

GetEventBootTime grabs the boot-time from a Event's metadata.

func GetMetadataValue added in v0.2.3

func GetMetadataValue(key string, metadata map[string]string) (string, bool)

Checks a map for a specific key, allowing for keys with or without forward-slash

func GetValidBirthDate added in v0.2.0

func GetValidBirthDate(currTime func() time.Time, payload []byte) (time.Time, error)

GetValidBirthDate attempts to get the birthdate from the payload. If it doesn't exist, the current time is returned. If the birthdate is too old or too far in the future, 0 is returned.

func GetWRPBootTime

func GetWRPBootTime(msg wrp.Message) (int64, error)

GetWRPBootTime grabs the boot-time from a wrp.Message's metadata.

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 AuthAcquirerConfig

type AuthAcquirerConfig struct {
	JWT   acquire.RemoteBearerTokenAcquirerOptions
	Basic string
}

type BootTimeParser

type BootTimeParser struct {
	Measures Measures
	Logger   log.Logger
	Client   EventClient
}

BootTimeParser takes online events and calculates the reboot time of a device by getting the last offline event from codex.

func (*BootTimeParser) Parse

func (b *BootTimeParser) Parse(wrpWithTime queue.WrpWithTime) error
Parse calculates boot time of devices by querying codex for the latest offline events and performing

calculations. An analysis of codex events is only triggered by a device online event from caduceus. Steps to calculate boot time:

  1. Determine if message is online event.
  2. Get lastest Offline event from Codex where metadata field of /boot-time differs of online event.
  3. Subtract Online birthdate from steps 2 event Birthdate.
  4. Record Metric.

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	MaxRequests                uint32
	Interval                   time.Duration
	Timeout                    time.Duration
	ConsecutiveFailuresAllowed uint32
}

type CodexClient

type CodexClient struct {
	Address string
	Auth    acquire.Acquirer
	// contains filtered or unexported fields
}

func (*CodexClient) GetEvents

func (c *CodexClient) GetEvents(device string) []Event

GetEvents queries codex for events related to a device.

type CodexConfig

type CodexConfig struct {
	Address        string
	Auth           AuthAcquirerConfig
	MaxRetryCount  int
	CircuitBreaker CircuitBreakerConfig
}

CodexConfig determines the auth and address for connecting to the codex cluster.

type Event

type Event struct {
	MsgType         int               `json:"msg_type"`
	Source          string            `json:"source"`
	Dest            string            `json:"dest,omitempty"`
	TransactionUUID string            `json:"transaction_uuid,omitempty"`
	ContentType     string            `json:"content_type,omitempty"`
	Metadata        map[string]string `json:"metadata"`
	Payload         string            `json:"payload,omitempty"`
	BirthDate       int64             `json:"birth_date"`
	PartnerIDs      []string          `json:"partner_ids,omitempty"`
}

Event is the struct that codex query results will be unmarshalled into.

type EventClient

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

type Measures

type Measures struct {
	fx.In
	MetadataFields        metrics.Counter   `name:"metadata_fields"`
	BootTimeHistogram     metrics.Histogram `name:"boot_time_duration"`
	RebootTimeHistogram   metrics.Histogram `name:"reboot_to_manageable_duration"`
	UnparsableEventsCount metrics.Counter   `name:"unparsable_events_count"`
}

Measures tracks the various event-related metrics.

type MetadataParser

type MetadataParser struct {
	Measures Measures
}

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

func (MetadataParser) Parse

func (m MetadataParser) Parse(wrpWithTime queue.WrpWithTime) error

Parse gathers metrics for each metadata key.

type ParsersIn

type ParsersIn struct {
	fx.In
	Parsers []queue.Parser `group:"parsers"`
}

ParsersIn brings together all of the different types of parsers that glaukos uses.

type RebootTimeParser added in v0.2.0

type RebootTimeParser struct {
	Measures Measures
	Logger   log.Logger
	Client   EventClient
	Label    string
}

RebootTimeParser takes fully-manageable events and calculates the reboot time of a device by getting the last reboot-pending event from codex.

func (*RebootTimeParser) Parse added in v0.2.0

func (b *RebootTimeParser) Parse(wrpWithTime queue.WrpWithTime) error
 Parse calculates reboot time of devices by querying codex for the latest device events and performing
 calculations. An analysis of codex events is only triggered by a fully-manageable event from caduceus.
 Steps to calculate boot time:
	 1) Determine if message is fully-manageable event.
	 2) Get latest reboot-pending event from Codex where metadata field of /boot-time differs from the fully-manageable event.
	 3) Subtract fully-manageable's birthdate from step 2's event birthdate.
	 4) Record Metric.

Jump to

Keyboard shortcuts

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