discovery

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagInstanceUUID        = `instanceUuid`
	TagContextPath         = `contextPath`
	TagComponentAttributes = `componentAttributes`
	TagServiceName         = `name`
	TagBuildVersion        = `version`
	TagBuildNumber         = `buildNumber`
	TagBuildDateTime       = `buildDateTime`
	TagSecure              = `secure`

	ComponentAttributeDelimiter         = `~`
	ComponentAttributeKeyValueSeparator = `:`
)
View Source
const (
	InstanceMetaKeyVersion     = `version`
	InstanceMetaKeyContextPath = `context`
	InstanceMetaKeySMCR        = `SMCR`
)
View Source
const (
	FxGroup = "discovery"
)

Variables

View Source
var (
	ErrInstancerStopped = fmt.Errorf("instancer is already stopped")
)

Functions

This section is empty.

Types

type Callback

type Callback func(Instancer)

type Client

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

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 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 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

type ServiceRegistrar added in v0.14.0

type ServiceRegistrar interface {
	Register(ctx context.Context, registration ServiceRegistration) error
	Deregister(ctx context.Context, registration ServiceRegistration) error
}

ServiceRegistrar is the interface to interact with external service registration system.

type ServiceRegistration added in v0.14.0

type ServiceRegistration interface {
	ID() string
	Name() string
	Address() string
	Port() int
	Tags() []string
	Meta() map[string]any

	SetID(id string)
	SetName(name string)
	SetAddress(addr string)
	SetPort(port int)
	AddTags(tags ...string)
	RemoveTags(tags ...string)
	SetMeta(key string, value any)
}

ServiceRegistration is the data to be registered with any external service registration system. It contains information about current running service instance. The implementation depends on which service discovery tech-stack is used. e.g. Consul would be *consulsd.ServiceRegistration

type ServiceRegistrationCustomizer added in v0.14.0

type ServiceRegistrationCustomizer interface {
	Customize(ctx context.Context, reg ServiceRegistration)
}

ServiceRegistrationCustomizer customize given ServiceRegistration during bootstrap. Any ServiceRegistrationCustomizer provided with fx group defined as FxGroup will be applied automatically.

func NewBuildInfoCustomizer added in v0.14.0

func NewBuildInfoCustomizer() ServiceRegistrationCustomizer

NewBuildInfoCustomizer returns a ServiceRegistrationCustomizer that extract service's build information and put it in tags and metadata

func NewPropertiesBasedCustomizer added in v0.14.0

func NewPropertiesBasedCustomizer(appCtx *bootstrap.ApplicationContext, propertyPaths map[string]string) ServiceRegistrationCustomizer

NewPropertiesBasedCustomizer returns a ServiceRegistrationCustomizer that populate tags and metadata based on service's loaded properties and the given "propertyPaths". "propertyPaths" is a map that contains metadata key as "key" and its corresponding property path.

type ServiceRegistrationCustomizerFunc added in v0.14.0

type ServiceRegistrationCustomizerFunc func(ctx context.Context, reg ServiceRegistration)

ServiceRegistrationCustomizerFunc is the func that implements ServiceRegistrationCustomizer

func (ServiceRegistrationCustomizerFunc) Customize added in v0.14.0

Directories

Path Synopsis
Package sd, provide base implementation of discovery.Client and discovery.Instancer.
Package sd, provide base implementation of discovery.Client and discovery.Instancer.

Jump to

Keyboard shortcuts

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