config

package
v0.0.0-...-f113805 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package config is designed to listen to the config changes through the store and create a fully-resolved configuration state that can be used by the rest of the runtime code.

The main purpose of this library is to create an object-model that simplifies queries and correctness checks that the client code needs to deal with. This is accomplished by making sure the config state is fully resolved, and incorporating otherwise complex queries within this package.

Index

Constants

View Source
const AdapterKind = "adapter"

AdapterKind defines the config kind Name of adapter infos (name, templates is consumes, its own configuration).

View Source
const AttributeManifestKind = "attributemanifest"

AttributeManifestKind define the config kind Name of attribute manifests.

View Source
const ContextProtocolAttributeName = "context.protocol"

ContextProtocolAttributeName is the attribute that defines the protocol context.

View Source
const ContextProtocolTCP = "tcp"

ContextProtocolTCP defines constant for tcp protocol.

View Source
const RulesKind = "rule"

RulesKind defines the config kind Name of mixer Rules.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(
	handler *HandlerLegacy,
	instances []*InstanceLegacy,
	env adapter.Env, templates map[string]*template.Info) (h adapter.Handler, err error)

BuildHandler instantiates a handler object using the passed in handler and instances configuration.

func GetInstancesGroupedByHandlers

func GetInstancesGroupedByHandlers(s *Snapshot) map[*HandlerLegacy][]*InstanceLegacy

GetInstancesGroupedByHandlers queries the snapshot and returns all used instances, grouped by the handlers that will receive them.

func KindMap

func KindMap(adapterInfo map[string]*adapter.Info, templateInfo map[string]*template.Info) map[string]proto.Message

KindMap generates a map from object kind to its proto message.

func ValidateBuilder

func ValidateBuilder(
	handler *HandlerLegacy,
	instances []*InstanceLegacy, templates map[string]*template.Info) (hb adapter.HandlerBuilder, err error)

ValidateBuilder constructs and validates a builder.

Types

type Action

type Action struct {
	// Handler that this action is resolved to.
	Handler *Handler
	// Instances that should be generated as part of invoking action.
	Instances []*Instance
}

Action configuration. Fully resolved.

type ActionLegacy

type ActionLegacy struct {
	// Handler that this action is resolved to.
	Handler *HandlerLegacy

	// Instances that should be generated as part of invoking action.
	Instances []*InstanceLegacy
}

ActionLegacy configuration. Fully resolved.

type Adapter

type Adapter struct {
	Name string

	// Adapter's file descriptor set.
	ConfigDescSet *descriptor.FileDescriptorSet

	// package name of the `Params` message
	PackageName string

	SupportedTemplates []Template

	SessionBased bool

	Description string
}

Adapter contains info about an adapter

type AdapterInfoRegistry

type AdapterInfoRegistry interface {
	GetAdapter(name string) *AdapterMetadata
	GetTemplate(name string) *TemplateMetadata
}

AdapterInfoRegistry to find metadata about templates and adapters

type AdapterMetadata

type AdapterMetadata struct {
	Name               string
	ConfigDescSet      *descriptor.FileDescriptorSet
	ConfigDescProto    *descriptor.FileDescriptorProto
	SupportedTemplates []string
}

AdapterMetadata contains info about an adapter

type Counters

type Counters struct {

	// Externally visible counters
	MatchErrors               prometheus.Counter
	UnsatisfiedActionHandlers prometheus.Counter
	HandlerValidationError    prometheus.Counter
	// contains filtered or unexported fields
}

Counters is the configuration related performance Counters. Other parts of the code can depend on some of the Counters here as well.

type Ephemeral

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

Ephemeral configuration state that gets updated by incoming config change events. By itself, the data contained is not meaningful. BuildSnapshot must be called to create a new snapshot instance, which contains fully resolved config. The Ephemeral is thread safe, which mean the state can be incrementally built asynchronously, before calling BuildSnapshot, using ApplyEvent.

func NewEphemeral

func NewEphemeral(
	templates map[string]*template.Info,
	adapters map[string]*adapter.Info) *Ephemeral

NewEphemeral returns a new Ephemeral instance.

NOTE: initial state is computed even if there are errors in the config. Configuration that has errors is reported in the returned error object, and is ignored in the snapshot creation.

func (*Ephemeral) ApplyEvent

func (e *Ephemeral) ApplyEvent(events []*store.Event)

ApplyEvent to the internal ephemeral state. This gets called by an external event listener to relay store change events to this ephemeral config object.

func (*Ephemeral) BuildSnapshot

func (e *Ephemeral) BuildSnapshot() (*Snapshot, error)

BuildSnapshot builds a stable, fully-resolved snapshot view of the configuration.

func (*Ephemeral) GetEntry

func (e *Ephemeral) GetEntry(event *store.Event) (*store.Resource, bool)

GetEntry returns the value stored for the key in the ephemeral.

