registry

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 19 Imported by: 32

Documentation

Overview

Copyright 2020 The Magma Authors.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package registry provides Registry interface for Go based gateways as well as cloud connection routines

Package registry for Magma microservices

Package registry for Magma microservices

Copyright 2020 The Magma Authors.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package registry provides Registry interface for Go based gateways as well as cloud connection routines

Index

Constants

View Source
const (
	GrpcMaxDelaySec        = 10
	GrpcMaxLocalTimeoutSec = 30
	GrpcMaxTimeoutSec      = 60
)
View Source
const (
	ControlProxyServiceName = "CONTROL_PROXY"
)
View Source
const DefaultSharedCloudConnectionTTL = time.Hour * 4

DefaultSharedCloudConnectionTTL - default duration to reuse the same connection

Variables

This section is empty.

Functions

func AddService

func AddService(location ServiceLocation)

AddService add a new service to global registry. If the service already exists, overwrites the service config.

func AddServices

func AddServices(locations ...ServiceLocation)

AddServices adds new services to the global registry. If any services already exist, their locations will be overwritten

func FindServices

func FindServices(label string) []string

FindServices returns the names of all registered services that have the passed label.

func GetAnnotation

func GetAnnotation(service, annotationName string) (string, error)

GetAnnotation returns the annotation value for the passed annotation name. The service needs to be added to the registry before this.

func GetAnnotationList

func GetAnnotationList(service, annotationName string) ([]string, error)

GetAnnotationList returns the comma-split fields of the value for the passed annotation name. The service needs to be added to the registry before this.

func GetClientConnection

