package routing

import "istio.io/istio/mixer/pkg/runtime/routing"

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:

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

type Destination struct {
// Handler to invokeHandleradapter.Handler// HandlerName is the name of the handler. Used for monitoring/logging purposes.HandlerNamestring// AdapterName is the name of the adapter. Used for monitoring/logging purposes.AdapterNamestring// 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.FriendlyNamestring// contains filtered or unexported fields
}

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

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 InstanceGroup struct {
// Condition for applying this instance group.Conditioncompiled.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.

type NamedBuilder struct {
InstanceShortNamestringBuildertemplate.InstanceBuilderFn// ActionName is the action name in the rule, used to reference the output of the handler applied to the instanceActionNamestring
}

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

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.