entitycache

package
v0.1.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(originalService, mergedService *entitycachev1.Service)

Merge merges `mergedService` into `originalService`. This sums `EntitiesCount`.

func Module added in v0.1.2

func Module() fx.Option

Module sets up EntityCache with Fx.

func RegisterEntityCacheService added in v0.1.2

func RegisterEntityCacheService(server *grpc.Server, cache *EntityCache)

RegisterEntityCacheService registers a service for entity cache.

func ServiceIDsFromEntity

func ServiceIDsFromEntity(entity *Entity) []services.ServiceID

ServiceIDsFromEntity returns a list of services the entity is a part of.

Types

type Entity

type Entity struct {
	// ID of the entity
	ID EntityID `json:"id,omitempty"`

	// IP Address of this entity
	IPAddress string `json:"ip_address"`
	// Services is a List of names of services this entity is a part of.
	// We store "well-known-labels" (identifying a service) in a separate
	// fields for easier access. Note: we could store `[]agent_core/services/ServiceID`
	// here directly, but right now it'd cause cyclic dependency.
	Services []string `json:"services"`
	// EntityName is the name of this entity
	EntityName string `json:"name"`
}

Entity represents a pod, vm, etc.

Entities can be created with NewEntity.

func NewEntity

func NewEntity(id EntityID, ipAddress, name string, services []string) *Entity

NewEntity creates a new entity from ID and IP address from the tagger.

func (*Entity) IP

func (e *Entity) IP() string

IP returns IP of this entity.

func (*Entity) Name

func (e *Entity) Name() string

Name returns Name of this entity.

type EntityCache

type EntityCache struct {
	entitycachev1.UnimplementedEntityCacheServiceServer
	sync.RWMutex
	// contains filtered or unexported fields
}

EntityCache maps IP addresses and Entity names to entities.

func NewEntityCache

func NewEntityCache() *EntityCache

NewEntityCache creates a new, empty EntityCache.

func (*EntityCache) Clear

func (c *EntityCache) Clear()

Clear removes all entities from the cache.

func (*EntityCache) GetByIP

func (c *EntityCache) GetByIP(entityIP string) *Entity

GetByIP retrieves entity with a given IP address.

func (*EntityCache) GetByName

func (c *EntityCache) GetByName(entityName string) *Entity

GetByName retrieves entity with a given name.

func (*EntityCache) GetServicesList added in v0.1.2

func (c *EntityCache) GetServicesList(ctx context.Context, _ *emptypb.Empty) (*entitycachev1.ServicesList, error)

GetServicesList returns a list of services based on entities in cache.

func (*EntityCache) Put

func (c *EntityCache) Put(entity *Entity)

Put maps given IP address and name to the entity it currently represents.

func (*EntityCache) Remove

func (c *EntityCache) Remove(entity *Entity) bool

Remove removes entity from the cache and returns `true` if any of IP address or name mapping exists. If no such entity was found, returns `false`.

func (*EntityCache) Services

func (c *EntityCache) Services() *entitycachev1.ServicesList

Services returns a list of services based on entities in cache.

Each service is identified by 2 values: - agent group - service name

This shouldn't happen in real world, but entities which have multiple values for an agent group is ignored. Entities which have multiple values for service name will create one service for each of them.

type EntityID

type EntityID struct {
	Prefix string `json:"prefix,omitempty"`
	UID    string `json:"uid,omitempty"`
}

EntityID is a unique Entity identifier.

type FxIn

type FxIn struct {
	fx.In
	Lifecycle      fx.Lifecycle
	EntityTrackers notifiers.Trackers `name:"entity_trackers"`
}

FxIn are the parameters for ProvideEntityCache.

type ServiceKey

type ServiceKey struct {
	Name string `json:"name"`
}

ServiceKey holds key for service.

Jump to

Keyboard shortcuts

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