olympus

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: LGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackLogPageSize int = 4000
View Source
var CutOfFrequencyRatio float64 = 15.0
View Source
var OLYMPUS_VERSION = "v0.5.8"

Current package version

View Source
var UnknownEndpointError = errors.New("unknown PushSubscription endpoint")

Functions

func AppendSuffix added in v0.5.6

func AppendSuffix(str string, suffix string) string

func BackInsertionSort

func BackInsertionSort[T any](slice []T, value T, less func(a, b T) bool) []T

func BackLinearSearch

func BackLinearSearch[T any](slice []T, value T, less func(a, b T) bool) int

func BuildNotificationPayload

func BuildNotificationPayload(updates []ZonedAlarmUpdate) ([]byte, error)

func CacheControl

func CacheControl(maxAge time.Duration) func(http.Handler) http.Handler

func EnableCORS

func EnableCORS(origins []string) func(http.Handler) http.Handler

func Execute

func Execute() error

func Golangify

func Golangify[T any](r *http.Request) (*T, error)

func HTTPLogWrap

func HTTPLogWrap(logger *logrus.Entry) func(h http.Handler) http.Handler

func Insert

func Insert[T any](slice []T, value T, index int) []T

func InsertSlice

func InsertSlice[T any](a, b []T, begin, end int) []T

func IsSubscribedTo

func IsSubscribedTo(zone string, level api.AlarmLevel, settings api.NotificationSettings) bool

func JSONify

func JSONify(w http.ResponseWriter, obj interface{})

func LinearSearch

func LinearSearch[T any](slice []T, value T, less func(a, b T) bool) int

func Max

func Max[T constraints.Ordered](a, b T) T

func MayBeSubscribedTo

func MayBeSubscribedTo(zone string, settings api.NotificationSettings) bool

func NewNotificationLogger

func NewNotificationLogger() *logNotification

func NopCloser

func NopCloser(w io.Writer) io.WriteCloser

func PrependPrefix added in v0.5.7

func PrependPrefix(str string, prefix string) string

func RecoverWrap

func RecoverWrap(logger *logrus.Entry) func(h http.Handler) http.Handler

func ZoneIdentifier

func ZoneIdentifier(hostname, zoneName string) string

Types

type AlarmLogger

type AlarmLogger interface {
	ActiveAlarmsCount() (failures, emergencies, warnings int)
	GetReports() []api.AlarmReport
	// PushAlarms adds a list of AlarmEvents to this logger.
	PushAlarms([]*api.AlarmUpdate, string)
	ClearDomain(string, time.Time)
}

func NewAlarmLogger

func NewAlarmLogger() AlarmLogger

type AlreadyExistError

type AlreadyExistError string

func (AlreadyExistError) Error

func (a AlreadyExistError) Error() string

type BatchingFilter

type BatchingFilter func(outgoing chan<- []ZonedAlarmUpdate, incoming <-chan ZonedAlarmUpdate)

func BatchAlarmUpdate

func BatchAlarmUpdate(batchPeriod time.Duration) BatchingFilter

Batches alarms updates so they are no more than a batch every silenceWindow

type CSRFHandler

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

func NewCSRFHandler

func NewCSRFHandler(secret []byte) (*CSRFHandler, error)

func (*CSRFHandler) CheckCSRFCookie

func (hh *CSRFHandler) CheckCSRFCookie(h http.Handler) http.Handler

func (*CSRFHandler) SetCSRFCookie

func (hh *CSRFHandler) SetCSRFCookie(h http.Handler) http.Handler

type ClimateDataDownsampler

type ClimateDataDownsampler interface {
	// Adds a new list of value to the sampler for a given time.Time
	// t. If mx is non nil, an asynchronous update will be performed.
	Add(values TimedValues)

	// Returns the resulting time series
	TimeSeries() api.ClimateTimeSeries
}

A ClimateDataDownsample is used to keep trace of a set of time series over a certain time window. It optimize system performance by greatly reducing the amount of data.

