viewreg

package
v0.0.0-...-6719cd2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package viewreg tracks all the known view servers in the cluster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature uint8

A Feature represents a gRPC service that a server may provide.

const (
	DiagnosticsFeature Feature = (1 << 0) // rpc.Diagnostics service
	CarouselFeature    Feature = (1 << 1) // rpc.Carousel service
	HashPOFeature      Feature = (1 << 2) // rpc.ReadFactsPO service
	HashSPFeature      Feature = (1 << 3) // rpc.ReadFactsSP service
)

Each of these symbols corresponds to one gRPC service. Use the Provides() method on a View to determine if the View is providing the service. The values here are intended for this package's internal use.

Note: Features that a server supports may not be "provided" if the Registry has not confirmed that server as healthy.

func (Feature) String

func (f Feature) String() string

String returns human-readable strings like "Diagnostics".

type Registry

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

A Registry tracks all the known view servers in the cluster. It is intended to be a long-lived object, as it manages connections to those servers.

func NewRegistry

func NewRegistry(ctx context.Context, servers discovery.Locator) *Registry

NewRegistry constructs a Registry. The registry will shut down all its connections and activity when 'ctx' is closed. It discovers the gRPC port for all view servers from 'servers'.

Warning: it takes some time for a Registry to discover view servers and determine them to be healthy. As a result, it's a bad idea to create a Registry and immediately rely on it to make irreversible decisions. Callers may want to use LastChanged(), WaitForStable(), or WaitForChanged() to wait until the Registry is ready.

func (*Registry) AllViews

func (registry *Registry) AllViews() []View

AllViews returns all of the known views, even those believed to be unhealthy. The views are returned in no particular order. The caller is free to modify the returned slice and its values.

func (*Registry) Dump

func (registry *Registry) Dump(b bytes.StringWriter)

Dump writes detailed information about all the views to 'b'.

func (*Registry) HealthyViews

func (registry *Registry) HealthyViews(feature ...Feature) []View

HealthyViews returns the set of views that are believed healthy and provide all of the given features. The views are returned in no particular order. The caller is free to modify the returned slice and its values.

TODO: Carousel clients often want to exclude talking to themselves. Should this module try to filter out localhost?

func (*Registry) LastChanged

func (registry *Registry) LastChanged() time.Time

LastChanged returns the latest timestamp when any View was added, removed, or updated. Callers can use this to predict whether the Registry is likely to change in the near future. Two versions of the Registry are guaranteed to have distinct timestamps.

func (*Registry) Summary

func (registry *Registry) Summary() logrus.Fields

Summary returns some information about the registry for use in debug log messages about the Registry.

func (*Registry) WaitForChange

func (registry *Registry) WaitForChange(ctx context.Context, lastChanged time.Time) error

WaitForChange blocks until Registry.LastChanged() is after 'lastChanged'. This can be used to wait until the Registry satisfies some condition. It returns nil if successful, or ctx.Err() if the given Context expires first.

func (*Registry) WaitForStable

func (registry *Registry) WaitForStable(ctx context.Context, d time.Duration) error

WaitForStable blocks until the registry hasn't changed for at least duration 'd'. This can be used to predict that the Registry is unlikely to change in the near future. It returns nil if the registry hasn't changed for 'd', or ctx.Err() if the given Context expires first.

type View

type View struct {
	// The location of the server's gRPC port. This is a shared value; callers
	// must not modify it.
	Endpoint *discovery.Endpoint
	// If the server hosts a partition, this identifies its space and range.
	// Otherwise, this is nil. This is guaranteed to be non-nil if the view
	// provides any of CarouselFeature, HashPOFeature, or HashSPFeature.
	Partition partitioning.FactPartition
	// contains filtered or unexported fields
}

A View represents a single remote Akutan server.

func (*View) Carousel

func (view *View) Carousel() rpc.CarouselClient

Carousel returns a stub to invoke Carousel RPCs. If the View is not known to provide the CarouselFeature, the RPCs invoked through this stub are likely to fail. This method is cheap to call frequently.

func (*View) Diagnostics

func (view *View) Diagnostics() rpc.DiagnosticsClient

Diagnostics returns a stub to invoke Diagnostics RPCs. If the View is not known to provide the DiagnosticsFeature, the RPCs invoked through this stub are likely to fail. This method is cheap to call frequently.

func (*View) HashPO

func (view *View) HashPO() rpc.ReadFactsPOClient

HashPO returns a stub to invoke ReadFactsPO RPCs. If the View is not known to provide the HashPOFeature, the RPCs invoked through this stub are likely to fail. This method is cheap to call frequently.

func (*View) HashSP

func (view *View) HashSP() rpc.ReadFactsSPClient

HashSP returns a stub to invoke ReadFactsSP RPCs. If the View is not known to provide the HashSPFeature, the RPCs invoked through this stub are likely to fail. This method is cheap to call frequently.

func (*View) Healthy

func (view *View) Healthy() bool

Healthy returns true if the server had a high likelihood of being reachable at the time the View was created, false otherwise.

func (*View) Provides

func (view *View) Provides(features ...Feature) bool

Provides returns true if the server is known to have all of the given features, false otherwise.

func (*View) SetFeaturesForTesting

func (view *View) SetFeaturesForTesting(features ...Feature)

SetFeaturesForTesting sets the View's provided features to those given. It is intended for unit testing only.

func (View) String

func (view View) String() string

String returns a short description of the view's address and services.

Note: This intentionally takes a non-pointer receiver so that fmt.Sprint(View{...}) calls this.

Jump to

Keyboard shortcuts

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