func GetClientConnection(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

GetClientConnection provides a gRPC connection to a service on the address addr.

func GetConnection

func GetConnection(service string) (*grpc.ClientConn, error)

GetConnection provides a gRPC connection to a service in the registry.

func GetConnectionImpl

func GetConnectionImpl(ctx context.Context, service string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func GetEchoServerPort

func GetEchoServerPort(service string) (int, error)

GetEchoServerPort returns the listening port for the service's echo server. The service needs to be added to the registry before this.

func GetServiceAddress

func GetServiceAddress(service string) (string, error)

GetServiceAddress returns the RPC address of the service from global registry The service needs to be added to the registry before this.

func GetServicePort

func GetServicePort(service string) (int, error)

GetServicePort returns the listening port for the RPC service. The service needs to be added to the registry before this.

func GetServiceProxyAliases

func GetServiceProxyAliases(service string) (map[string]int, error)

GetServiceProxyAliases returns the proxy_aliases, if any, of the service from global registry The service needs to be added to the registry before this.

func GetSharedCloudConnectionTTL

func GetSharedCloudConnectionTTL() time.Duration

GetSharedCloudConnectionTTL atomically gets and returns current Shared Cloud Connection TTL value

func ListAllServices

func ListAllServices() []string

ListAllServices lists all services' names from global registry

func ListControllerServices

func ListControllerServices() []string

ListControllerServices list all services that should run on a controller instances This is a comma separated list in an env var named CONTROLLER_SERVICES. This will be used for metricsd on controller to determine what services to pull metrics from.

func MustPopulateServices

func MustPopulateServices()

MustPopulateServices is same as PopulateServices but fails on errors.

func PopulateServices

func PopulateServices() error

PopulateServices populates the service registry based on the per-module config files at /etc/magma/configs/MODULE_NAME/service_registry.yml.

func RemoveService

func RemoveService(service string)

RemoveService removes a service from the registry. Has no effect if the service does not exist.

func RemoveServicesWithLabel

func RemoveServicesWithLabel(label string)

RemoveServicesWithLabel removes all services from the registry which have the passed label.

func SetSharedCloudConnectionTTL

func SetSharedCloudConnectionTTL(ttl time.Duration)

SetSharedCloudConnectionTTL atomically sets Shared Cloud Connection TTL Note: the new TTL will apply only to newly created connections, existing cached connections will not be affected

Types

type ServiceLocation

type ServiceLocation struct {
	// Name of the service.
	Name string
	// Host name of the service.
	Host string
	// Port is the service's gRPC endpoint.
	Port int
	// EchoPort is the service's HTTP endpoint for providing obsidian handlers.
	EchoPort int
	// ProxyAliases provides the list of host:port aliases for the service.
	ProxyAliases map[string]int

	// Labels provide a way to identify the service.
	// Use cases include listing service mesh servicers the service implements.
	Labels map[string]string
	// Annotations provides a string-to-string map of per-service metadata.
	Annotations map[string]string
}

ServiceLocation is an entry for the service registry which identifies a service by name and the host:port that it is running on.

func LoadServiceRegistryConfig

func LoadServiceRegistryConfig(moduleName string) ([]ServiceLocation, error)

LoadServiceRegistryConfig reads service registry config file from /etc/magma/configs/{moduleName} or override config.

func LoadServiceRegistryConfigs

func LoadServiceRegistryConfigs() ([]ServiceLocation, error)

LoadServiceRegistryConfigs reads service registry config file from all modules under /etc/magma/configs/. Also, prefers override configs on a per-module basis.

func (ServiceLocation) HasLabel

func (s ServiceLocation) HasLabel(label string) bool

func (ServiceLocation) String

func (s ServiceLocation) String() string

String implements ServiceLocation stringer interface Returns string in the form: <service name> @ host:port (also known as: host:port, ...)

type ServiceRegistry

type ServiceRegistry struct {
	sync.RWMutex
	ServiceConnections map[string]*grpc.ClientConn
	ServiceLocations   map[string]ServiceLocation
	// contains filtered or unexported fields
}

func Get

func Get() *ServiceRegistry

Get returns a reference to the instance of global platform registry

func New

func New() *ServiceRegistry

New creates and returns a new registry

func (*ServiceRegistry) AddService

func (r *ServiceRegistry) AddService(location ServiceLocation)

AddService add a new service. If the service already exists, overwrites the service config.

func (*ServiceRegistry) AddServices

func (r *ServiceRegistry) AddServices(locations ...ServiceLocation)

AddServices adds new services to the registry. If any services already exist, their locations will be overwritten

func (*ServiceRegistry) CleanupSharedCloudConnection

func (r *ServiceRegistry) CleanupSharedCloudConnection(service string) bool

CleanupSharedCloudConnection removes cached cloud connection for the service from cache and closes it Returns true if connection was cached

func (*ServiceRegistry) FindServices

func (r *ServiceRegistry) FindServices(label string) []string

FindServices returns the names of all registered services that have the passed label.

func (*ServiceRegistry) GetAnnotation

func (r *ServiceRegistry) GetAnnotation(service, annotationName string) (string, error)

GetAnnotation returns the annotation value for the passed annotation name.

func (*ServiceRegistry) GetAnnotationList

func (r *ServiceRegistry) GetAnnotationList(service, annotationName string) ([]string, error)

GetAnnotationList returns the comma-split fields of the value for the passed annotation name. First splits by field separator, then strips all whitespace (including newlines). Empty fields are removed.

func (*ServiceRegistry) GetCloudConnection

func (r *ServiceRegistry) GetCloudConnection(service string) (*grpc.ClientConn, error)

GetCloudConnection Creates and returns a new GRPC service connection to the service in the cloud for a gateway either directly or via control proxy Input: service - name of cloud service to connect to

Output: *grpc.ClientConn with connection to cloud service

error if it exists

func (*ServiceRegistry) GetCloudConnectionFromServiceConfig

func (r *ServiceRegistry) GetCloudConnectionFromServiceConfig(
	controlProxyConfig *config.ConfigMap, service string) (*grpc.ClientConn, error)

GetCloudConnectionFromServiceConfig returns a connection to the cloud using a specific control_proxy service config map. This map must contain the cloud_address and local_port params Input: serviceConfig - ConfigMap containing cloud_address and local_port

and optional proxy_cloud_connections, cloud_port, rootca_cert, gateway_cert/key fields if direct
cloud connection is needed
service - name of cloud service to connect to

Output: *grpc.ClientConn with connection to cloud service

error if it exists

func (*ServiceRegistry) GetConnection

func (r *ServiceRegistry) GetConnection(service string) (*grpc.ClientConn, error)

GetConnection provides a gRPC connection to a service in the registry. The service needs to be added to the registry before this.

func (*ServiceRegistry) GetConnectionImpl

func (r *ServiceRegistry) GetConnectionImpl(ctx context.Context, service string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func (*ServiceRegistry) GetEchoServerPort

func (r *ServiceRegistry) GetEchoServerPort(service string) (int, error)

GetEchoServerPort returns the listening port for the service's echo server. The service needs to be added to the registry before this.

func (*ServiceRegistry) GetServiceAddress

func (r *ServiceRegistry) GetServiceAddress(service string) (string, error)

GetServiceAddress returns the RPC address of the service. The service needs to be added to the registry before this.

func (*ServiceRegistry) GetServicePort

func (r *ServiceRegistry) GetServicePort(service string) (int, error)

GetServicePort returns the listening port for the RPC service. The service needs to be added to the registry before this.

func (*ServiceRegistry) GetServiceProxyAliases

func (r *ServiceRegistry) GetServiceProxyAliases(service string) (map[string]int, error)

GetServiceProxyAliases returns the proxy_aliases, if any, of the service. The service needs to be added to the registry before this.

func (*ServiceRegistry) GetSharedCloudConnection

func (r *ServiceRegistry) GetSharedCloudConnection(service string) (*grpc.ClientConn, error)

GetSharedCloudConnection returns a new GRPC service connection to the service in the cloud for a gateway either directly or via control proxy GetSharedCloudConnection will return an existing cached cloud connection if it's available and healthy, if not - it'll try to create, cache and return a new cloud connection Input: service - name of cloud service to connect to

Output: *grpc.ClientConn with connection to cloud service

error if it exists

func (*ServiceRegistry) GetSharedCloudConnectionFromServiceConfig

func (r *ServiceRegistry) GetSharedCloudConnectionFromServiceConfig(
	controlProxyConfig *config.ConfigMap, service string) (*grpc.ClientConn, error)

GetSharedCloudConnectionFromServiceConfig returns a connection to the cloud using a specific control_proxy service config map. This map must contain the cloud_address and local_port params GetSharedCloudConnectionFromServiceConfig will return an existing cached cloud connection if it's available and healthy, if not - it'll try to create, cache and return a new cloud connection Input: serviceConfig - ConfigMap containing cloud_address and local_port

and optional proxy_cloud_connections, cloud_port, rootca_cert, gateway_cert/key fields if direct
cloud connection is needed
service - name of cloud service to connect to

Output: *grpc.ClientConn with connection to cloud service

error if it exists

Note: controlProxyConfig differences are ignored in cached connection mapping,

if an update to ConfigMap is required - use CleanupSharedCloudConnection() to flush the service conn cache

func (*ServiceRegistry) ListAllServices

func (r *ServiceRegistry) ListAllServices() []string

ListAllServices lists the names of all registered services.

func (*ServiceRegistry) RemoveService

func (r *ServiceRegistry) RemoveService(service string)

RemoveService removes a service from the registry. Has no effect if the service does not exist.

func (*ServiceRegistry) RemoveServicesWithLabel

func (r *ServiceRegistry) RemoveServicesWithLabel(label string)

RemoveServicesWithLabel removes all services from the registry which have the passed label.

Jump to

Keyboard shortcuts

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