services

package
v0.0.0-...-3b9dd47 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: Apache-2.0 Imports: 18 Imported by: 5 modules, 18 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advertisement interface {
	// the service being advertised.
	ServiceID() ServiceID

	// sets the service being advertised.
	SetServiceID(service ServiceID) Advertisement

	// optional health function, return an error to indicate unhealthy.
	Health() func() error

	// sets the health function for the advertised instance.
	SetHealth(health func() error) Advertisement

	// PlacementInstance returns the placement instance associated with this advertisement, which
	// contains the ID of the instance advertising and all other relevant fields.
	PlacementInstance() placement.Instance

	// SetPlacementInstance sets the Instance that is advertising.
	SetPlacementInstance(p placement.Instance) Advertisement
}

Advertisement advertises the availability of a given instance of a service.

func NewAdvertisement

func NewAdvertisement() Advertisement

NewAdvertisement creates a new Advertisement.

type CampaignOptions

type CampaignOptions interface {
	// LeaderValue allows the user to override the value a campaign announces
	// (that is, the value an observer sees upon calling Leader()). This
	// defaults to the hostname of the caller.
	LeaderValue() string
	SetLeaderValue(v string) CampaignOptions
}

CampaignOptions provide the ability to override campaign defaults.

func NewCampaignOptions

func NewCampaignOptions() (CampaignOptions, error)

NewCampaignOptions returns an empty CampaignOptions.

type Configuration

type Configuration struct {
	InitTimeout *time.Duration `yaml:"initTimeout"`
}

Configuration is the config for service options.

func (Configuration) NewOptions

func (cfg Configuration) NewOptions() Options

NewOptions creates an Option.

type ElectionConfiguration

type ElectionConfiguration struct {
	LeaderTimeout *time.Duration `yaml:"leaderTimeout"`
	ResignTimeout *time.Duration `yaml:"resignTimeout"`
	TTLSeconds    *int           `yaml:"TTLSeconds"`
}

ElectionConfiguration is for configuring election timeouts and TTLs

func (ElectionConfiguration) NewOptions

func (cfg ElectionConfiguration) NewOptions() ElectionOptions

NewOptions creates an ElectionOptions.

type ElectionOptions

type ElectionOptions interface {
	// Duration after which a call to Leader() will timeout if no response
	// returned from etcd. Defaults to 30 seconds.
	LeaderTimeout() time.Duration
	SetLeaderTimeout(t time.Duration) ElectionOptions

	// Duration after which a call to Resign() will timeout if no response
	// returned from etcd. Defaults to 30 seconds.
	ResignTimeout() time.Duration
	SetResignTimeout(t time.Duration) ElectionOptions

	// TTL returns the TTL used for campaigns. By default (ttl == 0), etcd will
	// set the TTL to 60s.
	TTLSecs() int
	SetTTLSecs(ttl int) ElectionOptions
}

ElectionOptions configure specific election-scoped options.

func NewElectionOptions

func NewElectionOptions() ElectionOptions

NewElectionOptions returns an empty ElectionOptions.

type HeartbeatGen

type HeartbeatGen func(sid ServiceID) (HeartbeatService, error)

HeartbeatGen generates a heartbeat store for a given zone.

type HeartbeatService

type HeartbeatService interface {
	// Heartbeat sends heartbeat for a service instance with a ttl.
	Heartbeat(instance placement.Instance, ttl time.Duration) error

	// Get gets healthy instances for a service.
	Get() ([]string, error)

	// GetInstances returns a deserialized list of healthy Instances.
	GetInstances() ([]placement.Instance, error)

	// Delete deletes the heartbeat for a service instance.
	Delete(instance string) error

	// Watch watches the heartbeats for a service.
	Watch() (xwatch.Watch, error)
}

HeartbeatService manages heartbeating instances.

type KVGen

type KVGen func(zone string) (kv.Store, error)

KVGen generates a kv store for a given zone.

type LeaderGen

type LeaderGen func(sid ServiceID, opts ElectionOptions) (LeaderService, error)

LeaderGen generates a leader service instance for a given service.

type LeaderService

