cynic

package
v0.0.0-...-d6cef19 Latest Latest
Warning

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

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

Documentation

Overview

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling

Copyright 2018-2021 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling. Library interface goes here.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn) Copyright 2019 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling

Copyright 2018-2021 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling

Copyright 2018-2021 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cynic monitors you from the ceiling.

Copyright 2018 Simon Symeonidis (psyomn)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// StopEvent is the signal to stop the running querying event.
	StopEvent = iota

	// AddEvent adds a event to a running cynic instance.
	AddEvent

	// DeleteEvent removes a event from a running cynic instance.
	DeleteEvent
)
View Source
const (
	// StatusPort is the default port the status http server will
	// respond on.
	StatusPort = "9999"

	// DefaultStatusEndpoint is where the default status json can
	// be retrieved from.
	DefaultStatusEndpoint = "/status/"
)
View Source
const VERSION string = "2.4.1"

VERSION is the version of the current package. Update with every new tag/release.

Variables

View Source
var ErrStatusValueNotFound = fmt.Errorf("could not find required value")

Functions

func Start

func Start(session Session)

Start starts a cynic instance, with any provided hooks.

Types

type AlertFunc

type AlertFunc = func([]AlertMessage)

AlertFunc defines the hook signature for alert messages.

type AlertMessage

type AlertMessage struct {
	Response      interface{} `json:"response_text"`
	Now           string      `json:"now"`
	CynicHostname string      `json:"cynic_hostname"`
}

AlertMessage defines a simple alert structure that can be used by users of the library, and decide how to show information about the alerts.

type Alerter

type Alerter struct {
	Ch chan AlertMessage
	// contains filtered or unexported fields
}

Alerter is an entity that ticks, and if there are alert messages, will fire up behavior.

func AlerterNew

func AlerterNew(waitTime int, alerter AlertFunc) Alerter

AlerterNew creates a new alerter.

func (*Alerter) Start

func (s *Alerter) Start()

Start begins the alerter.

func (*Alerter) Stop

func (s *Alerter) Stop()

Stop the alerter.

type Event

type Event struct {
	Label string
	// contains filtered or unexported fields
}

Event is some event that should be executed in a specified amount of time. There are no real time guarantees. - A event is an action - A event can have many:

  • hooks (that can act as contracts)

- A event may be bound to a data repository/cache.

func EventNew

func EventNew(secs int) Event

EventNew creates a new event that is primarily used for pure execution.

func (*Event) AddHook

func (s *Event) AddHook(fn HookSignature)

AddHook appends a hook to the event.

func (*Event) Delete

func (s *Event) Delete()

Delete marks event for deletion.

func (*Event) Execute

func (s *Event) Execute()

Execute the event.

func (*Event) GetAbsExpiry

func (s *Event) GetAbsExpiry() int64

GetAbsExpiry gets the timestamp.

func (*Event) GetOffset

func (s *Event) GetOffset() int

GetOffset returns the offset time of the event.

func (*Event) GetSecs

func (s *Event) GetSecs() int

GetSecs returns the number of seconds.

func (*Event) ID

func (s *Event) ID() uint64

ID returns the unique identifier of the event.

func (*Event) Immediate

func (s *Event) Immediate(val bool)

Immediate will make the event run immediately.

func (*Event) IsDeleted

func (s *Event) IsDeleted() bool

IsDeleted returns if event is marked for deletion.

func (*Event) IsImmediate

func (s *Event) IsImmediate() bool

IsImmediate returns true if event is immediate.

func (*Event) IsRepeating

func (s *Event) IsRepeating() bool

IsRepeating says whether a event repeats or not.

func (*Event) NumHooks

func (s *Event) NumHooks() int

NumHooks counts the hooks.

func (*Event) Repeat

func (s *Event) Repeat(rep bool)

Repeat makes the event repeatable.

func (*Event) SetAbsExpiry

func (s *Event) SetAbsExpiry(ts int64)

SetAbsExpiry sets the timestamp that the event is supposed to expire on.

func (*Event) SetDataRepo

func (s *Event) SetDataRepo(repo *StatusCache)

SetDataRepo sets where the data processed should be stored in.

func (*Event) SetExtra

func (s *Event) SetExtra(extra interface{})

SetExtra state you may want passed to hooks.

func (*Event) SetOffset

func (s *Event) SetOffset(offset int)

SetOffset sets the time before the event starts ticking.

func (*Event) SetSecs

func (s *Event) SetSecs(secs int)

SetSecs sets the seconds of the event to fire on.

func (*Event) String

func (s *Event) String() string

func (*Event) UniqStr

func (s *Event) UniqStr() string

UniqStr combines the label and id in order to have a unique, human readable label.

type EventBuilder

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

EventBuilder is a helper to set properties to a lot of events. For example, if you have 10 events you want to run within 100 seconds, you can use this builder in oder to disperse everything over 10 seconds.

func EventBuilderNew

func EventBuilderNew(events []Event) EventBuilder

EventBuilderNew creates a new events builder. Simple configurations. If you want something more complex, you should do it on your own.

func (*EventBuilder) Build

func (s *EventBuilder) Build() (Session, bool)

