store

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func InitDB(storageFilePath string) (*bbolt.DB, error)

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 Seed

func Seed(store Store, logger *zap.Logger) error

Seed adds bundled resources to the store

Types

type AgentUpdater

type AgentUpdater func(current *model.Agent)

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]) Contains

func (e Events[T]) Contains(uniqueKey string, eventType EventType) bool

Contains returns true if the item already exists

func (Events[T]) Empty

func (e Events[T]) Empty() bool

Empty returns true if there are no events

func (Events[T]) Include

func (e Events[T]) Include(item T, eventType EventType)

Include an item of with the specified event type.

func (Events[T]) Keys

func (e Events[T]) Keys() []string

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(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)

	Configurations(options ...QueryOption) ([]*model.Configuration, error)
	Configuration(string) (*model.Configuration, error)
	DeleteConfiguration(string) (*model.Configuration, error)

	Source(name string) (*model.Source, error)
	Sources() ([]*model.Source, error)
	DeleteSource(name string) (*model.Source, error)

	SourceType(name string) (*model.SourceType, error)
	SourceTypes() ([]*model.SourceType, error)
	DeleteSourceType(name string) (*model.SourceType, error)

	Destination(name string) (*model.Destination, error)
	Destinations() ([]*model.Destination, error)
	DeleteDestination(name string) (*model.Destination, error)

	DestinationType(name string) (*model.DestinationType, error)
	DestinationTypes() ([]*model.DestinationType, error)
	DeleteDestinationType(name string) (*model.DestinationType, error)

	ApplyResources([]model.Resource) ([]model.ResourceStatus, error)
	// Batch delete of a slice of resources, returns the successfully deleted resources or an error.
	DeleteResources([]model.Resource) ([]model.ResourceStatus, error)

	// AgentConfiguration returns the configuration that should be applied to an agent.
	AgentConfiguration(agentID string) (*model.Configuration, error)

	// AgentsIDsMatchingConfiguration returns the list of agent IDs that are using the specified configuration
	AgentsIDsMatchingConfiguration(*model.Configuration) ([]string, error)

	// CleanupDisconnectedAgents removes agents that have disconnected before the specified time
	CleanupDisconnectedAgents(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() search.Index

	// ConfigurationIndex provides access to the search Index for Configurations
	ConfigurationIndex() search.Index

	// UserSessions must implement the gorilla sessions.Store interface
	UserSessions() sessions.Store
}

Store handles interacting with a storage backend,

func NewBoltStore

func NewBoltStore(db *bbolt.DB, sessionsSecret string, logger *zap.Logger) Store

NewBoltStore returns a new store boltstore struct that implements the store.Store interface.

func NewGoogleCloudStore

func NewGoogleCloudStore(ctx context.Context, cfg *common.Server, logger *zap.Logger) (Store, error)

NewGoogleCloudStore creates a new Google Cloud store that uses Cloud Datastore for storage and Pub/sub for events.

func NewMapStore

func NewMapStore(logger *zap.Logger, sessionsSecret string) Store

NewMapStore returns an in memory Store

type Updates

type Updates struct {
	Agents           Events[*model.Agent]
	Sources          Events[*model.Source]
	SourceTypes      Events[*model.SourceType]
	Destinations     Events[*model.Destination]
	DestinationTypes Events[*model.DestinationType]
	Configurations   Events[*model.Configuration]
}

Updates are sent on the channel available from Store.Updates().

func NewUpdates

func NewUpdates() *Updates

NewUpdates returns a New Updates struct

func (*Updates) Empty

func (updates *Updates) Empty() bool

Empty returns true if all individual updates are empty

func (*Updates) IncludeAgent

func (updates *Updates) IncludeAgent(agent *model.Agent, eventType EventType)

IncludeAgent will include the agent in the updates. While updates.Agents.Include can also be used directly, this matches the pattern of IncludeResource.

func (*Updates) IncludeResource

func (updates *Updates) IncludeResource(r model.Resource, eventType EventType)

IncludeResource will include the resource in the updates for the appropriate type. If the specified Resource is not supported by Updates, this will do nothing.

func (*Updates) Size

func (updates *Updates) Size() int

Size returns the sum of all updates of all types

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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