func NewClimateDataDownsampler

func NewClimateDataDownsampler(window, unit time.Duration, samples int) ClimateDataDownsampler

type ClimateLogger

type ClimateLogger interface {
	Host() string
	ZoneName() string
	ZoneIdentifier() string
	// PushTarget update current target for this logger.
	PushTarget(*api.ClimateTarget)
	// PushReports updates a list of reports to this logger.
	PushReports([]*api.ClimateReport)
	GetClimateTimeSeries(window string) api.ClimateTimeSeries
	GetClimateReport() *api.ZoneClimateReport
}

func NewClimateLogger

func NewClimateLogger(declaration *api.ClimateDeclaration) ClimateLogger

type ClosedOlympusServerError

type ClosedOlympusServerError struct{}

func (ClosedOlympusServerError) Error

func (e ClosedOlympusServerError) Error() string

type GenerateSecretsCommand

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

func (*GenerateSecretsCommand) Execute

func (c *GenerateSecretsCommand) Execute([]string) error

type GenerateVAPIDKeysCommand

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

func (*GenerateVAPIDKeysCommand) Execute

func (c *GenerateVAPIDKeysCommand) Execute([]string) error

type GracefulServer

type GracefulServer interface {
	Run() error
	Close() error
}

func NewGracefulServer

func NewGracefulServer(server *http.Server) GracefulServer

type GrpcSubscription

type GrpcSubscription[T any] struct {
	// contains filtered or unexported fields
}

func (GrpcSubscription[T]) NotifyAlarms

func (s GrpcSubscription[T]) NotifyAlarms(updates []*api.AlarmUpdate)

type NoClimateRunningError

type NoClimateRunningError string

func (NoClimateRunningError) Error

func (z NoClimateRunningError) Error() string

type NoTrackingRunningError

type NoTrackingRunningError string

func (NoTrackingRunningError) Error

func (z NoTrackingRunningError) Error() string

type NotificationFor

type NotificationFor struct {
	Subscription *webpush.Subscription
	Updates      []ZonedAlarmUpdate
}

type NotificationSender

type NotificationSender interface {
	Send(NotificationFor) error
}

func NewNotificationSender

func NewNotificationSender() (NotificationSender, error)

type NotificationSubscription

type NotificationSubscription struct {
	Push     *webpush.Subscription
	Settings api.NotificationSettings
}

type Notifier

type Notifier interface {
	Incoming() chan<- ZonedAlarmUpdate
	Outgoing() <-chan NotificationFor

	RegisterPushSubscription(*webpush.Subscription) error
	UpdatePushSubscription(*api.NotificationSettingsUpdate) error

	Loop()
}

func NewNotifier

func NewNotifier(batchPeriod time.Duration) Notifier

type Olympus

type Olympus struct {
	api.UnimplementedOlympusServer
	// contains filtered or unexported fields
}

func NewOlympus

func NewOlympus() (*Olympus, error)

func (*Olympus) Close

func (o *Olympus) Close() (err error)

func (*Olympus) GetAlarmReports

func (o *Olympus) GetAlarmReports(host, zone string) ([]api.AlarmReport, error)

func (*Olympus) GetClimateTimeSerie

func (o *Olympus) GetClimateTimeSerie(host, zone, window string) (api.ClimateTimeSeries, error)

GetClimateTimeSeries returns the time series for a zone within a given window. window should be one of "10m","1h","1d", "1w". It may return a ZoneNotFoundError.

func (*Olympus) GetServiceLogs

func (o *Olympus) GetServiceLogs() []api.ServiceLog

func (*Olympus) GetZoneReport

func (o *Olympus) GetZoneReport(host, zone string) (*api.ZoneReport, error)

func (*Olympus) GetZones

func (o *Olympus) GetZones() []api.ZoneReportSummary

func (*Olympus) NotifyAlarm

func (o *Olympus) NotifyAlarm(ctx context.Context, zone string, update *api.AlarmUpdate)