Build takes all the things you gave the builder, puts them together, and gives you a session object to do whatever you will with it.

func (*EventBuilder) DistributeEvents

func (s *EventBuilder) DistributeEvents(maxTime int)

DistributeEvents over a max time interval.

func (*EventBuilder) Repeatable

func (s *EventBuilder) Repeatable()

Repeatable will mark all events as repeatable.

type EventQueue

type EventQueue []*Event

EventQueue is a priority queue that sorts events that are to happen via their absolute expiry.

func (EventQueue) Len

func (pq EventQueue) Len() int

func (EventQueue) Less

func (pq EventQueue) Less(i, j int) bool

func (*EventQueue) PeekID

func (pq *EventQueue) PeekID() (uint64, bool)

PeekID returns the id of the event at root.

func (*EventQueue) PeekTimestamp

func (pq *EventQueue) PeekTimestamp() (int64, bool)

PeekTimestamp gives the timestamp at the root of the heap.

func (*EventQueue) Pop

func (pq *EventQueue) Pop() interface{}

Pop retrieves the soonest event.

func (*EventQueue) Push

func (pq *EventQueue) Push(x interface{})

Push inserts an event into the priority queue.

func (EventQueue) Swap

func (pq EventQueue) Swap(i, j int)

type HookParameters

type HookParameters struct {
	// Planner is access to the planner that the hook executes
	// on. The user for example, should be able to add more events
	// through a hook.
	Planner *Planner

	// Status exposes the status repo. It acts as a repository for
	// hooks to store information after execution.
	Status *StatusCache

	// Extra is meant to be used by the user for any extra state
	// that needs to be passed to the hooks.
	Extra interface{}
}

HookParameters is any state that should be passed to the hook.

type HookSignature

type HookSignature = func(*HookParameters) (bool, interface{})

HookSignature specifies what the event hooks should look like.

type Planner

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

Planner is a structure that manages events inserted with expiration timestamps. The underlying data structures are magic, and you shouldn't care about them, unless you're opening up the hatch and stuff.

func PlannerNew

func PlannerNew() *Planner

PlannerNew creates a new, empty, timing wheel.

func (*Planner) Add

func (s *Planner) Add(event *Event)

Add adds an event to the planner.

func (*Planner) Delete

func (s *Planner) Delete(event *Event) bool

Delete marks a Event to be deleted. Returns true if event found and marked for deletion, false if not.

func (*Planner) GetAlerter

func (s *Planner) GetAlerter() *Alerter

GetAlerter gets the assigned alerter of planner.

func (*Planner) Len

func (s *Planner) Len() int

Len returns the amount of events the planner has stored for later execution.

func (*Planner) Run

func (s *Planner) Run()

Run runs the wheel, with a 1s tick.

func (*Planner) SetAlerter

func (s *Planner) SetAlerter(alerter *Alerter)

SetAlerter sets the alerter.

func (*Planner) String

func (s *Planner) String() string

func (*Planner) Tick

func (s *Planner) Tick()

Tick moves the cursor of the timing wheel, by one second.

type Session

type Session struct {
	Events         []Event
	StatusCache    *StatusCache
	Alerter        *Alerter
	SnapshotConfig *SnapshotConfig
}

Session is the configuration a cynic instance requires to start running and working.

type SnapshotConfig

type SnapshotConfig struct {
	Interval  time.Duration
	DumpEvery time.Duration
	Path      string
}

SnapshotConfig is the configuration for the snapshots to be taken

type SnapshotStore

type SnapshotStore struct {
	Magic     uint64
	Version   uint8 // storage version
	Snapshots []*snapshot
}

SnapshotStore is storage of states of the map at different times

func (*SnapshotStore) String

func (s *SnapshotStore) String() string

String stringifies the contents of SnapshotStore

type StatusCache

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

StatusCache stores any sort of information that is possibly retrieved or calculated by events. A server can be started to retrieve information in the map in json format.

func StatusServerNew

func StatusServerNew(host, port, root string) StatusCache

StatusServerNew creates a new status server for cynic.

func (*StatusCache) Delete

func (s *StatusCache) Delete(key string)

Delete removes an entry from the sync map.

func (*StatusCache) Get

func (s *StatusCache) Get(key string) (interface{}, error)

Get gets the value inside the contract results.

func (*StatusCache) GetPort

func (s *StatusCache) GetPort() int

GetPort this will return the port where the server was started. This is useful if you assign port 0 when initializing.

func (*StatusCache) NumEntries

func (s *StatusCache) NumEntries() (count int)

NumEntries returns the number of entries in the map.

func (*StatusCache) Start

func (s *StatusCache) Start()

Start starts all services associated with status caches. This includes the web interface if enabled, and the dumping of statuses in files.

func (*StatusCache) Stop

func (s *StatusCache) Stop()

Stop gracefully shuts down the server.

func (*StatusCache) Update

func (s *StatusCache) Update(key string, value interface{})

Update updates the information about all the contracts that are running on different endpoints.

func (*StatusCache) WithSnapshots

func (s *StatusCache) WithSnapshots(config *SnapshotConfig)

WithSnapshots will make the cache dump snapshots of the data with given intervals when the service starts.

Jump to

Keyboard shortcuts

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