func (*Ephemeral) SetState

func (e *Ephemeral) SetState(state map[store.Key]*store.Resource)

SetState with the supplied state map. All existing ephemeral state is overwritten.

type Handler

type Handler struct {
	Name string

	Adapter *Adapter

	// parameters used to construct the Handler.
	Params []byte

	// Connection information for the handler.
	Connection *v1beta1.Connection
}

Handler configuration. Fully resolved.

type HandlerLegacy

type HandlerLegacy struct {

	// Name of the Handler. Fully qualified.
	Name string

	// Associated adapter. Always resolved.
	Adapter *adapter.Info

	// parameters used to construct the Handler.
	Params proto.Message
}

HandlerLegacy configuration. Fully resolved.

type Instance

type Instance struct {
	Name string

	Template *Template

	// Encoder to create request instance bytes from attributes
	Encoder *dynamic.Encoder
}

Instance configuration. Fully resolved.

type InstanceLegacy

type InstanceLegacy struct {
	// Name of the instance. Fully qualified.
	Name string

	// Associated template. Always resolved.
	Template *template.Info

	// parameters used to construct the instance.
	Params proto.Message

	// inferred type for the instance.
	InferredType proto.Message
}

InstanceLegacy configuration. Fully resolved.

type ResourceType

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

ResourceType codifies types of resources. resources apply to certain protocols or methods.

func (ResourceType) IsCheck

func (r ResourceType) IsCheck() bool

IsCheck returns true if resource is for HTTP

func (ResourceType) IsHTTP

func (r ResourceType) IsHTTP() bool

IsHTTP returns true if resource is for HTTP

func (ResourceType) IsPreprocess

func (r ResourceType) IsPreprocess() bool

IsPreprocess returns true if resource is for Preprocess

func (ResourceType) IsQuota

func (r ResourceType) IsQuota() bool

IsQuota returns true if resource is for IsQuota

func (ResourceType) IsReport

func (r ResourceType) IsReport() bool

IsReport returns true if resource is for Report

func (ResourceType) IsTCP

func (r ResourceType) IsTCP() bool

IsTCP returns true if resource is for TCP

func (ResourceType) String

func (r ResourceType) String() string

String return string presentation of const.

type Rule

type Rule struct {
	Name         string
	Namespace    string
	Match        string
	Actions      []*Action
	ResourceType ResourceType
}

Rule configuration. Fully resolved.

type RuleLegacy

type RuleLegacy struct {
	// Name of the rule
	Name string

	// Namespace of the rule
	Namespace string

	// Match condition
	Match string

	Actions []*ActionLegacy

	ResourceType ResourceType
}

RuleLegacy configuration. Fully resolved.

type Snapshot

type Snapshot struct {
	ID int64

	// Static information
	Templates map[string]*template.Info
	Adapters  map[string]*adapter.Info

	// Config store based information
	Attributes ast.AttributeDescriptorFinder

	HandlersLegacy  map[string]*HandlerLegacy
	InstancesLegacy map[string]*InstanceLegacy
	RulesLegacy     []*RuleLegacy

	//  TemplateMetadatas contains template descriptors loaded from the store
	TemplateMetadatas map[string]*TemplateMetadata
	//  AdapterMetadatas contains adapter metadata loaded from the store
	AdapterMetadatas map[string]*AdapterMetadata

	Handlers  map[string]*Handler
	Instances map[string]*Instance
	Rules     []*Rule

	// Perf Counters relevant to configuration.
	Counters Counters
}

Snapshot view of configuration.

func Empty

func Empty() *Snapshot

Empty returns a new, empty configuration snapshot.

func GetSnapshotForTest

func GetSnapshotForTest(templates map[string]*template.Info, adapters map[string]*adapter.Info, serviceConfig string, globalConfig string) (*Snapshot, error)

GetSnapshotForTest creates a config.Snapshot for testing purposes, based on the supplied configuration.

func (*Snapshot) String

func (s *Snapshot) String() string

String writes out contents of a snapshot in a stable way. Useful for quickly writing out contents in a string for comparison testing.

type Template

type Template struct {
	// Name of the template.
	//
	// Note this is the template's resource name and not the template's internal name that adapter developer
	// uses to implement adapter service.
	Name string

	// InternalPackageDerivedName is the name of the template from adapter developer point of view.
	// The service and functions implemented by the adapter is based on this name
	// NOTE: This name derived from template proto package and not the resource name.
	InternalPackageDerivedName string

	// Template's file descriptor set.
	FileDescSet *descriptor.FileDescriptorSet

	// package name of the `Template` message
	PackageName string
}

Template contains info about a template

type TemplateMetadata

type TemplateMetadata struct {
	Name          string
	FileDescSet   *descriptor.FileDescriptorSet
	FileDescProto *descriptor.FileDescriptorProto
}

TemplateMetadata contains info about a template

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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