endpointdiscovery

package module
v1.9.6 Latest Latest
Warning

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

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

Documentation

Overview

Package endpointdiscovery provides a feature implemented in the AWS SDK for Go V2 that allows client to fetch a valid endpoint to serve an API request. Discovered endpoints are stored in an internal thread-safe cache to reduce the number of calls made to fetch the endpoint.

Endpoint discovery stores endpoint by associating to a generated cache key. Cache key is built using service-modeled sdkId and any service-defined input identifiers provided by the customer.

Endpoint cache keys follow the grammar:

key = sdkId.identifiers

identifiers = map[string]string

The endpoint discovery cache implementation is internal. Clients resolves the cache size to 10 entries. Each entry may contain multiple host addresses as returned by the service.

Each discovered endpoint has a TTL associated to it, and are evicted from cache lazily i.e. when client tries to retrieve an endpoint but finds an expired entry instead.

Endpoint discovery feature can be turned on by setting the `AWS_ENABLE_ENDPOINT_DISCOVERY` env variable to TRUE.

By default, the feature is set to AUTO - indicating operations that require endpoint discovery always use it. To completely turn off the feature, one should set the value as FALSE. Similar configuration rules apply for shared config file where key is `endpoint_discovery_enabled`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscoverEndpoint

type DiscoverEndpoint struct {

	// Options provides optional settings used with
	// Discover Endpoint operation.
	Options []func(*DiscoverEndpointOptions)

	// DiscoverOperation represents the endpoint discovery operation that
	// returns an Endpoint or error.
	DiscoverOperation func(ctx context.Context, region string, options ...func(*DiscoverEndpointOptions)) (WeightedAddress, error)

	// EndpointDiscoveryEnableState represents the customer configuration for endpoint
	// discovery feature.
	EndpointDiscoveryEnableState aws.EndpointDiscoveryEnableState

	// EndpointDiscoveryRequired states if an operation requires to perform
	// endpoint discovery.
	EndpointDiscoveryRequired bool

	// The client region
	Region string
}

DiscoverEndpoint is a finalize step middleware used to discover endpoint for an API operation.

func (*DiscoverEndpoint) HandleFinalize added in v1.8.3

HandleFinalize performs endpoint discovery and updates the request host with the result.

The resolved host from this procedure MUST override that of modeled endpoint resolution and middleware should be ordered accordingly.

func (*DiscoverEndpoint) ID

func (*DiscoverEndpoint) ID() string

ID represents the middleware identifier

type DiscoverEndpointOptions

type DiscoverEndpointOptions struct {

	// EndpointResolverUsedForDiscovery is the endpoint resolver used to
	// resolve an endpoint for discovery api call.
	EndpointResolverUsedForDiscovery interface{}

	// DisableHTTPS will disable tls for endpoint discovery call and
	// subsequent discovered endpoint if service did not return an
	// endpoint scheme.
	DisableHTTPS bool

	// Logger to log warnings or debug statements.
	Logger logging.Logger
}

DiscoverEndpointOptions are optionals used with DiscoverEndpoint operation.

type Endpoint

type Endpoint struct {
	Key       string
	Addresses WeightedAddresses
}

Endpoint represents an endpoint used in endpoint discovery.

func (*Endpoint) Add

func (e *Endpoint) Add(addr WeightedAddress)

Add will add a given WeightedAddress to the address list of Endpoint.

func (*Endpoint) GetValidAddress

func (e *Endpoint) GetValidAddress() (WeightedAddress, bool)

GetValidAddress will return a non-expired weight endpoint

func (*Endpoint) Len

func (e *Endpoint) Len() int

Len returns the number of valid endpoints where valid means the endpoint has not expired.

func (*Endpoint) Prune added in v1.3.2

func (e *Endpoint) Prune() bool

Prune will prune the expired addresses from the endpoint by allocating a new []WeightAddress. This is not concurrent safe, and should be called from a single owning thread.

type EndpointCache

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

EndpointCache is an LRU cache that holds a series of endpoints based on some key. The data structure makes use of a read write mutex to enable asynchronous use.

func NewEndpointCache

func NewEndpointCache(endpointLimit int64) *EndpointCache

NewEndpointCache will return a newly initialized cache with a limit of endpointLimit entries.

func (*EndpointCache) Add

func (c *EndpointCache) Add(endpoint Endpoint)

Add is a concurrent safe operation that will allow new endpoints to be added to the cache. If the cache is full, the number of endpoints equal endpointLimit, then this will remove the oldest entry before adding the new endpoint.

func (*EndpointCache) Get

func (c *EndpointCache) Get(endpointKey string) (WeightedAddress, bool)

Get will retrieve a weighted address based off of the endpoint key. If an endpoint should be retrieved, due to not existing or the current endpoint has expired the Discoverer object that was passed in will attempt to discover a new endpoint and add that to the cache.

func (*EndpointCache) Has

func (c *EndpointCache) Has(endpointKey string) bool

Has returns if the enpoint cache contains a valid entry for the endpoint key provided.

type WeightedAddress

type WeightedAddress struct {
	URL     *url.URL
	Expired time.Time
}

WeightedAddress represents an address with a given weight.

func (WeightedAddress) HasExpired

func (e WeightedAddress) HasExpired() bool

HasExpired will return whether or not the endpoint has expired with the exception of a zero expiry meaning does not expire.

type WeightedAddresses

type WeightedAddresses []WeightedAddress

WeightedAddresses represents a list of WeightedAddress.

Jump to

Keyboard shortcuts

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