Documentation ¶
Overview ¶
Config provides decoupling between various configuration sources (etcd, files,...) and the pieces that actually care about them (loadbalancer, proxy). Config takes 1 or more configuration sources and allows for incremental (add/remove) and full replace (set) changes from each of the sources, then creates a union of the configuration and provides a unified view for both service handlers as well as endpoint handlers. There is no attempt to resolve conflicts of any sort. Basic idea is that each configuration source gets a channel from the Config service and pushes updates to it via that channel. Config then keeps track of incremental & replace changes and distributes them to listeners as appropriate.
Watches etcd and gets the full configuration on preset intervals. Expects the list of exposed services to live under: registry/services which in etcd is exposed like so: http://<etcd server>/v2/keys/registry/services
The port that proxy needs to listen in for each service is a value in: registry/services/<service>
The endpoints for each of the services found is a json string representing that service at: /registry/services/<service>/endpoint and the format is: '[ { "machine": <host>, "name": <name", "port": <port> },
{ "machine": <host2>, "name": <name2", "port": <port2> } ]',
Reads the configuration from the file. Example file for two services [nodejs & mysql] {"Services": [
{ "Name":"nodejs", "Port":10000, "Endpoints":["10.240.180.168:8000", "10.240.254.199:8000", "10.240.62.150:8000"] }, { "Name":"mysql", "Port":10001, "Endpoints":["10.240.180.168:9000", "10.240.254.199:9000", "10.240.62.150:9000"] }
] }
Index ¶
- Constants
- func EtcdResponseToService(response *etcd.Response) (*api.Service, error)
- func ParseEndpoints(jsonString string) (api.Endpoints, error)
- type ConfigFile
- type ConfigSourceEtcd
- func (impl ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error)
- func (impl ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error)
- func (impl ConfigSourceEtcd) ProcessChange(response *etcd.Response)
- func (impl ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response)
- func (impl ConfigSourceEtcd) Run()
- func (impl ConfigSourceEtcd) WatchForChanges()
- type ConfigSourceFile
- type EndpointsConfigHandler
- type EndpointsUpdate
- type Operation
- type ServiceConfig
- func (impl *ServiceConfig) EndpointsChannelListener(source string, listenChannel chan EndpointsUpdate)
- func (impl *ServiceConfig) GetEndpointsConfigurationChannel(source string) chan EndpointsUpdate
- func (impl *ServiceConfig) GetServiceConfigurationChannel(source string) chan ServiceUpdate
- func (impl *ServiceConfig) NotifyEndpointsUpdate()
- func (impl *ServiceConfig) NotifyServiceUpdate()
- func (impl *ServiceConfig) RegisterEndpointsHandler(handler EndpointsConfigHandler)
- func (impl *ServiceConfig) RegisterServiceHandler(handler ServiceConfigHandler)
- func (impl *ServiceConfig) Run()
- func (impl *ServiceConfig) ServiceChannelListener(source string, listenChannel chan ServiceUpdate)
- type ServiceConfigHandler
- type ServiceJSON
- type ServiceUpdate
Constants ¶
const RegistryRoot = "registry/services"
Variables ¶
This section is empty.
Functions ¶
func EtcdResponseToService ¶
EtcdResponseToServiceAndLocalport takes an etcd response and pulls it apart to find service
Types ¶
type ConfigFile ¶
type ConfigFile struct {
Services []ServiceJSON
}
type ConfigSourceEtcd ¶
type ConfigSourceEtcd struct {
// contains filtered or unexported fields
}
func NewConfigSourceEtcd ¶
func NewConfigSourceEtcd(client *etcd.Client, serviceChannel chan ServiceUpdate, endpointsChannel chan EndpointsUpdate) ConfigSourceEtcd
func (ConfigSourceEtcd) GetEndpoints ¶
func (impl ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error)
func (ConfigSourceEtcd) GetServices ¶
Finds the list of services and their endpoints from etcd. This operation is akin to a set a known good at regular intervals.
func (ConfigSourceEtcd) ProcessChange ¶
func (impl ConfigSourceEtcd) ProcessChange(response *etcd.Response)
func (ConfigSourceEtcd) ProcessEndpointResponse ¶
func (impl ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response)
func (ConfigSourceEtcd) Run ¶
func (impl ConfigSourceEtcd) Run()
func (ConfigSourceEtcd) WatchForChanges ¶
func (impl ConfigSourceEtcd) WatchForChanges()
type ConfigSourceFile ¶
type ConfigSourceFile struct {
// contains filtered or unexported fields
}
func NewConfigSourceFile ¶
func NewConfigSourceFile(filename string, serviceChannel chan ServiceUpdate, endpointsChannel chan EndpointsUpdate) ConfigSourceFile
func (ConfigSourceFile) Run ¶
func (impl ConfigSourceFile) Run()
type EndpointsConfigHandler ¶
type EndpointsConfigHandler interface { // OnUpdate gets called when endpoints configuration is changed for a given // service on any of the configuration sources. An example is when a new // service comes up, or when containers come up or down for an existing service. OnUpdate(endpoints []api.Endpoints) }
type EndpointsUpdate ¶
Defines an operation sent on the channel. You can add or remove single endpoints by sending an array of size one and Op == ADD|REMOVE. For setting the state of the system to a given state for this source configuration, set Endpoints as desired and Op to SET, which will reset the system state to that specified in this operation for this source channel. To remove all endpoints, set Endpoints to empty array and Op to SET
type ServiceConfig ¶
type ServiceConfig struct {
// contains filtered or unexported fields
}
func NewServiceConfig ¶
func NewServiceConfig() ServiceConfig
func (*ServiceConfig) EndpointsChannelListener ¶
func (impl *ServiceConfig) EndpointsChannelListener(source string, listenChannel chan EndpointsUpdate)
func (*ServiceConfig) GetEndpointsConfigurationChannel ¶
func (impl *ServiceConfig) GetEndpointsConfigurationChannel(source string) chan EndpointsUpdate
GetEndpointConfigurationChannel returns a channel where a configuration source can send updates of new endpoint configurations. Multiple calls with the same source will return the same channel. This allows change and state based sources to use the same channel. Difference source names however will be treated as a union.
func (*ServiceConfig) GetServiceConfigurationChannel ¶
func (impl *ServiceConfig) GetServiceConfigurationChannel(source string) chan ServiceUpdate
GetServiceConfigurationChannel returns a channel where a configuration source can send updates of new service configurations. Multiple calls with the same source will return the same channel. This allows change and state based sources to use the same channel. Difference source names however will be treated as a union.
func (*ServiceConfig) NotifyEndpointsUpdate ¶
func (impl *ServiceConfig) NotifyEndpointsUpdate()
func (*ServiceConfig) NotifyServiceUpdate ¶
func (impl *ServiceConfig) NotifyServiceUpdate()
func (*ServiceConfig) RegisterEndpointsHandler ¶
func (impl *ServiceConfig) RegisterEndpointsHandler(handler EndpointsConfigHandler)
Register ServiceConfigHandler to receive updates of changes to services.
func (*ServiceConfig) RegisterServiceHandler ¶
func (impl *ServiceConfig) RegisterServiceHandler(handler ServiceConfigHandler)
Register ServiceConfigHandler to receive updates of changes to services.
func (*ServiceConfig) Run ¶
func (impl *ServiceConfig) Run()
func (*ServiceConfig) ServiceChannelListener ¶
func (impl *ServiceConfig) ServiceChannelListener(source string, listenChannel chan ServiceUpdate)
type ServiceConfigHandler ¶
type ServiceJSON ¶
TODO: kill this struct.
type ServiceUpdate ¶
Defines an operation sent on the channel. You can add or remove single services by sending an array of size one and Op == ADD|REMOVE. For setting the state of the system to a given state for this source configuration, set Services as desired and Op to SET, which will reset the system state to that specified in this operation for this source channel. To remove all services, set Services to empty array and Op to SET