type LeaderService interface {
	// Close closes the election service client entirely. No more campaigns can be
	// started and any outstanding campaigns are closed.
	Close() error

	// Campaign proposes that the caller become the leader for a specified
	// election, with its leadership being refreshed on an interval according to
	// the ElectionOptions the service was created with. It returns a read-only
	// channel of campaign status events that is closed when the user resigns
	// leadership or the campaign is invalidated due to background session
	// expiration (i.e. failing to refresh etcd leadership lease). The caller
	// MUST consume this channel until it is closed or risk goroutine leaks.
	// Users are encouraged to read the package docs of services/leader for
	// advice on proper usage and common gotchas.
	//
	// The leader will announce its hostname to observers unless opts is non-nil
	// and opts.LeaderValue() is non-empty.
	Campaign(electionID string, opts CampaignOptions) (<-chan campaign.Status, error)

	// Resign gives up leadership of a specified election if the caller is the
	// current leader (if the caller is not the leader an error is returned).
	Resign(electionID string) error

	// Leader returns the current leader of a specified election (if there is no
	// leader then leader.ErrNoLeader is returned).
	Leader(electionID string) (string, error)

	// Observe returns a channel on which leader updates for a specified election
	// will be returned. If no one is campaigning for the given election the call
	// will still succeed and the channel will receive its first update when an
	// election is started.
	Observe(electionID string) (<-chan string, error)
}

LeaderService provides access to etcd-backed leader elections.

type Metadata

type Metadata interface {
	// String returns a description of the metadata.
	String() string

	// Port returns the port to be used to contact the service.
	Port() uint32

	// SetPort sets the port.
	SetPort(p uint32) Metadata

	// LivenessInterval is the ttl interval for an instance to be considered as healthy.
	LivenessInterval() time.Duration

	// SetLivenessInterval sets the LivenessInterval.
	SetLivenessInterval(l time.Duration) Metadata

	// HeartbeatInterval is the interval for heatbeats.
	HeartbeatInterval() time.Duration

	// SetHeartbeatInterval sets the HeartbeatInterval.
	SetHeartbeatInterval(h time.Duration) Metadata

	// Proto returns the proto representation for the Metadata.
	Proto() (*metadatapb.Metadata, error)
}

Metadata contains the metadata for a service.

func NewMetadata

func NewMetadata() Metadata

NewMetadata creates new Metadata.

func NewMetadataFromProto

func NewMetadataFromProto(m *metadatapb.Metadata) (Metadata, error)

NewMetadataFromProto converts a Metadata proto message to an instance of Metadata.

type MockAdvertisement

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

Mock of Advertisement interface

func NewMockAdvertisement

func NewMockAdvertisement(ctrl *gomock.Controller) *MockAdvertisement

func (*MockAdvertisement) EXPECT

func (_m *MockAdvertisement) EXPECT() *_MockAdvertisementRecorder

func (*MockAdvertisement) Health

func (_m *MockAdvertisement) Health() func() error

func (*MockAdvertisement) PlacementInstance

func (_m *MockAdvertisement) PlacementInstance() placement.Instance

func (*MockAdvertisement) ServiceID

func (_m *MockAdvertisement) ServiceID() ServiceID

func (*MockAdvertisement) SetHealth

func (_m *MockAdvertisement) SetHealth(health func() error) Advertisement

func (*MockAdvertisement) SetPlacementInstance

func (_m *MockAdvertisement) SetPlacementInstance(p placement.Instance) Advertisement

func (*MockAdvertisement) SetServiceID

func (_m *MockAdvertisement) SetServiceID(service ServiceID) Advertisement

type MockCampaignOptions

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

Mock of CampaignOptions interface

func NewMockCampaignOptions

func NewMockCampaignOptions(ctrl *gomock.Controller) *MockCampaignOptions

func (*MockCampaignOptions) EXPECT

func (_m *MockCampaignOptions) EXPECT() *_MockCampaignOptionsRecorder

func (*MockCampaignOptions) LeaderValue

func (_m *MockCampaignOptions) LeaderValue() string

func (*MockCampaignOptions) SetLeaderValue

func (_m *MockCampaignOptions) SetLeaderValue(v string) CampaignOptions

type MockElectionOptions

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

Mock of ElectionOptions interface

