Documentation
¶
Overview ¶
Package service provides basic integration with go.serversets
Deprecated: service is no longer planned to be used by future WebPA/XMiDT services.
This package is frozen and no new functionality will be added.
Index ¶
- Constants
- Variables
- func FormatInstance(scheme, address string, port int) string
- func Metrics() []xmetrics.Metric
- func NewAccessorEndpoint(a accessor.Accessor) endpoint.Endpoint
- func NewContextualInstancer(i sd.Instancer, m map[string]interface{}) sd.Instancer
- func NopCloser() error
- func NormalizeInstance(defaultScheme, instance string) (string, error)
- type ContextualInstancer
- type Environment
- type Instancers
- type Key
- type KeyParser
- type MockEnvironment
- func (m *MockEnvironment) AccessorFactory() accessor.AccessorFactory
- func (m *MockEnvironment) Close() error
- func (m *MockEnvironment) Closed() <-chan struct{}
- func (m *MockEnvironment) DefaultScheme() string
- func (m *MockEnvironment) Deregister()
- func (m *MockEnvironment) Instancers() Instancers
- func (m *MockEnvironment) IsRegistered(instance string) bool
- func (m *MockEnvironment) Register()
- func (m *MockEnvironment) UpdateInstancers(currentKeys map[string]bool, instancersToAdd Instancers)
- type MockInstancer
- type MockRegistrar
- type Option
- type Registrars
- type StringKey
Constants ¶
const ( ErrorCount = "sd_error_count" UpdateCount = "sd_update_count" InstanceCount = "sd_instance_count" LastErrorTimestamp = "sd_last_error_timestamp" LastUpdateTimestamp = "sd_last_update_timestamp" ServiceLabel = "service" EventKeyLabel = "eventKey" )
const DefaultScheme = "https"
DefaultScheme is the default URI scheme assumed by this service discovery infrastructure
Variables ¶
var ( // ErrIncomplete is returned by platform-specific code that creates environments // whenever the configuration is incomplete: it contains connection information // but no watches or registrations. ErrIncomplete = errors.New("No watches or registrations configured") )
Functions ¶
func FormatInstance ¶
FormatInstance creates an instance string from a (scheme, address, port) tuple. If the port is the default for the scheme, it is not included. If scheme is empty, DefaultScheme is used. If the port is nonpositive, then it is ignored.
func NewAccessorEndpoint ¶
NewAccessorEndpoint produces a go-kit Endpoint which delegates to an Accessor. The returned Endpoint expects a service Key as its request, and returns the instance string as the response.
func NewContextualInstancer ¶
NewContextualInstancer returns an sd.Instancer that has been enriched with metadata. This metadata allows infrastructure to carry configuration information about the instancer across API boundaries so that it can be logged or otherwise processed.
If m is empty, i is returned as is.
func NopCloser ¶
func NopCloser() error
NopCloser is a closer function that does nothing. It always returns a nil error. Useful for testing. Also used internally for the Environment's closer function in place of nil.
func NormalizeInstance ¶
NormalizeInstance canonicalizes an instance string from a service discovery backend, using an optional defaultScheme to be used if no scheme is found in the instance string. If defaultScheme is empty, DefaultScheme is assumed instead.
This function performs the following on the instance:
(1) If instance is a blank string, e.g. contains only whitespace or is empty, an empty string is returned with an error
(2) If the instance with whitespace trimmed off is not a valid instance, an error is returned with the trimmed instance string.
This function is intentionally lenient on what is a valid instance string, e.g. "foobar.com", "foobar.com:8080", "asdf://foobar.com", etc
(3) If there was no scheme prepended on the instance, either defaultScheme (if non-empty) or the global DefaultScheme is used instead
(4) Finally, FormatInstance is called with the parsed scheme, address, and port. Default ports for schemes will be omitted from the
final string.
Types ¶
type ContextualInstancer ¶
func (ContextualInstancer) Metadata ¶
func (ci ContextualInstancer) Metadata() map[string]interface{}
type Environment ¶
type Environment interface {
sd.Registrar
io.Closer
// IsRegistered tests if the given instance is registered in this environment. Useful for
// determining if an arbitrary instance refers to this process.
IsRegistered(string) bool
// DefaultScheme is the default URI scheme to assume for discovered service instances. This is
// typically driven by configuration.
DefaultScheme() string
// Instancers returns a copy of the internal set of Instancers this environment is configured to watch.
// Changing the returned Instancers will not result in changing this Environment's state.
Instancers() Instancers
// UpdateInstancers configures the set of sd.Instancer objects for use in the environment.
UpdateInstancers(currentKeys map[string]bool, instancersToAdd Instancers)
// AccessorFactory returns the creation strategy for Accessors used in this environment.
// Typically, this factory is set via configuration by some external source.
AccessorFactory() accessor.AccessorFactory
// Closed returns a channel that is closed when this Environment in closed.
Closed() <-chan struct{}
}
Environment represents everything known about a service discovery backend. It also provide a central handle for tasks related to service discovery, such as Accessor hashing.
func NewEnvironment ¶
func NewEnvironment(options ...Option) Environment
NewEnvironment constructs a new service discovery client environment. It is possible to construct an environment without any Registrars or Instancers, which essentially makes a no-op environment.
type Instancers ¶
Instancers is a collection of sd.Instancer objects, keyed by arbitrary strings.
func (Instancers) Copy ¶
func (is Instancers) Copy() Instancers
func (Instancers) Has ¶
func (is Instancers) Has(key string) bool
func (Instancers) Len ¶
func (is Instancers) Len() int
func (Instancers) Stop ¶
func (is Instancers) Stop()
type Key ¶
type Key interface {
// Bytes returns the raw byte slice contents of the key. This is what will be
// passed to Accessor.Get.
Bytes() []byte
}
Key represents a service key.
type KeyParser ¶
KeyParser is a parsing strategy that takes an arbitrary string and produces a service Key.
type MockEnvironment ¶
MockEnvironment is a stretchr/testify mocked Environment
func (*MockEnvironment) AccessorFactory ¶
func (m *MockEnvironment) AccessorFactory() accessor.AccessorFactory
func (*MockEnvironment) Close ¶
func (m *MockEnvironment) Close() error
func (*MockEnvironment) Closed ¶
func (m *MockEnvironment) Closed() <-chan struct{}
func (*MockEnvironment) DefaultScheme ¶
func (m *MockEnvironment) DefaultScheme() string
func (*MockEnvironment) Deregister ¶
func (m *MockEnvironment) Deregister()
func (*MockEnvironment) Instancers ¶
func (m *MockEnvironment) Instancers() Instancers
func (*MockEnvironment) IsRegistered ¶
func (m *MockEnvironment) IsRegistered(instance string) bool
func (*MockEnvironment) Register ¶
func (m *MockEnvironment) Register()
func (*MockEnvironment) UpdateInstancers ¶
func (m *MockEnvironment) UpdateInstancers(currentKeys map[string]bool, instancersToAdd Instancers)
type MockInstancer ¶
MockInstancer is a stretchr/testify mocked sd.Instancer
func (*MockInstancer) Deregister ¶
func (m *MockInstancer) Deregister(events chan<- sd.Event)
func (*MockInstancer) Register ¶
func (m *MockInstancer) Register(events chan<- sd.Event)
func (*MockInstancer) Stop ¶
func (m *MockInstancer) Stop()
type MockRegistrar ¶
MockRegistrar is a stretchr/testify mocked sd.Registrar
func (*MockRegistrar) Deregister ¶
func (m *MockRegistrar) Deregister()
func (*MockRegistrar) Register ¶
func (m *MockRegistrar) Register()
type Option ¶
type Option func(*environment)
Option represents a service discovery option for configuring an Environment
func WithAccessorFactory ¶
func WithAccessorFactory(af accessor.AccessorFactory) Option
WithAccessorFactory configures the creation strategy for Accessor objects. By default, DefaultAccessorFactory is used. Passing nil via this option sets (or resets) the environment back to using the DefaultAccessorFactory.
func WithCloser ¶
WithCloser configures the function used to completely shut down the service discover backend. By default, NopCloser is used. Passing a nil function for this option sets (or resets) the closer back to the NopCloser.
func WithDefaultScheme ¶
WithDefaultScheme configures the default URI scheme for discovered instances that do not specify a scheme. Some service discovery backends do not have a way to advertise a particular scheme that is revealed as part of the discovered instances.
func WithInstancers ¶
func WithInstancers(i Instancers) Option
WithInstancers configures the set of sd.Instancer objects for use in the environment. The Instancers may be nil or empty for applications which have no need of monitoring discovered services.
func WithProvider ¶
WithProvider configures the metrics provider for the environment
func WithRegistrars ¶
func WithRegistrars(r Registrars) Option
WithRegistrars configures the mapping of sd.Registrar objects to use for service advertisement.
type Registrars ¶
Registrars is a aggregate sd.Registrar that allows allows composite registration and deregistration. Keys in this map type will be service advertisements or instances, e.g. "host.com:8080" or "https://foobar.com"
func (Registrars) Deregister ¶
func (r Registrars) Deregister()
func (Registrars) Has ¶
func (r Registrars) Has(key string) bool
func (Registrars) Len ¶
func (r Registrars) Len() int
func (Registrars) Register ¶
func (r Registrars) Register()