Documentation ¶
Overview ¶
Package store contains the Store interface and implementations
Index ¶
- Variables
- func InitDB(storageFilePath string) (*bbolt.DB, error)
- func MergeUpdates(into, from *Updates) bool
- func Seed(ctx context.Context, store Store, logger *zap.Logger) error
- type AgentUpdater
- type DependencyError
- type DependentResources
- type Event
- type EventType
- type Events
- func (e Events[T]) ByType(eventType EventType) []Event[T]
- func (e Events[T]) CanSafelyMerge(other Events[T]) bool
- func (e Events[T]) Clone() Events[T]
- func (e Events[T]) Contains(uniqueKey string, eventType EventType) bool
- func (e Events[T]) Empty() bool
- func (e Events[T]) Include(item T, eventType EventType)
- func (e Events[T]) Keys() []string
- func (e Events[T]) Merge(other Events[T])
- func (e Events[T]) Updates() []Event[T]
- type Options
- type QueryOption
- type Store
- type Updates
- func (u *Updates) AddAffectedConfigurations(configurations []*model.Configuration)
- func (u *Updates) AddAffectedDestinations(destinations []*model.Destination)
- func (u *Updates) AddAffectedProcessors(processors []*model.Processor)
- func (u *Updates) AddAffectedSources(sources []*model.Source)
- func (u *Updates) AffectsConfiguration(configuration *model.Configuration) bool
- func (u *Updates) AffectsDestination(destination *model.Destination) bool
- func (u *Updates) AffectsProcessor(processor *model.Processor) bool
- func (u *Updates) AffectsSource(source *model.Source) bool
- func (u *Updates) CouldAffectConfigurations() bool
- func (u *Updates) CouldAffectDestinations() bool
- func (u *Updates) CouldAffectProcessors() bool
- func (u *Updates) CouldAffectSources() bool
- func (u *Updates) Empty() bool
- func (u *Updates) HasDestinationEvents() bool
- func (u *Updates) HasDestinationTypeEvents() bool
- func (u *Updates) HasProcessorEvents() bool
- func (u *Updates) HasProcessorTypeEvents() bool
- func (u *Updates) HasSourceEvents() bool
- func (u *Updates) HasSourceTypeEvents() bool
- func (u *Updates) IncludeAgent(agent *model.Agent, eventType EventType)
- func (u *Updates) IncludeAgentVersion(agentVersion *model.AgentVersion, eventType EventType)
- func (u *Updates) IncludeConfiguration(configuration *model.Configuration, eventType EventType)
- func (u *Updates) IncludeDestination(destination *model.Destination, eventType EventType)
- func (u *Updates) IncludeDestinationType(destinationType *model.DestinationType, eventType EventType)
- func (u *Updates) IncludeProcessor(processor *model.Processor, eventType EventType)
- func (u *Updates) IncludeProcessorType(processorType *model.ProcessorType, eventType EventType)
- func (u *Updates) IncludeResource(r model.Resource, eventType EventType)
- func (u *Updates) IncludeSource(source *model.Source, eventType EventType)
- func (u *Updates) IncludeSourceType(sourceType *model.SourceType, eventType EventType)
- func (u *Updates) Size() int
- type UpdatesEventBus
Constants ¶
This section is empty.
Variables ¶
var ErrResourceInUse = errors.New("resource in use")
ErrResourceInUse is used in delete functions to indicate the delete could not be performed because the Resource is a dependency of another. i.e. the Source that is being deleted is being referenced in a Configuration.
var ErrResourceMissing = errors.New("resource not found")
ErrResourceMissing is used in delete functions to indicate the delete could not be performed because no such resource exists
Functions ¶
func InitDB ¶
InitDB takes in the full path to a storage file and returns an opened bbolt database. It will return an error if the file cannot be opened.
func MergeUpdates ¶ added in v1.9.0
MergeUpdates merges the updates from the given Updates into the current Updates.
Types ¶
type AgentUpdater ¶
AgentUpdater is given the current Agent model (possibly empty except for ID) and should update the Agent directly. We take this approach so that appropriate locking and/or transactions can be used for the operation as needed by the Store implementation.
type DependencyError ¶
type DependencyError struct {
// contains filtered or unexported fields
}
DependencyError is returned when trying to delete a resource that is being referenced by other resources.
func (*DependencyError) Error ¶
func (de *DependencyError) Error() string
type DependentResources ¶
type DependentResources []dependency
DependentResources is the return type of store.dependentResources and used to construct DependencyError. It has help methods empty(), message(), and add().
func FindDependentResources ¶
func FindDependentResources(ctx context.Context, s Store, r model.Resource) (DependentResources, error)
FindDependentResources finds the dependent resources using the ConfigurationIndex provided by the Store.
type Event ¶
type Event[T model.HasUniqueKey] struct { Type EventType `json:"type"` Item T `json:"item"` }
Event represents an insert, update, or remove of something stored in Store.
type EventType ¶
type EventType uint8
EventType is the type of event
const ( EventTypeInsert EventType = 1 EventTypeUpdate EventType = 2 EventTypeRemove EventType = 3 EventTypeLabel EventType = 4 )
Insert, Update, Remove, and Label are the possible changes to a resource. Remove can indicate that the resource has been deleted or that it no longer matches a filtered list of resources being observed.
Label is currently used to indicate that Agent labels have changed but there may also be other updates so it can be considered a subset of EventTypeUpdate where every EventTypeLabel is also an EventTypeUpdate.
type Events ¶
type Events[T model.HasUniqueKey] map[string]Event[T]
Events is a map of ID to Event
func NewEvents ¶
func NewEvents[T model.HasUniqueKey]() Events[T]
NewEvents returns a new empty set of events
func NewEventsWithItem ¶
func NewEventsWithItem[T model.HasUniqueKey](item T, eventType EventType) Events[T]
NewEventsWithItem returns a new set of events with an initial item and eventType
func (Events[T]) CanSafelyMerge ¶ added in v0.5.2
CanSafelyMerge returns true if the other events can be merged into this one. Currently we only merge events with different keys.
func (Events[T]) Merge ¶ added in v0.5.2
Merge will add events from the other events. Note that this will currently overwrite any existing events. Use CanSafelyMerge first to determine if a Merge can be done without overwriting and losing events.
func (Events[T]) Updates ¶ added in v0.5.2
Updates returns all events of type EventTypeUpdate
type Options ¶ added in v0.5.2
type Options struct { // SessionsSecret is used to encode sessions SessionsSecret string // MaxEventsToMerge is the maximum number of update events (inserts, updates, deletes, etc) to merge into a single // event. MaxEventsToMerge int }
Options are options that are common to all store implementations
type QueryOption ¶
type QueryOption func(*queryOptions)
QueryOption is an option used in Store queries
func WithLimit ¶
func WithLimit(limit int) QueryOption
WithLimit sets the maximum number of results to return. For paging, if the pages have 10 items per page, set the limit to 10.
func WithOffset ¶
func WithOffset(offset int) QueryOption
WithOffset sets the offset for the results to return. For paging, if the pages have 10 items per page and this is the 3rd page, set the offset to 20.
func WithQuery ¶
func WithQuery(query *search.Query) QueryOption
WithQuery adds a search query string to the query options
func WithSelector ¶
func WithSelector(selector model.Selector) QueryOption
WithSelector adds a selector to the query options
func WithSort ¶
func WithSort(field string) QueryOption
WithSort sets the sort order for the request. The sort value is the name of the field, sorted ascending. To sort descending, prefix the field with a minus sign (-). Some Stores only allow sorting by certain fields. Sort values not supported will be ignored.
type Store ¶
type Store interface { Clear() Agent(ctx context.Context, id string) (*model.Agent, error) Agents(ctx context.Context, options ...QueryOption) ([]*model.Agent, error) AgentsCount(context.Context, ...QueryOption) (int, error) // UpsertAgent adds a new Agent to the Store or updates an existing one UpsertAgent(ctx context.Context, agentID string, updater AgentUpdater) (*model.Agent, error) UpsertAgents(ctx context.Context, agentIDs []string, updater AgentUpdater) ([]*model.Agent, error) DeleteAgents(ctx context.Context, agentIDs []string) ([]*model.Agent, error) AgentVersion(ctx context.Context, name string) (*model.AgentVersion, error) AgentVersions(ctx context.Context) ([]*model.AgentVersion, error) DeleteAgentVersion(ctx context.Context, name string) (*model.AgentVersion, error) Configurations(ctx context.Context, options ...QueryOption) ([]*model.Configuration, error) Configuration(ctx context.Context, name string) (*model.Configuration, error) DeleteConfiguration(ctx context.Context, name string) (*model.Configuration, error) Source(ctx context.Context, name string) (*model.Source, error) Sources(ctx context.Context) ([]*model.Source, error) DeleteSource(ctx context.Context, name string) (*model.Source, error) SourceType(ctx context.Context, name string) (*model.SourceType, error) SourceTypes(ctx context.Context) ([]*model.SourceType, error) DeleteSourceType(ctx context.Context, name string) (*model.SourceType, error) Processor(ctx context.Context, name string) (*model.Processor, error) Processors(ctx context.Context) ([]*model.Processor, error) DeleteProcessor(ctx context.Context, name string) (*model.Processor, error) ProcessorType(ctx context.Context, name string) (*model.ProcessorType, error) ProcessorTypes(ctx context.Context) ([]*model.ProcessorType, error) DeleteProcessorType(ctx context.Context, name string) (*model.ProcessorType, error) Destination(ctx context.Context, name string) (*model.Destination, error) Destinations(ctx context.Context) ([]*model.Destination, error) DeleteDestination(ctx context.Context, name string) (*model.Destination, error) DestinationType(ctx context.Context, name string) (*model.DestinationType, error) DestinationTypes(ctx context.Context) ([]*model.DestinationType, error) DeleteDestinationType(ctx context.Context, name string) (*model.DestinationType, error) ApplyResources(ctx context.Context, resources []model.Resource) ([]model.ResourceStatus, error) // Batch delete of a slice of resources, returns the successfully deleted resources or an error. DeleteResources(ctx context.Context, resources []model.Resource) ([]model.ResourceStatus, error) // AgentConfiguration returns the configuration that should be applied to an agent. AgentConfiguration(ctx context.Context, agentID string) (*model.Configuration, error) // AgentsIDsMatchingConfiguration returns the list of agent IDs that are using the specified configuration AgentsIDsMatchingConfiguration(ctx context.Context, conf *model.Configuration) ([]string, error) // CleanupDisconnectedAgents removes agents that have disconnected before the specified time CleanupDisconnectedAgents(ctx context.Context, since time.Time) error // Updates will receive pipelines and configurations that have been updated or deleted, either because the // configuration changed or a component in them was updated. Agents inserted/updated from UpsertAgent and agents // removed from CleanupDisconnectedAgents are also sent with Updates. Updates() eventbus.Source[*Updates] // AgentIndex provides access to the search AgentIndex implementation managed by the Store AgentIndex(ctx context.Context) search.Index // ConfigurationIndex provides access to the search Index for Configurations ConfigurationIndex(ctx context.Context) search.Index // UserSessions must implement the gorilla sessions.Store interface UserSessions() sessions.Store // Measurements stores stats for agents and configurations Measurements() stats.Measurements }
Store handles interacting with a storage backend.
func NewBoltStore ¶
NewBoltStore returns a new store boltstore struct that implements the store.Store interface.
type Updates ¶
type Updates struct { Agents Events[*model.Agent] AgentVersions Events[*model.AgentVersion] Sources Events[*model.Source] SourceTypes Events[*model.SourceType] Processors Events[*model.Processor] ProcessorTypes Events[*model.ProcessorType] Destinations Events[*model.Destination] DestinationTypes Events[*model.DestinationType] Configurations Events[*model.Configuration] }
Updates is a collection of events created by a store operation.
func (*Updates) AddAffectedConfigurations ¶ added in v1.9.0
func (u *Updates) AddAffectedConfigurations(configurations []*model.Configuration)
AddAffectedConfigurations will add updates for Configurations that are affected by other resource updates.
func (*Updates) AddAffectedDestinations ¶ added in v1.9.0
func (u *Updates) AddAffectedDestinations(destinations []*model.Destination)
AddAffectedDestinations will add updates for Destinations that are affected by other resource updates.
func (*Updates) AddAffectedProcessors ¶ added in v1.9.0
AddAffectedProcessors will add updates for Processors that are affected by other resource updates.
func (*Updates) AddAffectedSources ¶ added in v1.9.0
AddAffectedSources will add updates for Sources that are affected by other resource updates.
func (*Updates) AffectsConfiguration ¶ added in v1.9.0
func (u *Updates) AffectsConfiguration(configuration *model.Configuration) bool
AffectsConfiguration returns true if the updates affect the given configuration.
func (*Updates) AffectsDestination ¶ added in v1.9.0
func (u *Updates) AffectsDestination(destination *model.Destination) bool
AffectsDestination returns true if the updates affect the given destination.
func (*Updates) AffectsProcessor ¶ added in v1.9.0
AffectsProcessor returns true if the updates affect the given processor.
func (*Updates) AffectsSource ¶ added in v1.9.0
AffectsSource returns true if the updates affect the given source.
func (*Updates) CouldAffectConfigurations ¶ added in v1.9.0
CouldAffectConfigurations returns true if the updates could affect configurations.
func (*Updates) CouldAffectDestinations ¶ added in v1.9.0
CouldAffectDestinations returns true if the updates could affect destinations.
func (*Updates) CouldAffectProcessors ¶ added in v1.9.0
CouldAffectProcessors returns true if the updates could affect processors.
func (*Updates) CouldAffectSources ¶ added in v1.9.0
CouldAffectSources returns true if the updates could affect sources.
func (*Updates) HasDestinationEvents ¶ added in v1.9.0
HasDestinationEvents returns true if any destination events exist.
func (*Updates) HasDestinationTypeEvents ¶ added in v1.9.0
HasDestinationTypeEvents returns true if any destination type events exist.
func (*Updates) HasProcessorEvents ¶ added in v1.9.0
HasProcessorEvents returns true if any processor events exist.
func (*Updates) HasProcessorTypeEvents ¶ added in v1.9.0
HasProcessorTypeEvents returns true if any processor type events exist.
func (*Updates) HasSourceEvents ¶ added in v1.9.0
HasSourceEvents returns true if any source events exist.
func (*Updates) HasSourceTypeEvents ¶ added in v1.9.0
HasSourceTypeEvents returns true if any source type events exist.
func (*Updates) IncludeAgent ¶
IncludeAgent will add an agent event to Updates.
func (*Updates) IncludeAgentVersion ¶ added in v1.9.0
func (u *Updates) IncludeAgentVersion(agentVersion *model.AgentVersion, eventType EventType)
IncludeAgentVersion will add an agent version event to Updates.
func (*Updates) IncludeConfiguration ¶ added in v1.9.0
func (u *Updates) IncludeConfiguration(configuration *model.Configuration, eventType EventType)
IncludeConfiguration will add a configuration event to Updates.
func (*Updates) IncludeDestination ¶ added in v1.9.0
func (u *Updates) IncludeDestination(destination *model.Destination, eventType EventType)
IncludeDestination will add a destination event to Updates.
func (*Updates) IncludeDestinationType ¶ added in v1.9.0
func (u *Updates) IncludeDestinationType(destinationType *model.DestinationType, eventType EventType)
IncludeDestinationType will add a destination type event to Updates.
func (*Updates) IncludeProcessor ¶ added in v1.9.0
IncludeProcessor will add a processor event to Updates.
func (*Updates) IncludeProcessorType ¶ added in v1.9.0
func (u *Updates) IncludeProcessorType(processorType *model.ProcessorType, eventType EventType)
IncludeProcessorType will add a processor type event to Updates.
func (*Updates) IncludeResource ¶
IncludeResource will add a resource event to Updates. If the resource is not supported by Updates, this will do nothing.
func (*Updates) IncludeSource ¶ added in v1.9.0
IncludeSource will add a source event to Updates.
func (*Updates) IncludeSourceType ¶ added in v1.9.0
func (u *Updates) IncludeSourceType(sourceType *model.SourceType, eventType EventType)
IncludeSourceType will add a source type event to Updates.
type UpdatesEventBus ¶ added in v1.9.0
type UpdatesEventBus struct {
// contains filtered or unexported fields
}
UpdatesEventBus is a wrapped event bus for store updates.
func NewUpdatesEventBus ¶ added in v1.9.0
func NewUpdatesEventBus(ctx context.Context, maxEventsToMerge int) *UpdatesEventBus
NewUpdatesEventBus creates a new UpdatesEventBus.
func (*UpdatesEventBus) Send ¶ added in v1.9.0
func (s *UpdatesEventBus) Send(updates *Updates)
Send adds an Updates event to the internal channel where it can be merged and relayed to the external channel.
Directories ¶
Path | Synopsis |
---|---|
Package search provides a search engine with indexing and suggestions for the store
|
Package search provides a search engine with indexing and suggestions for the store |
Package stats provides the store for measurements associated with agents and configurations.
|
Package stats provides the store for measurements associated with agents and configurations. |