func NewMockElectionOptions

func NewMockElectionOptions(ctrl *gomock.Controller) *MockElectionOptions

func (*MockElectionOptions) EXPECT

func (_m *MockElectionOptions) EXPECT() *_MockElectionOptionsRecorder

func (*MockElectionOptions) LeaderTimeout

func (_m *MockElectionOptions) LeaderTimeout() time.Duration

func (*MockElectionOptions) ResignTimeout

func (_m *MockElectionOptions) ResignTimeout() time.Duration

func (*MockElectionOptions) SetLeaderTimeout

func (_m *MockElectionOptions) SetLeaderTimeout(t time.Duration) ElectionOptions

func (*MockElectionOptions) SetResignTimeout

func (_m *MockElectionOptions) SetResignTimeout(t time.Duration) ElectionOptions

func (*MockElectionOptions) SetTTLSecs

func (_m *MockElectionOptions) SetTTLSecs(ttl int) ElectionOptions

func (*MockElectionOptions) TTLSecs

func (_m *MockElectionOptions) TTLSecs() int

type MockHeartbeatService

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

Mock of HeartbeatService interface

func NewMockHeartbeatService

func NewMockHeartbeatService(ctrl *gomock.Controller) *MockHeartbeatService

func (*MockHeartbeatService) Delete

func (_m *MockHeartbeatService) Delete(instance string) error

func (*MockHeartbeatService) EXPECT

func (_m *MockHeartbeatService) EXPECT() *_MockHeartbeatServiceRecorder

func (*MockHeartbeatService) Get

func (_m *MockHeartbeatService) Get() ([]string, error)

func (*MockHeartbeatService) GetInstances

func (_m *MockHeartbeatService) GetInstances() ([]placement.Instance, error)

func (*MockHeartbeatService) Heartbeat

func (_m *MockHeartbeatService) Heartbeat(instance placement.Instance, ttl time.Duration) error

func (*MockHeartbeatService) Watch

func (_m *MockHeartbeatService) Watch() (watch.Watch, error)

type MockLeaderService

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

Mock of LeaderService interface

func NewMockLeaderService

func NewMockLeaderService(ctrl *gomock.Controller) *MockLeaderService

func (*MockLeaderService) Campaign

func (_m *MockLeaderService) Campaign(electionID string, opts CampaignOptions) (<-chan campaign.Status, error)

func (*MockLeaderService) Close

func (_m *MockLeaderService) Close() error

func (*MockLeaderService) EXPECT

func (_m *MockLeaderService) EXPECT() *_MockLeaderServiceRecorder

func (*MockLeaderService) Leader

func (_m *MockLeaderService) Leader(electionID string) (string, error)

func (*MockLeaderService) Observe

func (_m *MockLeaderService) Observe(electionID string) (<-chan string, error)

func (*MockLeaderService) Resign

func (_m *MockLeaderService) Resign(electionID string) error

type MockMetadata

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

Mock of Metadata interface

func NewMockMetadata

func NewMockMetadata(ctrl *gomock.Controller) *MockMetadata

func (*MockMetadata) EXPECT

func (_m *MockMetadata) EXPECT() *_MockMetadataRecorder

func (*MockMetadata) HeartbeatInterval

func (_m *MockMetadata) HeartbeatInterval() time.Duration

func (*MockMetadata) LivenessInterval

func (_m *MockMetadata) LivenessInterval() time.Duration

func (*MockMetadata) Port

func (_m *MockMetadata) Port() uint32

func (*MockMetadata) Proto

func (_m *MockMetadata) Proto() (*metadatapb.Metadata, error)

func (*MockMetadata) SetHeartbeatInterval

func (_m *MockMetadata) SetHeartbeatInterval(h time.Duration) Metadata

func (*MockMetadata) SetLivenessInterval

func (_m *MockMetadata) SetLivenessInterval(l time.Duration) Metadata

func (*MockMetadata) SetPort

func (_m *MockMetadata) SetPort(p uint32) Metadata

func (*MockMetadata) String

func (_m *MockMetadata) String() string

type MockNamespaceOptions

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

Mock of NamespaceOptions interface

func NewMockNamespaceOptions

