segmentio / emissary

Multi-backend Envoy xDS service.
MIT License
8 stars 7 forks source link

Eds/pubsub #6

Closed rjenkins closed 5 years ago

rjenkins commented 5 years ago

NOTE: This is a reviewer first pull request. Please read commit by commit, particularly because eds.go was edited extensively to remove EdsStreamHandler. Each individual commit will be easy to read and include details about the changes in the commit message. i.e. If you just look at the file change for eds.go it may be difficult to grok.

This PR introduces the consulEdsPoller which provides publish/subscribe semantics for gRPC clients requesting Envoy ClusterLoadAssignment data from Emissary. The data is fetched from consul in the form of consul-go []Endpoint structs and converted to a protobuf ClusterLoadAssignment which is encapsulated in a DiscoveryResponse.

Prior to this change each gRPC connection spawned a goroutine to query consul. Now each connection registers with the consulEdsPoller which consolidates querying of consul to a single goroutine and the results are fanned out to each connection.

Additionally we fix Context in two key places. 1. We pass in the root context from the main func to eds and select on the Done channel. Secondly each gRPC conenction has its own context which we monitor Done for in it's handle(consulEdsResult) func.

rjenkins commented 5 years ago

Note: You can ignore the build circle failure it is simply an error on docker push which I will fix later