func (*Olympus) RegisterClimate

func (o *Olympus) RegisterClimate(ctx context.Context, declaration *api.ClimateDeclaration) (csub *GrpcSubscription[ClimateLogger], err error)

func (*Olympus) RegisterTracking

func (o *Olympus) RegisterTracking(ctx context.Context, declaration *api.TrackingDeclaration) (tsub *GrpcSubscription[TrackingLogger], err error)

func (*Olympus) UnregisterClimate

func (o *Olympus) UnregisterClimate(ctx context.Context, host, name string, graceful bool) (err error)

func (*Olympus) UnregisterTracker

func (o *Olympus) UnregisterTracker(ctx context.Context, host string, graceful bool) (err error)

func (*Olympus) ZoneIsRegistered

func (o *Olympus) ZoneIsRegistered(host, zone string) bool

type OlympusGRPCWrapper

type OlympusGRPCWrapper Olympus

func (*OlympusGRPCWrapper) Climate

func (o *OlympusGRPCWrapper) Climate(stream api.Olympus_ClimateServer) (err error)

func (*OlympusGRPCWrapper) Log

func (*OlympusGRPCWrapper) SendAlarm

func (o *OlympusGRPCWrapper) SendAlarm(ctx context.Context, update *api.AlarmUpdate) (*empty.Empty, error)

func (*OlympusGRPCWrapper) SubscriptionContext

func (o *OlympusGRPCWrapper) SubscriptionContext() context.Context

func (*OlympusGRPCWrapper) Tracking

func (o *OlympusGRPCWrapper) Tracking(stream api.Olympus_TrackingServer) (err error)

type Options

type Options struct {
}

type PersistentMap

type PersistentMap[T any] struct {
	Map map[string]T
	// contains filtered or unexported fields
}

func NewPersistentMap

func NewPersistentMap[T any](name string) *PersistentMap[T]

func (*PersistentMap[T]) Save

func (m *PersistentMap[T]) Save() error

func (*PersistentMap[T]) SaveKey

func (m *PersistentMap[T]) SaveKey(key string) (err error)

type RunCommand

type RunCommand struct {
	Verbose []bool `long:"verbose" short:"v" description:"enables verbose logging, set multiple time to increase the level"`

	Address      string   `long:"http-listen" short:"l" description:"Address for the HTTP server" default:":3000"`
	RPC          int      `long:"rpc-listen" short:"r" description:"Port for the RPC Service" default:"3001"`
	AllowCORS    []string `long:"allow-cors" description:"allow cors from domain"`
	OtelEndpoint string   `long:"otel-exporter" description:"Open Telemetry exporter endpoint" env:"OLYMPUS_OTEL_ENDPOINT"`
}

func (*RunCommand) Execute

func (c *RunCommand) Execute([]string) error

type ServiceLogger

type ServiceLogger interface {
	Log(ctx context.Context, identifier string, on, graceful bool)
	Logs() []api.ServiceLog
	OnServices() []string
	OffServices() []string
}

func NewServiceLogger

func NewServiceLogger() ServiceLogger

type TimedValues

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

TimedValues holds a list of time series with a common time vector. Values should be added or removed from the time series only using this struct interface. It is designed and optimized for live data logging, where data is added in real-time as it becomes available, but is robust to out-of-order insertion.

func (*TimedValues) DeepCopy

func (d *TimedValues) DeepCopy() TimedValues

DeepCopy performs a deep copy of the TimedValues.

func (*TimedValues) Downsample

func (d *TimedValues) Downsample(samples int, reference time.Time, unit time.Duration) [][]lttb.Point[float32]

Downsample downsamples the TimedValues to not exceed a given number of samples. The list of resulting time series may contains empty values. After downsampling, the time vector of the series will most likely not correspong to each other, as the LTTB algorithm retains time reference to keep the most representative shape of the original serie.

func (*TimedValues) FrequencyCutoff

func (d *TimedValues) FrequencyCutoff(minimumPeriod time.Duration) TimedValues