func NewMockNamespaceOptions(ctrl *gomock.Controller) *MockNamespaceOptions

func (*MockNamespaceOptions) EXPECT

func (_m *MockNamespaceOptions) EXPECT() *_MockNamespaceOptionsRecorder

func (*MockNamespaceOptions) MetadataNamespace

func (_m *MockNamespaceOptions) MetadataNamespace() string

func (*MockNamespaceOptions) PlacementNamespace

func (_m *MockNamespaceOptions) PlacementNamespace() string

func (*MockNamespaceOptions) SetMetadataNamespace

func (_m *MockNamespaceOptions) SetMetadataNamespace(v string) NamespaceOptions

func (*MockNamespaceOptions) SetPlacementNamespace

func (_m *MockNamespaceOptions) SetPlacementNamespace(v string) NamespaceOptions

type MockOptions

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

Mock of Options interface

func NewMockOptions

func NewMockOptions(ctrl *gomock.Controller) *MockOptions

func (*MockOptions) EXPECT

func (_m *MockOptions) EXPECT() *_MockOptionsRecorder

func (*MockOptions) HeartbeatGen

func (_m *MockOptions) HeartbeatGen() HeartbeatGen

func (*MockOptions) InitTimeout

func (_m *MockOptions) InitTimeout() time.Duration

func (*MockOptions) InstrumentsOptions

func (_m *MockOptions) InstrumentsOptions() instrument.Options

func (*MockOptions) KVGen

func (_m *MockOptions) KVGen() KVGen

func (*MockOptions) LeaderGen

func (_m *MockOptions) LeaderGen() LeaderGen

func (*MockOptions) NamespaceOptions

func (_m *MockOptions) NamespaceOptions() NamespaceOptions

func (*MockOptions) SetHeartbeatGen

func (_m *MockOptions) SetHeartbeatGen(gen HeartbeatGen) Options

func (*MockOptions) SetInitTimeout

func (_m *MockOptions) SetInitTimeout(t time.Duration) Options

func (*MockOptions) SetInstrumentsOptions

func (_m *MockOptions) SetInstrumentsOptions(iopts instrument.Options) Options

func (*MockOptions) SetKVGen

func (_m *MockOptions) SetKVGen(gen KVGen) Options

func (*MockOptions) SetLeaderGen

func (_m *MockOptions) SetLeaderGen(gen LeaderGen) Options

func (*MockOptions) SetNamespaceOptions

func (_m *MockOptions) SetNamespaceOptions(opts NamespaceOptions) Options

func (*MockOptions) Validate

func (_m *MockOptions) Validate() error

type MockOverrideOptions

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

Mock of OverrideOptions interface

func NewMockOverrideOptions

func NewMockOverrideOptions(ctrl *gomock.Controller) *MockOverrideOptions

func (*MockOverrideOptions) EXPECT

func (_m *MockOverrideOptions) EXPECT() *_MockOverrideOptionsRecorder

func (*MockOverrideOptions) NamespaceOptions

func (_m *MockOverrideOptions) NamespaceOptions() NamespaceOptions

func (*MockOverrideOptions) SetNamespaceOptions

func (_m *MockOverrideOptions) SetNamespaceOptions(opts NamespaceOptions) OverrideOptions

type MockQueryOptions

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

Mock of QueryOptions interface

func NewMockQueryOptions

func NewMockQueryOptions(ctrl *gomock.Controller) *MockQueryOptions

func (*MockQueryOptions) EXPECT

func (_m *MockQueryOptions) EXPECT() *_MockQueryOptionsRecorder

func (*MockQueryOptions) IncludeUnhealthy

func (_m *MockQueryOptions) IncludeUnhealthy() bool

func (*MockQueryOptions) SetIncludeUnhealthy

func (_m *MockQueryOptions) SetIncludeUnhealthy(h bool) QueryOptions

type MockService

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

Mock of Service interface

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

func (*MockService) EXPECT

func (_m *MockService) EXPECT() *_MockServiceRecorder

func (*MockService) Instance

func (_m *MockService) Instance(instanceID string) (ServiceInstance, error)

func (*MockService) Instances

func (_m *MockService) Instances() []ServiceInstance

