routing

package
v0.0.0-...-35e2b90 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package routing implements a routing table for resolving incoming requests to handlers. The table data model is structured for efficient use by the runtime code during actual dispatch. At a high-level, the structure of table is as follows:

Table: map[variety]varietyTable varietyTable: map[namespace]NamespaceTable NamespaceTable: list(Destination) Destination: unique(handler&template) + list(InstanceGroup) InstanceGroup: condition + list(InstanceBuilders) + list(OutputMappers)

The call into table.GetDestinations performs a lookup on the first map by the variety (i.e. quota, check, report, apa etc.), followed by a lookup on the second map for the namespace, and a NamespaceTable struct is returned.

The returned NamespaceTable holds all the handlers that should be dispatched to, along with conditions and builders for the instances. These include handlers that were defined for the namespace of the request, as well as the handlers from the default namespace. If there were no explicit rules in the request's namespace, then only the handlers from the default namespace is applied. Similarly, if the request is for the default namespace, then only the handlers from the default namespace is applied.

Beneath the namespace layer, the same handler can appear multiple times in this list for each template that is supported by the handler. This helps caller to ensure that each dispatch to the handler will use a unique template.

The client code is expected to work as follows:

  • Call GetDestinations(variety, namespace) to get a NamespaceTable.
  • Go through the list of entries in the NamespaceTable.
  • For each entry begin a dispatch session to the associated handler.
  • Go through the InstanceGroup
  • For each InstanceGroup, check the condition and see if the inputs/outputs apply.
  • If applies, then call InstanceBuilders to create instances
  • Depending on the variety, either aggregate all instances in the group, and send them all at once, or dispatch for every instance individually to the adapter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Destination

type Destination struct {

	// Handler to invoke
	Handler adapter.Handler

	// HandlerName is the name of the handler. Used for monitoring/logging purposes.
	HandlerName string

	// AdapterName is the name of the adapter. Used for monitoring/logging purposes.
	AdapterName string

	// Template of the handler.
	Template *template.Info

	// InstanceGroups that should be (conditionally) applied to the handler.
	InstanceGroups []*InstanceGroup

	// FriendlyName is the friendly name of this configured handler entry. Used for monitoring/logging purposes.
	FriendlyName string

	// Perf counters for keeping track of dispatches to adapters/handlers.
	Counters DestinationCounters
	// contains filtered or unexported fields
}

Destination contains a target handler, and instances to send, grouped by the conditional match that applies to them.

func (*Destination) MaxInstances

func (d *Destination) MaxInstances() int

MaxInstances returns the maximum number of instances that can be built from this Destination.

type DestinationCounters

type DestinationCounters struct {
	// contains filtered or unexported fields
}

DestinationCounters are used to track the total/failed dispatch counts and dispatch duration for a target destination, based on the template/handler/adapter label set.

func (DestinationCounters) Update

func (d DestinationCounters) Update(duration time.Duration, failed bool)

Update the counters. Duration is the total dispatch duration. Failed indicates whether the dispatch returned an error or not.

type InstanceGroup

type InstanceGroup struct {

	// Condition for applying this instance group.
	Condition compiled.Expression

	// TODO(Issue #2139): This should be removed when we stop doing resource-type based checks.
	// ResourceType is the resource type condition for this instance group.
	ResourceType config.ResourceType

	// Builders for the instances in this group for each instance that should be applied.
	Builders []template.InstanceBuilderFn

	// Mappers for attribute-generating adapters that map output attributes into the main attribute set.
	Mappers []template.OutputMapperFn
	// contains filtered or unexported fields
}

InstanceGroup is a set of instances that needs to be sent to a handler, grouped by a condition expression.

func (*InstanceGroup) Matches

func (i *InstanceGroup) Matches(bag attribute.Bag) bool

Matches returns true, if the instances from this input set should be used for the given attribute bag.

type NamespaceTable

type NamespaceTable struct {
	// contains filtered or unexported fields
}

NamespaceTable contains a list of destinations that should be targeted for a given namespace.

func (*NamespaceTable) Count

func (d *NamespaceTable) Count() int

Count returns the number of entries contained.

func (*NamespaceTable) Entries

func (d *NamespaceTable) Entries() []*Destination

Entries in the table.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is the main routing table. It is used to find the set of handlers that should be invoked, along with the instance builders and match conditions.

func BuildTable

func BuildTable(
	handlers *handler.Table,
	config *config.Snapshot,
	expb *compiled.ExpressionBuilder,
	defaultConfigNamespace string,
	debugInfo bool) *Table

BuildTable builds and returns a routing table. If debugInfo is set, the returned table will have debugging information attached, which will show up in String() call.

func Empty

func Empty() *Table

Empty returns an empty routing table.

func (*Table) GetDestinations

func (t *Table) GetDestinations(variety tpb.TemplateVariety, namespace string) *NamespaceTable

GetDestinations returns the set of destinations (handlers) for the given template variety and for the given namespace.

func (*Table) ID

func (t *Table) ID() int64

ID of the table. Based on the Config Snapshot id.

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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