Documentation ¶
Index ¶
- Constants
- Variables
- func BenchSystem(name string) (*System, *Context)
- func ExampleSystem(name string) (*System, *Context)
- func GetRuntimes(ctx *Context) (map[string]interface{}, error)
- func GetStorage(ctx *Context, storageType string, storageConfig interface{}) (Storage, error)
- func ParseLocationTTL(ttl string) (time.Duration, error)
- func ServiceAvailable(ctx *Context, url string, timeout time.Duration) bool
- func SystemForTest(name string) (*System, *Context)
- type CachedLocation
- type CachedLocations
- type GroupControls
- type LocToGroup
- type System
- func (sys *System) AddFact(ctx *Context, location string, id string, fact string) (string, error)
- func (sys *System) AddFactJS(ctx *Context, location string, id string, fact string) map[string]interface{}
- func (sys *System) AddRule(ctx *Context, location string, id string, rule string) (string, error)
- func (sys *System) ClearLocation(ctx *Context, location string) error
- func (sys *System) ClearLocationStats(ctx *Context, location string) error
- func (sys *System) ClearStats(ctx *Context) error
- func (sys *System) Close(ctx *Context) error
- func (sys *System) CloseLocation(ctx *Context, loc string) error
- func (s *System) Control() *SystemControl
- func (sys *System) CreateLocation(ctx *Context, location string) (bool, error)
- func (sys *System) DeleteLocation(ctx *Context, location string) error
- func (sys *System) EnableRule(ctx *Context, location string, id string, enable bool) error
- func (sys *System) GetCachedLocations(ctx *Context) []string
- func (sys *System) GetFact(ctx *Context, location string, id string) (js string, err error)
- func (sys *System) GetLastUpdatedMem(ctx *Context, location string) (string, error)
- func (sys *System) GetLocation(ctx *Context, name string) (*Location, error)
- func (sys *System) GetLocationStats(ctx *Context, location string) (*ServiceStats, error)
- func (sys *System) GetParents(ctx *Context, location string) ([]string, error)
- func (sys *System) GetProfileBlock(ctx *Context) (string, error)
- func (sys *System) GetProfileCPU(ctx *Context, stop bool) (prof []byte, err error)
- func (sys *System) GetProfileMem(ctx *Context) (string, error)
- func (sys *System) GetRule(ctx *Context, location string, id string) (js string, err error)
- func (sys *System) GetSize(ctx *Context, location string) (int, error)
- func (sys *System) GetStats(ctx *Context) (*ServiceStats, error)
- func (sys *System) ListRules(ctx *Context, location string, includeInherited bool) ([]string, error)
- func (s *System) LocControl(ctx *Context, loc string) *Control
- func (sys *System) LogLoop(level LogLevel, ctx *Context, scope string, interval time.Duration, ...)
- func (sys *System) OpenLocation(ctx *Context, name string, checkExists bool) (*Location, error)
- func (sys *System) PeekStorage(ctx *Context) (Storage, error)
- func (sys *System) ProcessEvent(ctx *Context, location string, event string) (*FindRules, error)
- func (sys *System) Query(ctx *Context, location string, query string) (*QueryResult, error)
- func (sys *System) RemFact(ctx *Context, location string, id string) (string, error)
- func (sys *System) RemRule(ctx *Context, location string, id string) (string, error)
- func (sys *System) RetryEventWork(ctx *Context, location string, work *FindRules) error
- func (sys *System) RuleEnabled(ctx *Context, location string, id string) (bool, error)
- func (sys *System) RunJavascript(ctx *Context, location string, code string, libraries []string, bs *Bindings, ...) (interface{}, error)
- func (sys *System) RuntimeLogLoop(level LogLevel, ctx *Context, scope string, interval time.Duration, ...)
- func (sys *System) SearchFacts(ctx *Context, location string, pattern string, includeInherited bool) (*SearchResults, error)
- func (sys *System) SearchRules(ctx *Context, location string, event string, includeInherited bool) (map[string]string, error)
- func (s *System) SetControl(control SystemControl)
- func (sys *System) SetParents(ctx *Context, location string, parents []string) (string, error)
- func (sys *System) StartProfileCPU(ctx *Context) error
- type SystemConfig
- type SystemControl
Constants ¶
const Forever = -1 * time.Second
Forever is a location TTL that is infinite.
const Never = 0 * time.Second
Never is a location TTL that is effectively zero.
const ProfCPUFileName = "pprof_cpu"
Variables ¶
var EndOfTime = time.Unix(1<<62, 0)
EndOfTime is not actually the end of time, but it is a long time from now.
If you are wondering, this value is in the year 146138514283.
Functions ¶
func BenchSystem ¶
BenchSystem makes a System that might be appropriate for benchmarks.
Verbosity is 'NOTHING'. Based on 'ExampleSystem'.
func ExampleSystem ¶
func GetRuntimes ¶
GetRuntimes get a list of current the System's runtime data.
func GetStorage ¶
GetStorage attempts to create a Storage.
See '../storage/' for some implementations.
Possible storage types:
"none": This Storage doesn't remember anything. "mem": In-memory-only storage. Never writes to disk. "bolt": BoltDB Storage. 'storageConfig' should be a filename. "dynamodb": DynamoDB Storage. 'storageConfig' should be REGION:TABLE_NAME:CONSISTENT_READS, where CONSISTENT_READS is either 'true' or 'false'.
func ParseLocationTTL ¶
ParseLocationTTL tries to parse a duration.
"never" parses to 'Never' and "forever" parses to 'Forever'. Otherwise you should provide a duration in 'time.Duration' syntax.
func ServiceAvailable ¶
ServiceAvailable checks to see if what's at 'url' is accessible and at least semi-functional.
The URL should include the full path (ideally to a health check).
func SystemForTest ¶
Types ¶
type CachedLocation ¶
CachedLocation mostly provides a mutex associated with the target location.
That mutex allows use to block only on this specific location when opening it. That's way better than having a system-wide lock held when opening each location because opening a location could take a long time.
type CachedLocations ¶
CachedLocations is just that: a location cache keyed by name.
We have this struct in part to have a mutex dedicated to this state.
func NewCachedLocations ¶
func NewCachedLocations(ctx *Context) *CachedLocations
func (*CachedLocations) Count ¶
func (cl *CachedLocations) Count() int
func (*CachedLocations) Open ¶
func (cls *CachedLocations) Open(ctx *Context, sys *System, name string, check bool) (*Location, error)
Open gets a location from the cache after first creating it.
This function the top-level location cache API, and it uses 'CachedLocations.Get()' to do the real work.
TTL can be 'Never', 'Forever', or anything in between.
type GroupControls ¶
type GroupControls map[string]*Control
GroupControls maps a group to a 'core.Control'.
Used to be called 'LocControls'
type System ¶
type System struct { sync.Mutex *CachedLocations ProfCPUFile *os.File // contains filtered or unexported fields }
System is a location container.
A System is responsible for loading locations and directing API requests to then.
func NewSystem ¶
func NewSystem(ctx *Context, conf SystemConfig, cont SystemControl, cron cron.Cronner) (*System, error)
NewSystem does about what you'd think.
func SimpleSystem ¶
func SimpleSystem(ctx *Context) *System
SimpleSystem ia a basic system with 'FOREVER' TTL and 'DefaultVerbosity' Verbosity.
func (*System) ClearLocation ¶
ClearLocation should (!) clear all the state for the given location.
func (*System) ClearLocationStats ¶
ClearLocationStats clears stats for the given location.
func (*System) ClearStats ¶
ClearStats clear the System's stats.
func (*System) Close ¶
Close should shut down things.
Currently this method just calls 'storage.Close()', which itself might not really do anything (depending on the Storage, of course).
func (*System) CloseLocation ¶
CloseLocation currently does nothing.
func (*System) Control ¶
func (s *System) Control() *SystemControl
Control atomically gets the System's controls.
func (*System) CreateLocation ¶
CreateLocation exists solely to mark a location as created.
func (*System) DeleteLocation ¶
DeleteLocation should (!) clear all the state for the given location.
func (*System) EnableRule ¶
EnableRule enables or disables a rule.
func (*System) GetCachedLocations ¶
GetCachedLocations gets the set of cached locations.
Gets the System's mutex.
func (*System) GetLastUpdatedMem ¶
GetLastUpdatedMem reports what this system thinks the location's last updated timestamp is.
Does not query DynamoDB to find out. Just returns what is currently known in memory.
func (*System) GetLocation ¶
GetLocation implements core.LocationProvider.
Just calls 'findLocation(,,false)'.
func (*System) GetLocationStats ¶
GetLocationStats returns ServiceStats for the given location.
func (*System) GetParents ¶
GetParents gets the location's parents (if any).
func (*System) GetProfileBlock ¶
GetProfileBlock returns pprof block.
func (*System) GetProfileCPU ¶
GetProfileCPU gets/stops pprof cpu.
func (*System) GetProfileMem ¶
GetProfileMem returns pprof mem.
func (*System) GetSize ¶
GetSize returns the number of facts (including rules) stored in the given location.
func (*System) ListRules ¶
func (sys *System) ListRules(ctx *Context, location string, includeInherited bool) ([]string, error)
ListRules returns all rules (JSON) stored in the given location.
func (*System) LocControl ¶
LocControl gets a location controls.
A location's controls originate with the System's controls, which have a 'DefaultLocControl' that's used if 'LocToGroup' together with 'GroupControls' don't provide the required controls.
func (*System) LogLoop ¶
func (sys *System) LogLoop(level LogLevel, ctx *Context, scope string, interval time.Duration, iterations int)
LogLoop starts a loop that logs sys.stats at the given interval.
If iterations is negative, the loop is endless. Otherwise the loop terminates after the specified number of iteratins.
func (*System) OpenLocation ¶
OpenLocation wraps 'newLocation' to check for existence (optionally).
func (*System) PeekStorage ¶
PeekStorage is an unholy API to expose underlying storage.
Used by 'service' for testing purposes.
func (*System) ProcessEvent ¶
func (*System) RemFact ¶
RemFact remove a fact from the given location. Returns the ID of the removed fact.
func (*System) RemRule ¶
RemRule removes a rule from the given location. Returns the ID of the removed rule.
func (*System) RetryEventWork ¶
func (*System) RuleEnabled ¶
EnableRule enables or disables a rule.
func (*System) RunJavascript ¶
func (sys *System) RunJavascript(ctx *Context, location string, code string, libraries []string, bs *Bindings, props map[string]interface{}) (interface{}, error)
RunJavascript allows location-specific Javascript testing.
func (*System) RuntimeLogLoop ¶
func (sys *System) RuntimeLogLoop(level LogLevel, ctx *Context, scope string, interval time.Duration, iterations int)
RuntimeLogLoop runs a loop that logs Go runtime stats.
The "scope" parameter is opaque. Might be useful in downstream log/metric processing.
func (*System) SearchFacts ¶
func (sys *System) SearchFacts(ctx *Context, location string, pattern string, includeInherited bool) (*SearchResults, error)
SearchFacts finds facts that match the given pattern (JSON).
func (*System) SearchRules ¶
func (sys *System) SearchRules(ctx *Context, location string, event string, includeInherited bool) (map[string]string, error)
SearchRules finds rules with 'when' patterns that match the given event (JSON).
func (*System) SetControl ¶
func (s *System) SetControl(control SystemControl)
SetControl atomically gets the System's controls.
func (*System) SetParents ¶
SetParents sets the location's parents.
Returns the id of the property (if any).
func (*System) StartProfileCPU ¶
StartProfileCPU starts pprof cpu.
type SystemConfig ¶
type SystemConfig struct { // Type of storage: "dynamodb", "cassandra", "bolt", "memory", or "none" Storage string `json:"storage"` // How to configure storage. Examples: // // For "cassandra", the nodes: []interface{}{"localhost:9042"} // Those ports should talk CQL (for better or worse). // // For "bolt", the filename: "test" // StorageConfig interface{} // LinearState switches between IndexedState and LinearState. // // UnindexedState means LinearState. Maybe I should just say // that. UnindexedState bool // CheckExistence requires that a location is explicitly // created before it can be used. CheckExistence bool }
SystemConfig are read-only, boot-time settings for a System.
Once specified, these settings cannot be changed.
func ExampleConfig ¶
func ExampleConfig() *SystemConfig
ExampleConfig just generates a simple config for an in-memory-only System.
type SystemControl ¶
type SystemControl struct { // Turn on some timing in various places. Timing bool // The maximum number of locations that this System will serve. MaxLocations int // Whether to skip ssh/https insecure keys verification, should only be set true for testing InsecureSkipVerify bool // LocationTTL is the TTL for cached locations. // // Often either Forever or Never. LocationTTL time.Duration // LocToGroup maps a location to a group. LocToGroup `json:"-"` // GroupControls maps a group to a location control. GroupControls // DefaultLocationControl is exactly what you think. // // If LocToGroup and GroupControls don't find a control, we // use 'DefaultLocationControl'. DefaultLocControl *Control // CachedPending will use the location cache to keep pending // locations around. CachePending bool }
SystemControl represents ephemeral control options.
These settings are process-specific and not stored. Note that all of these values are simple (not maps or arrays or structs). You can change them (hopefully atomically) at will.
Set and get these controls with 'System.SetControl()' and 'System.Control()'.
Also see core.Control.
func ExampleSystemControl ¶
func ExampleSystemControl() *SystemControl
ExampleSystemControl uses default SystemControl fields, except for Timing, which is turned on.
func OverlayControl ¶
func OverlayControl(js []byte, control SystemControl) (*SystemControl, error)
OverlayControl parses the given JSON as a SystemControl, which is then added to the given control.