func (*MockService) Replication

func (_m *MockService) Replication() ServiceReplication

func (*MockService) SetInstances

func (_m *MockService) SetInstances(insts []ServiceInstance) Service

func (*MockService) SetReplication

func (_m *MockService) SetReplication(r ServiceReplication) Service

func (*MockService) SetSharding

func (_m *MockService) SetSharding(s ServiceSharding) Service

func (*MockService) Sharding

func (_m *MockService) Sharding() ServiceSharding

type MockServiceID

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

Mock of ServiceID interface

func NewMockServiceID

func NewMockServiceID(ctrl *gomock.Controller) *MockServiceID

func (*MockServiceID) EXPECT

func (_m *MockServiceID) EXPECT() *_MockServiceIDRecorder

func (*MockServiceID) Environment

func (_m *MockServiceID) Environment() string

func (*MockServiceID) Equal

func (_m *MockServiceID) Equal(value ServiceID) bool

func (*MockServiceID) Name

func (_m *MockServiceID) Name() string

func (*MockServiceID) SetEnvironment

func (_m *MockServiceID) SetEnvironment(env string) ServiceID

func (*MockServiceID) SetName

func (_m *MockServiceID) SetName(s string) ServiceID

func (*MockServiceID) SetZone

func (_m *MockServiceID) SetZone(zone string) ServiceID

func (*MockServiceID) String

func (_m *MockServiceID) String() string

func (*MockServiceID) Zone

func (_m *MockServiceID) Zone() string

type MockServiceInstance

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

Mock of ServiceInstance interface

func NewMockServiceInstance

func NewMockServiceInstance(ctrl *gomock.Controller) *MockServiceInstance

func (*MockServiceInstance) EXPECT

func (_m *MockServiceInstance) EXPECT() *_MockServiceInstanceRecorder

func (*MockServiceInstance) Endpoint

func (_m *MockServiceInstance) Endpoint() string

func (*MockServiceInstance) InstanceID

func (_m *MockServiceInstance) InstanceID() string

func (*MockServiceInstance) ServiceID

func (_m *MockServiceInstance) ServiceID() ServiceID

func (*MockServiceInstance) SetEndpoint

func (_m *MockServiceInstance) SetEndpoint(e string) ServiceInstance

func (*MockServiceInstance) SetInstanceID

func (_m *MockServiceInstance) SetInstanceID(id string) ServiceInstance

func (*MockServiceInstance) SetServiceID

func (_m *MockServiceInstance) SetServiceID(service ServiceID) ServiceInstance

func (*MockServiceInstance) SetShards

func (*MockServiceInstance) Shards

func (_m *MockServiceInstance) Shards() shard.Shards

type MockServiceReplication

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

Mock of ServiceReplication interface

func NewMockServiceReplication

func NewMockServiceReplication(ctrl *gomock.Controller) *MockServiceReplication

func (*MockServiceReplication) EXPECT

func (_m *MockServiceReplication) EXPECT() *_MockServiceReplicationRecorder

func (*MockServiceReplication) Replicas

func (_m *MockServiceReplication) Replicas() int

func (*MockServiceReplication) SetReplicas

func (_m *MockServiceReplication) SetReplicas(r int) ServiceReplication

type MockServiceSharding

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

Mock of ServiceSharding interface

func NewMockServiceSharding

func NewMockServiceSharding(ctrl *gomock.Controller) *MockServiceSharding

func (*MockServiceSharding) EXPECT

func (_m *MockServiceSharding) EXPECT() *_MockServiceShardingRecorder

func (*MockServiceSharding) IsSharded

func (_m *MockServiceSharding) IsSharded() bool

func (*MockServiceSharding) NumShards

func (_m *MockServiceSharding) NumShards() int

func (*MockServiceSharding) SetIsSharded

func (_m *MockServiceSharding) SetIsSharded(s bool) ServiceSharding

func (*MockServiceSharding) SetNumShards

func (_m *MockServiceSharding) SetNumShards(n int) ServiceSharding

type MockServices

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

Mock of Services interface

func NewMockServices

func NewMockServices(ctrl *gomock.Controller) *MockServices

func (*MockServices) Advertise

