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
- func AddService(location ServiceLocation)
- func AddServices(locations ...ServiceLocation)
- func FindServices(label string) []string
- func GetAnnotation(service, annotationName string) (string, error)
- func GetAnnotationList(service, annotationName string) ([]string, error)
- func GetClientConnection(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func GetConnection(service string) (*grpc.ClientConn, error)
- func GetConnectionImpl(ctx context.Context, service string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func GetEchoServerPort(service string) (int, error)
- func GetServiceAddress(service string) (string, error)
- func GetServicePort(service string) (int, error)
- func GetServiceProxyAliases(service string) (map[string]int, error)
- func GetSharedCloudConnectionTTL() time.Duration
- func ListAllServices() []string
- func ListControllerServices() []string
- func MustPopulateServices()
- func PopulateServices() error
- func RemoveService(service string)
- func RemoveServicesWithLabel(label string)
- func SetSharedCloudConnectionTTL(ttl time.Duration)
- type ServiceLocation
- type ServiceRegistry
- func (r *ServiceRegistry) AddService(location ServiceLocation)
- func (r *ServiceRegistry) AddServices(locations ...ServiceLocation)
- func (r *ServiceRegistry) CleanupSharedCloudConnection(service string) bool
- func (r *ServiceRegistry) FindServices(label string) []string
- func (r *ServiceRegistry) GetAnnotation(service, annotationName string) (string, error)
- func (r *ServiceRegistry) GetAnnotationList(service, annotationName string) ([]string, error)
- func (r *ServiceRegistry) GetCloudConnection(service string) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) GetCloudConnectionFromServiceConfig(controlProxyConfig *config.ConfigMap, service string) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) GetConnection(service string) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) GetConnectionImpl(ctx context.Context, service string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) GetEchoServerPort(service string) (int, error)
- func (r *ServiceRegistry) GetServiceAddress(service string) (string, error)
- func (r *ServiceRegistry) GetServicePort(service string) (int, error)
- func (r *ServiceRegistry) GetServiceProxyAliases(service string) (map[string]int, error)
- func (r *ServiceRegistry) GetSharedCloudConnection(service string) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) GetSharedCloudConnectionFromServiceConfig(controlProxyConfig *config.ConfigMap, service string) (*grpc.ClientConn, error)
- func (r *ServiceRegistry) ListAllServices() []string
- func (r *ServiceRegistry) RemoveService(service string)
- func (r *ServiceRegistry) RemoveServicesWithLabel(label string)
Constants ¶
const ( GrpcMaxDelaySec = 10 GrpcMaxLocalTimeoutSec = 30 GrpcMaxTimeoutSec = 60 )
const (
ControlProxyServiceName = "CONTROL_PROXY"
)
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 ¶
FindServices returns the names of all registered services that have the passed label.
func GetAnnotation ¶
GetAnnotation returns the annotation value for the passed annotation name. The service needs to be added to the registry before this.
func GetAnnotationList ¶
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 ¶
GetEchoServerPort returns the listening port for the service's echo server. The service needs to be added to the registry before this.
func GetServiceAddress ¶
GetServiceAddress returns the RPC address of the service from global registry The service needs to be added to the registry before this.
func GetServicePort ¶
GetServicePort returns the listening port for the RPC service. The service needs to be added to the registry before this.
func GetServiceProxyAliases ¶
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 ¶
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 ¶
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 (*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.