discovery

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TAG_INSTANCE_ID          = "instanceUuid"
	TAG_MANAGED_SERVICE      = "managedMicroservice"
	TAG_COMPONENT_ATTRIBUTES = "componentAttributes"
	TAG_SERVICE_NAME         = "name"
	TAG_VERSION              = "version"
	TAG_BUILD_NUMBER         = "buildNumber"
	TAG_BUILD_DATE_TIME      = "buildDateTime"

	COMPONENT_ATTRIBUTE_DELIMITER = "~"
	KEY_VALUE_SEPARATOR           = ":"
)
View Source
const (
	InstanceMetaKeyVersion     = "version"
	InstanceMetaKeyContextPath = "context"
	InstanceMetaKeySMCR        = "SMCR"
	InstanceMetaKeySecure      = "secure"
)
View Source
const (
	DiscoveryPropertiesPrefix = "cloud.consul.discovery"
)

Variables

View Source
var COMPONENT_ATTRIBUTES_MAPPING = map[string]string{
	"serviceName": "application.name",
	"context":     "server.context-path",
	"name":        "info.app.attributes.displayName",
	"description": "info.app.description",
	"parent":      "info.app.attributes.parent",
	"type":        "info.app.attributes.type",
}
View Source
var (
	ErrInstancerStopped = fmt.Errorf("instancer is already stopped")
)

Functions

func Deregister

func Deregister(ctx context.Context, connection *consul.Connection, registration *api.AgentServiceRegistration) error

func NewRegistration

func NewRegistration(opts ...RegistrationOptions) *api.AgentServiceRegistration

func Register

func Register(ctx context.Context, connection *consul.Connection, registration *api.AgentServiceRegistration) error

Types

type Callback

type Callback func(Instancer)

type Client

type Client interface {
	Context() context.Context
	Instancer(serviceName string) (Instancer, error)
}

func NewConsulDiscoveryClient

func NewConsulDiscoveryClient(ctx context.Context, conn *consul.Connection, opts ...ClientOptions) Client

type ClientConfig

type ClientConfig struct {
	Logger          log.Logger
	Verbose         bool
	DefaultSelector InstanceMatcher
}

type ClientOptions

type ClientOptions func(opt *ClientConfig)

type ConsulInstancer

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

ConsulInstancer implements sd.Instancer and Instancer. It yields service for a serviceName in Consul. Note: implementing sd.Instancer is for compatibility reason, using it involves addtional Lock locking.

Try use Instancer's callback capability instead

func NewConsulInstancer

func NewConsulInstancer(ctx context.Context, opts ...ConsulInstancerOptions) *ConsulInstancer

NewConsulInstancer returns a customized Consul instancer that publishes service for the requested serviceName. It only returns service for which the passed tags are present.

func (*ConsulInstancer) Deregister

func (i *ConsulInstancer) Deregister(ch chan<- sd.Event)

Deregister implements sd.Instancer.

func (*ConsulInstancer) DeregisterCallback

func (i *ConsulInstancer) DeregisterCallback(id interface{})

func (*ConsulInstancer) Instances

func (i *ConsulInstancer) Instances(matcher InstanceMatcher) (ret []*Instance, err error)

Instances implements Instancer

func (*ConsulInstancer) Register

func (i *ConsulInstancer) Register(ch chan<- sd.Event)

Register implements sd.Instancer.

func (*ConsulInstancer) RegisterCallback

func (i *ConsulInstancer) RegisterCallback(id interface{}, cb Callback)

func (*ConsulInstancer) Service

func (i *ConsulInstancer) Service() (svc *Service)

Service implements Instancer

func (*ConsulInstancer) ServiceName

func (i *ConsulInstancer) ServiceName() string

ServiceName implements Instancer

func (*ConsulInstancer) Start

func (i *ConsulInstancer) Start(ctx context.Context)

func (*ConsulInstancer) Stop

func (i *ConsulInstancer) Stop()

Stop implements sd.Instancer and Instancer.

type ConsulInstancerOption

type ConsulInstancerOption struct {
	ServiceName      string
	ConsulConnection *consul.Connection
	Logger           log.Logger
	Selector         InstanceMatcher
	Verbose          bool
}

type ConsulInstancerOptions

type ConsulInstancerOptions func(opt *ConsulInstancerOption)

type Customizer

type Customizer interface {
	Customize(ctx context.Context, reg *api.AgentServiceRegistration)
}

type CustomizerFunc

type CustomizerFunc func(ctx context.Context, reg *api.AgentServiceRegistration)

func (CustomizerFunc) Customize

func (fn CustomizerFunc) Customize(ctx context.Context, reg *api.AgentServiceRegistration)

type Customizers

type Customizers struct {
	Customizers []Customizer
	// contains filtered or unexported fields
}

func NewCustomizers

func NewCustomizers(ctx *bootstrap.ApplicationContext) *Customizers