func (_m *MockServices) Advertise(ad Advertisement) error

func (*MockServices) EXPECT

func (_m *MockServices) EXPECT() *_MockServicesRecorder

func (*MockServices) HeartbeatService

func (_m *MockServices) HeartbeatService(service ServiceID) (HeartbeatService, error)

func (*MockServices) LeaderService

func (_m *MockServices) LeaderService(service ServiceID, opts ElectionOptions) (LeaderService, error)

func (*MockServices) Metadata

func (_m *MockServices) Metadata(sid ServiceID) (Metadata, error)

func (*MockServices) PlacementService

func (_m *MockServices) PlacementService(sid ServiceID, popts placement.Options) (placement.Service, error)

func (*MockServices) Query

func (_m *MockServices) Query(service ServiceID, opts QueryOptions) (Service, error)

func (*MockServices) SetMetadata

func (_m *MockServices) SetMetadata(sid ServiceID, m Metadata) error

func (*MockServices) Unadvertise

func (_m *MockServices) Unadvertise(service ServiceID, id string) error

func (*MockServices) Watch

func (_m *MockServices) Watch(service ServiceID, opts QueryOptions) (Watch, error)

type MockWatch

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

Mock of Watch interface

func NewMockWatch

func NewMockWatch(ctrl *gomock.Controller) *MockWatch

func (*MockWatch) C

func (_m *MockWatch) C() <-chan struct{}

func (*MockWatch) Close

func (_m *MockWatch) Close()

func (*MockWatch) EXPECT

func (_m *MockWatch) EXPECT() *_MockWatchRecorder

func (*MockWatch) Get

func (_m *MockWatch) Get() Service

type NamespaceOptions

type NamespaceOptions interface {
	// PlacementNamespace is the custom namespace for placement.
	PlacementNamespace() string

	// SetPlacementNamespace sets the custom namespace for placement.
	SetPlacementNamespace(v string) NamespaceOptions

	// MetadataNamespace is the custom namespace for metadata.
	MetadataNamespace() string

	// SetMetadataNamespace sets the custom namespace for metadata.
	SetMetadataNamespace(v string) NamespaceOptions
}

NamespaceOptions are options to provide custom namespaces in service discovery service. TODO(cw): Provide overrides for leader service and heartbeat service.

func NewNamespaceOptions

func NewNamespaceOptions() NamespaceOptions

NewNamespaceOptions constructs a new NamespaceOptions.

type NamespacesConfiguration

type NamespacesConfiguration struct {
	Placement string `yaml:"placement"`
	Metadata  string `yaml:"metadata"`
}

NamespacesConfiguration configs the NamespaceOptions.

func (NamespacesConfiguration) NewOptions

func (cfg NamespacesConfiguration) NewOptions() NamespaceOptions

NewOptions creates a new NamespaceOptions.

type Options

type Options interface {
	// InitTimeout is the max time to wait on a new service watch for a valid initial value.
	// If the value is set to 0, then no wait will be done and the watch could return empty value.
	InitTimeout() time.Duration

	// SetInitTimeout sets the InitTimeout.
	SetInitTimeout(t time.Duration) Options

	// KVGen is the function to generate a kv store for a given zone.
	KVGen() KVGen

	// SetKVGen sets the KVGen.
	SetKVGen(gen KVGen) Options

	// HeartbeatGen is the function to generate a heartbeat store for a given zone.
	HeartbeatGen() HeartbeatGen

	// SetHeartbeatGen sets the HeartbeatGen.
	SetHeartbeatGen(gen HeartbeatGen) Options

	// LeaderGen is the function to generate a leader service instance for a
	// given service.
	LeaderGen() LeaderGen

	// SetLeaderGen sets the leader generation function.
	SetLeaderGen(gen LeaderGen) Options

	// InstrumentsOptions is the instrument options.
	InstrumentsOptions() instrument.Options

	// SetInstrumentsOptions sets the InstrumentsOptions.
	SetInstrumentsOptions(iopts instrument.Options) Options

	// NamespaceOptions is the custom namespaces.
	NamespaceOptions() NamespaceOptions

	// SetNamespaceOptions sets the NamespaceOptions.
	SetNamespaceOptions(opts NamespaceOptions) Options

	// Validate validates the Options.
	Validate() error
}

