Documentation
¶
Index ¶
- Constants
- Variables
- func IsNoLabelsFound(err error) bool
- func MakePodLabelKey(node types.NodeName, podID types.PodID) string
- func NewConsulAggregator(labelType Type, kv consulutil.ConsulLister, logger logging.Logger, ...) *consulAggregator
- func NewFakeApplicator() *fakeApplicator
- func NewHTTPApplicator(client *http.Client, matchesEndpoint *url.URL) (*httpApplicator, error)
- func NewHTTPLabelServer(applicator ApplicatorWithoutWatches, batchTime time.Duration, ...) *labelHTTPServer
- func NodeAndPodIDFromPodLabel(labeled Labeled) (types.NodeName, types.PodID, error)
- func Nothing() labels.Selector
- type Applicator
- type ApplicatorWithoutWatches
- type Batcher
- type CASError
- type ConsulApplicator
- func (c *ConsulApplicator) GetCachedMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error)
- func (c *ConsulApplicator) GetLabels(labelType Type, id string) (Labeled, error)
- func (c *ConsulApplicator) GetLabelsWithIndex(labelType Type, id string) (Labeled, uint64, error)
- func (c *ConsulApplicator) GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error)
- func (c *ConsulApplicator) ListLabels(labelType Type) ([]Labeled, error)
- func (c *ConsulApplicator) RemoveAllLabels(labelType Type, id string) error
- func (c *ConsulApplicator) RemoveAllLabelsTxn(ctx context.Context, labelType Type, id string) error
- func (c *ConsulApplicator) RemoveLabel(labelType Type, id, label string) error
- func (c *ConsulApplicator) RemoveLabelTxn(ctx context.Context, labelType Type, id, label string) error
- func (c *ConsulApplicator) RemoveLabelsTxn(ctx context.Context, labelType Type, id string, keysToRemove []string) error
- func (c *ConsulApplicator) SetLabel(labelType Type, id, label, value string) error
- func (c *ConsulApplicator) SetLabelTxn(ctx context.Context, labelType Type, id, label, value string) error
- func (c *ConsulApplicator) SetLabels(labelType Type, id string, labels map[string]string) error
- func (c *ConsulApplicator) SetLabelsTxn(ctx context.Context, labelType Type, id string, labels map[string]string) error
- func (c *ConsulApplicator) SetMetricsRegistry(metReg MetricsRegistry)
- func (c *ConsulApplicator) WatchMatchDiff(selector labels.Selector, labelType Type, aggregationRate time.Duration, ...) <-chan *LabeledChanges
- func (c *ConsulApplicator) WatchMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration, ...) (chan []Labeled, error)
- type LabelFetcher
- type Labeled
- type LabeledChanges
- type LabeledWithIndex
- type MetricsRegistry
- type SetLabelRequest
- type SetLabelsRequest
- type Type
- type TypeBatcher
Constants ¶
const ( POD = Type("pod") NODE = Type("node") PC = Type("pod_clusters") RC = Type("replication_controller") RU = Type("rolls") )
These types (with the exception of RC) are named such that the path to an objects labels is the same as the path to the object but with labelRoot prepended. Example: the labels for /intent/foo.com/slug are at /labels/intent/foo.com/slug. Note: the tree name for RCs is pluralized, while the label is not, so this doesn't hold true for RCs
Variables ¶
var DefaultAggregationRate = 10 * time.Second
minimum required time between retrievals of label subtrees.
var InvalidType error = errors.New("Invalid type provided")
var NoLabelsFound = errors.New("No labels found")
NoLabelsFound represents a 404 error from consul. In most cases the results should be ignored if this error is encountered because under normal operation there should always be labels for most types such as replication controllers. Resources that trend to zero such as rolling updates are an example of a case where this error might be expected under normal operation. The client must know the safety and likelihood of missing labels and decide what to do based on that information.
Functions ¶
func IsNoLabelsFound ¶
func MakePodLabelKey ¶
these utility functions are used primarily while we exist in a mutable deployment world. We will need to figure out how to replace these with different datasources to allow RCs and DSs to continue to function correctly in the future.
func NewConsulAggregator ¶
func NewConsulAggregator( labelType Type, kv consulutil.ConsulLister, logger logging.Logger, metReg MetricsRegistry, aggregationRate time.Duration, ) *consulAggregator
func NewFakeApplicator ¶
func NewFakeApplicator() *fakeApplicator
func NewHTTPApplicator ¶
func NewHTTPLabelServer ¶
func NewHTTPLabelServer(applicator ApplicatorWithoutWatches, batchTime time.Duration, logger logging.Logger) *labelHTTPServer
Construct a new HTTP Applicator server. If batchTime is non-zero, use batching for handling requests that operate over an entire label type (select, list).
Types ¶
type Applicator ¶
type Applicator interface { // Assign a label to the object identified by the Type and ID SetLabel(labelType Type, id, name, value string) error // Assign a group of labels in a batched operation SetLabels(labelType Type, id string, labels map[string]string) error // Remove a label from the identified object RemoveLabel(labelType Type, id, name string) error // Remove all labels from the identified object RemoveAllLabels(labelType Type, id string) error // Lists all labels on all objects associated with this type. // mostly useful for secondary caching. Do not use directly // if you just want to answer a simple query - use GetMatches // instead. ListLabels(labelType Type) ([]Labeled, error) // Get all Labels assigned to the given object GetLabels(labelType Type, id string) (Labeled, error) // Return all objects of the given type that match the given selector. GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error) // Return all objects of the given type that match the given selector // out of a cache that is refreshed at a rate according to // aggregationRate GetCachedMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error) // Watch a label selector of a given type and see updates to that set // of Labeled over time. If an error occurs, the Applicator implementation // is responsible for handling it and recovering gracefully. // // The watch may be terminated by the underlying implementation without signaling on // the quit channel - this will be indicated by the closing of the result channel. For // this reason, callers should **always** verify that the channel is closed by checking // the "ok" boolean or using `range`. WatchMatches( selector labels.Selector, labelType Type, aggregationRate time.Duration, quitCh <-chan struct{}, ) (chan []Labeled, error) // WatchMatchDiff does a diff on top of the results form the WatchMatches and // returns a LabeledChanges structure which contain changes WatchMatchDiff( selector labels.Selector, labelType Type, aggregationRate time.Duration, quitCh <-chan struct{}, ) <-chan *LabeledChanges }
General purpose backing store for labels and assignment to P2 objects
type ApplicatorWithoutWatches ¶
type ApplicatorWithoutWatches interface { SetLabel(labelType Type, id, name, value string) error SetLabels(labelType Type, id string, labels map[string]string) error SetLabelsTxn(ctx context.Context, labelType Type, id string, labels map[string]string) error RemoveLabel(labelType Type, id, name string) error RemoveLabelTxn(ctx context.Context, labelType Type, id, name string) error RemoveAllLabels(labelType Type, id string) error RemoveLabelsTxn(ctx context.Context, labelType Type, id string, keysToRemove []string) error RemoveAllLabelsTxn(ctx context.Context, labelType Type, id string) error ListLabels(labelType Type) ([]Labeled, error) GetLabels(labelType Type, id string) (Labeled, error) GetMatches(selector klabels.Selector, labelType Type) ([]Labeled, error) GetCachedMatches(selector klabels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error) GetLabelsWithIndex(labelType Type, id string) (Labeled, uint64, error) }
General purpose backing store for labels and assignment to P2 objects. This is a subset of the labels.Applicator that omits the Watch functions
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
func NewBatcher ¶
func (*Batcher) ForType ¶
func (b *Batcher) ForType(labelType Type) *TypeBatcher
type ConsulApplicator ¶
type ConsulApplicator struct {
// contains filtered or unexported fields
}
func NewConsulApplicator ¶
func NewConsulApplicator(client consulutil.ConsulClient, retries int, watchJitterWindow time.Duration) *ConsulApplicator
func (*ConsulApplicator) GetCachedMatches ¶
func (*ConsulApplicator) GetLabels ¶
func (c *ConsulApplicator) GetLabels(labelType Type, id string) (Labeled, error)
func (*ConsulApplicator) GetLabelsWithIndex ¶
func (*ConsulApplicator) GetMatches ¶
func (*ConsulApplicator) ListLabels ¶
func (c *ConsulApplicator) ListLabels(labelType Type) ([]Labeled, error)
func (*ConsulApplicator) RemoveAllLabels ¶
func (c *ConsulApplicator) RemoveAllLabels(labelType Type, id string) error
func (*ConsulApplicator) RemoveAllLabelsTxn ¶
RemoveAllLabelsTxn is the same as RemoveAllLabels but adds the operation to the passed transaction rather than synchronously making the requisite consul call
func (*ConsulApplicator) RemoveLabel ¶
func (c *ConsulApplicator) RemoveLabel(labelType Type, id, label string) error
func (*ConsulApplicator) RemoveLabelTxn ¶
func (*ConsulApplicator) RemoveLabelsTxn ¶
func (*ConsulApplicator) SetLabel ¶
func (c *ConsulApplicator) SetLabel(labelType Type, id, label, value string) error
func (*ConsulApplicator) SetLabelTxn ¶
func (*ConsulApplicator) SetLabelsTxn ¶
func (c *ConsulApplicator) SetLabelsTxn(ctx context.Context, labelType Type, id string, labels map[string]string) error
TODO: replace SetLabels() with this implementation. It's just separate right now to make exploring solutions require less code churn
func (*ConsulApplicator) SetMetricsRegistry ¶
func (c *ConsulApplicator) SetMetricsRegistry(metReg MetricsRegistry)
func (*ConsulApplicator) WatchMatchDiff ¶
func (c *ConsulApplicator) WatchMatchDiff( selector labels.Selector, labelType Type, aggregationRate time.Duration, quitCh <-chan struct{}, ) <-chan *LabeledChanges
func (*ConsulApplicator) WatchMatches ¶
func (c *ConsulApplicator) WatchMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration, quitCh <-chan struct{}) (chan []Labeled, error)
The current schema of labels in Consul is optimized for label retrieval on a single object of a given ID. This layout is less effective when attempting to perform a watch on the results of an arbitrary label selector, which is necessarily un-indexable. This implementation will perform the simplest possible optimization, which is to cache the entire contents of the tree under the given label type and share it with other watches.
Due to the possibility that this tree might change quite frequently in environments with lots of concurrent deployments, the aggregated result from Consul will only be queried by a maximum frequency of once per LabelAggregationCap.
Preparers should not use the consulApplicator's implementation of WatchMatches directly due to the cost of querying for this subtree on any sizeable fleet of machines. Instead, preparers should use the httpApplicator from a server that exposes the results of this (or another) implementation's watch.
type LabelFetcher ¶
type Labeled ¶
type LabeledChanges ¶
type LabeledWithIndex ¶
type MetricsRegistry ¶
type SetLabelRequest ¶
type SetLabelRequest struct {
Value string `json:"value"`
}
type SetLabelsRequest ¶
type TypeBatcher ¶
type TypeBatcher struct {
// contains filtered or unexported fields
}
Batches a single label type
func (*TypeBatcher) Retrieve ¶
func (b *TypeBatcher) Retrieve() ([]Labeled, error)