FrequencyCutOff creates a new TimedValues from the original one, which frequency does not exceed 1/minimumPeriod.

func (*TimedValues) Push

func (d *TimedValues) Push(other TimedValues, minimumPeriod time.Duration) bool

Push adds another TimedValues to the TimedValues. values may be dropped if it would make the series instantaneous frequency exceed the frequency 1/minimumPeriod. This method is optimized for two scenarios:

  • Adding a single value at the end of the TimedValues.
  • Adding a large chunk of values to the TimedValues.

It will return true if a value was actually added to the timed value.

func (*TimedValues) RollOutOfWindow

func (d *TimedValues) RollOutOfWindow(window time.Duration)

RollOutOfWindow prunes values which are older than window from the last time in the series.

func (*TimedValues) TimeVector

func (d *TimedValues) TimeVector(reference time.Time, unit time.Duration) []float32

TimeVector produces a time vector for a series, from a reference point. I.e from the first registered time or the last registered time.

type TrackingLogger

type TrackingLogger interface {
	TrackingInfo() *api.TrackingInfo
	PushDiskStatus(*api.DiskStatus)
}

func NewTrackingLogger

func NewTrackingLogger(ctx context.Context, declaration *api.TrackingDeclaration) TrackingLogger

type UnexpectedStreamServerError

type UnexpectedStreamServerError struct {
	Got, Expected string
}

func (UnexpectedStreamServerError) Error

type UpdateFilter

type UpdateFilter func(outgoing chan<- ZonedAlarmUpdate, incoming <-chan ZonedAlarmUpdate)

func FilterAlarmUpdates

func FilterAlarmUpdates(minimumOn time.Duration) UpdateFilter

type VersionCommand

type VersionCommand struct{}

func (*VersionCommand) Execute

func (c *VersionCommand) Execute([]string) error

type WebPushAction

type WebPushAction struct {
	Action string `json:"action,omitempty"`
	Title  string `json:"title,omitempty"`
}

type WebPushData

type WebPushData struct {
	OnActionClick map[string]WebPushTargetAction `json:"onActionClick,omitempty"`
}

type WebPushNotification

type WebPushNotification struct {
	Title   string          `json:"title,omitempty"` // Mandatory
	Body    string          `json:"body,omitempty"`  // Mandatory
	Actions []WebPushAction `json:"actions,omitempty"`
	Data    WebPushData     `json:"data,omitempty"`
	Icon    string          `json:"icon,omitempty"`    // Yes we would like something : https://web.dev/push-notifications-display-a-notification/#icon
	Image   string          `json:"image,omitempty"`   // Preferably not see https://web.dev/push-notifications-display-a-notification/#image
	Badge   string          `json:"badge,omitempty"`   // Yes we would like something : https://web.dev/push-notifications-display-a-notification/#badge
	Vibrate []int           `json:"vibrate,omitempty"` // Seems uneffective
	Sound   string          `json:"sound.omitempty"`   // Doesn't work
}

func NewMultiWebPushNotification

func NewMultiWebPushNotification(updates []ZonedAlarmUpdate) WebPushNotification

func NewSingleWebPushNotification

func NewSingleWebPushNotification(update ZonedAlarmUpdate) WebPushNotification

func NewWebPushNotification

func NewWebPushNotification(updates []ZonedAlarmUpdate) (WebPushNotification, error)

type WebPushTargetAction

type WebPushTargetAction struct {
	Operation string `json:"operation,omitempty"`
	URL       string `json:"url,omitempty"`
}

type ZoneNotFoundError

type ZoneNotFoundError string

func (ZoneNotFoundError) Error

func (z ZoneNotFoundError) Error() string

type ZonedAlarmUpdate

type ZonedAlarmUpdate struct {
	Zone   string
	Update *api.AlarmUpdate
}

func (ZonedAlarmUpdate) ID

func (u ZonedAlarmUpdate) ID() string

Jump to

Keyboard shortcuts

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