Options are options for the client of Services.

func NewOptions

func NewOptions() Options

NewOptions creates an Option

type OverrideConfiguration

type OverrideConfiguration struct {
	Namespaces NamespacesConfiguration `yaml:"namespaces"`
}

OverrideConfiguration configs the override options.

func (OverrideConfiguration) NewOptions

func (cfg OverrideConfiguration) NewOptions() OverrideOptions

NewOptions creates a new override options.

type OverrideOptions

type OverrideOptions interface {
	// NamespaceOptions is the namespace options.
	NamespaceOptions() NamespaceOptions

	// SetNamespaceOptions sets namespace options.
	SetNamespaceOptions(opts NamespaceOptions) OverrideOptions
}

OverrideOptions configs the override for service discovery.

func NewOverrideOptions

func NewOverrideOptions() OverrideOptions

NewOverrideOptions constructs a new OverrideOptions.

type QueryOptions

type QueryOptions interface {
	// IncludeUnhealthy decides whether unhealthy instances should be returned.
	IncludeUnhealthy() bool

	// SetIncludeUnhealthy sets the value of IncludeUnhealthy.
	SetIncludeUnhealthy(h bool) QueryOptions
}

QueryOptions are options to service discovery queries.

func NewQueryOptions

func NewQueryOptions() QueryOptions

NewQueryOptions creates new QueryOptions.

type Service

type Service interface {
	// Instance returns the service instance with the instance id.
	Instance(instanceID string) (ServiceInstance, error)

	// Instances returns the service instances.
	Instances() []ServiceInstance

	// SetInstances sets the service instances.
	SetInstances(insts []ServiceInstance) Service

	// Replication returns the service replication description or nil if none.
	Replication() ServiceReplication

	// SetReplication sets the service replication description or nil if none.
	SetReplication(r ServiceReplication) Service

	// Sharding returns the service sharding description or nil if none.
	Sharding() ServiceSharding

	// SetSharding sets the service sharding description or nil if none
	SetSharding(s ServiceSharding) Service
}

Service describes the metadata and instances of a service.

func NewService

func NewService() Service

NewService creates a new Service.

func NewServiceFromPlacement

func NewServiceFromPlacement(p placement.Placement, sid ServiceID) Service

NewServiceFromPlacement creates a Service from the placement and service ID.

func NewServiceFromProto

func NewServiceFromProto(
	p *placementpb.Placement,
	sid ServiceID,
) (Service, error)

NewServiceFromProto takes the data from a placement and a service id and returns the corresponding Service object.

type ServiceID

type ServiceID interface {
	// Name returns the service name of the ServiceID.
	Name() string

	// SetName sets the service name of the ServiceID.
	SetName(s string) ServiceID

	// Environment returns the environment of the ServiceID.
	Environment() string

	// SetEnvironment sets the environment of the ServiceID.
	SetEnvironment(env string) ServiceID

	// Zone returns the zone of the ServiceID.
	Zone() string

	// SetZone sets the zone of the ServiceID.
	SetZone(zone string) ServiceID

	// Equal retruns if the service IDs are equivalent.
	Equal(value ServiceID) bool

	// String returns a description of the ServiceID.
	String() string
}

ServiceID contains the fields required to id a service.

func NewServiceID

func NewServiceID() ServiceID

NewServiceID creates new ServiceID.

type ServiceIDConfiguration

type ServiceIDConfiguration struct {
	Name        string `yaml:"name"`
	Environment string `yaml:"environment"`
	Zone        string `yaml:"zone"`
}

ServiceIDConfiguration is for configuring serviceID.

func (ServiceIDConfiguration) NewServiceID

func (cfg ServiceIDConfiguration) NewServiceID() ServiceID

NewServiceID creates a ServiceID.

type ServiceInstance