func (*Customizers) Add

func (r *Customizers) Add(c Customizer)

func (*Customizers) Apply

func (r *Customizers) Apply(ctx context.Context, registration *api.AgentServiceRegistration)

type DefaultCustomizer

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

func NewDefaultCustomizer

func NewDefaultCustomizer(appContext *bootstrap.ApplicationContext) *DefaultCustomizer

func (*DefaultCustomizer) Customize

func (d *DefaultCustomizer) Customize(ctx context.Context, registration *api.AgentServiceRegistration)

type DiscoveryProperties

type DiscoveryProperties struct {
	HealthCheckPath            string                    `json:"health-check-path"`
	HealthCheckInterval        string                    `json:"health-check-interval"`
	Tags                       utils.CommaSeparatedSlice `json:"tags"`
	AclToken                   string                    `json:"acl-token"`
	IpAddress                  string                    `json:"ip-address"` //A pre-defined IP address
	Interface                  string                    `json:"interface"`  //The network interface from where to get the ip address. If IpAddress is defined, this field is ignored
	Port                       int                       `json:"port"`
	Scheme                     string                    `json:"scheme"`
	HealthCheckCriticalTimeout string                    `json:"health-check-critical-timeout"` //See api.AgentServiceCheck's DeregisterCriticalServiceAfter field
	DefaultSelector            SelectorProperties        `json:"default-selector"`              // Default tags or meta to use when discovering other services
}

func NewDiscoveryProperties

func NewDiscoveryProperties() *DiscoveryProperties

type HealthStatus

type HealthStatus int

HealthStatus maintenance > critical > warning > passing

const (
	HealthAny HealthStatus = iota
	HealthPassing
	HealthWarning
	HealthCritical
	HealthMaintenance
)

type Instance

type Instance struct {
	ID       string
	Service  string
	Address  string
	Port     int
	Tags     []string
	Meta     map[string]string
	Health   HealthStatus
	RawEntry interface{}
}

type InstanceMatcher

type InstanceMatcher matcher.ChainableMatcher

InstanceMatcher is a matcher.Matcher that takes Instance or *Instance

func InstanceIsHealthy

func InstanceIsHealthy() InstanceMatcher

InstanceIsHealthy returns an InstanceMatcher that matches healthy instances

func InstanceWithHealth

func InstanceWithHealth(status HealthStatus) InstanceMatcher

func InstanceWithMetaKV

func InstanceWithMetaKV(key, value string) InstanceMatcher

func InstanceWithProperties

func InstanceWithProperties(props *SelectorProperties) InstanceMatcher

InstanceWithProperties returns an InstanceMatcher that matches instances described in given selector properties could return nil

func InstanceWithTag

func InstanceWithTag(tag string, caseInsensitive bool) InstanceMatcher

func InstanceWithTagKV

func InstanceWithTagKV(key, value string, caseInsensitive bool) InstanceMatcher

func InstanceWithVersion

func InstanceWithVersion(verPattern string) InstanceMatcher

type Instancer

type Instancer interface {
	ServiceName() string
	Service() *Service
	Instances(InstanceMatcher) ([]*Instance, error)
	Start(ctx context.Context)
	Stop()
	RegisterCallback(id interface{}, cb Callback)
	DeregisterCallback(id interface{})
}

type RegistrationConfig

type RegistrationConfig struct {
	ApplicationName            string
	IPAddress                  string
	NetworkInterface           string
	Port                       int
	Tags                       []string
	HealthCheckPath            string
	HealthPort                 int
	HealthScheme               string
	HealthCheckInterval        string
	HealthCheckCriticalTimeout string
}

type RegistrationOptions

type RegistrationOptions func(cfg *RegistrationConfig)

type SelectorProperties

type SelectorProperties struct {
	Tags utils.CommaSeparatedSlice `json:"tags"`
	Meta map[string]string         `json:"meta"`
}

type Service

type Service struct {
	Name       string
	Insts      []*Instance
	Time       time.Time
	Err        error
	FirstErrAt time.Time
}

func (*Service) InstanceCount

func (s *Service) InstanceCount(selector InstanceMatcher) (ret int)

func (*Service) Instances

func (s *Service) Instances(selector InstanceMatcher) (ret []*Instance)

type ServiceCache

type ServiceCache interface {
	// Get returns service with given service name. return nil if not exist
	Get(name string) *Service
	// Set stores given service with name, returns non-nil if the service is already exists
	Set(name string, svc *Service) *Service
	// SetWithTTL stores given service with name and TTL, returns non-nil if the service is already exists
	// if ttl is zero or negative value, it's equivalent to Set
	SetWithTTL(name string, svc *Service, ttl time.Duration) *Service
	Has(name string) bool
	Entries() map[string]*Service
}

ServiceCache is not goroutine-safe unless the detail implementation says so

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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