routing

package
v0.0.0-...-dcdb1c8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: Apache-2.0 Imports: 19 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 *TemplateInfo

	// 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
	// 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 DirectiveGroup

type DirectiveGroup struct {
	Condition  compiled.Expression
	Operations []*HeaderOperation
}

DirectiveGroup is a group of route directive expressions with a condition. Directive expressions reference destination action names. Note that InstanceGroup organizes by handlers, rather than rules, which necessitates a different grouping for directives.

type HeaderOperation

type HeaderOperation struct {
	Type        HeaderOperationType
	HeaderName  string
	HeaderValue compiled.Expression
	Operation   descriptor.Rule_HeaderOperationTemplate_Operation
}

HeaderOperation is an intermediate form of a rule header operation.

type HeaderOperationType

type HeaderOperationType int

HeaderOperationType is an enumeration for the route directive header operation template type.

const (
	RequestHeaderOperation HeaderOperationType = iota
	ResponseHeaderOperation
)

Request and response header operation types.

type InstanceGroup

type InstanceGroup struct {

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

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

	// 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 NamedBuilder

type NamedBuilder struct {
	InstanceShortName string
	Builder           template.InstanceBuilderFn

	// ActionName is the action name in the rule, used to reference the output of the handler applied to the instance
	ActionName string
}

NamedBuilder holds a builder function and the short name of the associated instance.

type NamespaceTable

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

NamespaceTable contains a list of destinations and directives 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) Directives

func (d *NamespaceTable) Directives() []*DirectiveGroup

Directives in the table

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,
	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. CHECK_WITH_OUTPUT variety destinations are grouped together with CHECK variety destinations.

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

type TemplateInfo

type TemplateInfo struct {
	Name             string
	Variety          tpb.TemplateVariety
	DispatchReport   template.DispatchReportFn
	DispatchCheck    template.DispatchCheckFn
	DispatchQuota    template.DispatchQuotaFn
	DispatchGenAttrs template.DispatchGenerateAttributesFn
}

TemplateInfo is the common data that is needed from a template

Jump to

Keyboard shortcuts

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