type ServiceInstance interface {
	// ServiceID returns the service id of the instance.
	ServiceID() ServiceID

	// SetServiceID sets the service id of the instance.
	SetServiceID(service ServiceID) ServiceInstance

	// InstanceID returns the id of the instance.
	InstanceID() string

	// SetInstanceID sets the id of the instance.
	SetInstanceID(id string) ServiceInstance

	// Endpoint returns the endpoint of the instance.
	Endpoint() string

	// SetEndpoint sets the endpoint of the instance.
	SetEndpoint(e string) ServiceInstance

	// Shards returns the shards of the instance.
	Shards() shard.Shards

	// SetShards sets the shards of the instance.
	SetShards(s shard.Shards) ServiceInstance
}

ServiceInstance is a single instance of a service.

func NewServiceInstance

func NewServiceInstance() ServiceInstance

NewServiceInstance creates a new ServiceInstance.

func NewServiceInstanceFromPlacementInstance

func NewServiceInstanceFromPlacementInstance(
	instance placement.Instance,
	sid ServiceID,
) ServiceInstance

NewServiceInstanceFromPlacementInstance creates a new service instance from placement instance.

func NewServiceInstanceFromProto

func NewServiceInstanceFromProto(
	instance *placementpb.Instance,
	sid ServiceID,
) (ServiceInstance, error)

NewServiceInstanceFromProto creates a new service instance from proto.

type ServiceReplication

type ServiceReplication interface {
	// Replicas is the count of replicas.
	Replicas() int

	// SetReplicas sets the count of replicas.
	SetReplicas(r int) ServiceReplication
}

ServiceReplication describes the replication of a service.

func NewServiceReplication

func NewServiceReplication() ServiceReplication

NewServiceReplication creates a new ServiceReplication.

type ServiceSharding

type ServiceSharding interface {
	// NumShards is the number of shards to use for sharding.
	NumShards() int

	// SetNumShards sets the number of shards to use for sharding.
	SetNumShards(n int) ServiceSharding

	// IsSharded() returns whether this service is sharded.
	IsSharded() bool

	// SetIsSharded sets IsSharded.
	SetIsSharded(s bool) ServiceSharding
}

ServiceSharding describes the sharding of a service.

func NewServiceSharding

func NewServiceSharding() ServiceSharding

NewServiceSharding creates a new ServiceSharding.

type Services

type Services interface {
	// Advertise advertises the availability of an instance of a service.
	Advertise(ad Advertisement) error

	// Unadvertise indicates a given instance is no longer available.
	Unadvertise(service ServiceID, id string) error

	// Query returns the topology for a given service.
	Query(service ServiceID, opts QueryOptions) (Service, error)

	// Watch returns a watch on metadata and a list of available instances for a given service.
	Watch(service ServiceID, opts QueryOptions) (Watch, error)

	// Metadata returns the metadata for a given service.
	Metadata(sid ServiceID) (Metadata, error)

	// SetMetadata sets the metadata for a given service.
	SetMetadata(sid ServiceID, m Metadata) error

	// PlacementService returns a client of placement.Service.
	PlacementService(sid ServiceID, popts placement.Options) (placement.Service, error)

	// HeartbeatService returns a heartbeat store for the given service.
	HeartbeatService(service ServiceID) (HeartbeatService, error)

	// LeaderService returns an instance of a leader service for the given
	// service ID.
	LeaderService(service ServiceID, opts ElectionOptions) (LeaderService, error)
}

Services provides access to the service topology.

func NewServices

func NewServices(opts Options) (Services, error)

NewServices returns a client of Services.

type Watch

type Watch interface {
	// Close closes the watch.
	Close()

	// C returns the notification channel.
	C() <-chan struct{}

	// Get returns the latest service of the service watchable.
	Get() Service
}

Watch is a watcher that issues notification when a service is updated.

func NewWatch

func NewWatch(w watch.Watch) Watch

NewWatch creates a Watch.

Directories

Path Synopsis
heartbeat
Package leader provides functionality for etcd-backed leader elections.
Package leader provides functionality for etcd-backed leader elections.
campaign
Package campaign encapsulates the state of a campaign.
Package campaign encapsulates the state of a campaign.
election
Package election provides a wrapper around a subset of the Election functionality of etcd's concurrency package with error handling for common failure scenarios such as lease expiration.
Package election provides a wrapper around a subset of the Election functionality of etcd's concurrency package with error handling for common failure scenarios such as lease expiration.

Jump to

Keyboard shortcuts

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