Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-target app clients when name resolution changes #2579

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions probe/appclient/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type AppClient interface {
PipeConnection(string, xfer.Pipe)
PipeClose(string) error
Publish(r io.Reader) error
Target() url.URL
ReTarget(url.URL)
Stop()
}

Expand Down Expand Up @@ -84,10 +86,14 @@ func NewAppClient(pc ProbeConfig, hostname string, target url.URL, control xfer.
}

func (c *appClient) url(path string) string {
c.mtx.Lock()
defer c.mtx.Unlock()
return c.target.String() + path
}

func (c *appClient) wsURL(path string) string {
c.mtx.Lock()
defer c.mtx.Unlock()
output := c.target //copy the url
if output.Scheme == "https" {
output.Scheme = "wss"
Expand Down Expand Up @@ -140,6 +146,23 @@ func (c *appClient) releaseGoroutine() {
c.backgroundWait.Done()
}

func (c *appClient) Target() url.URL {
c.mtx.Lock()
defer c.mtx.Unlock()
return c.target
}

// Re-target the appClient, publishing to a new URL. Note that control
// and pipe websocket connections are left untouched since we don't
// want to disrupt them just because there's some load-balancing going
// on. They *will* however pick up the new URL when terminating
// (e.g. due to errors or when the connection drops).
func (c *appClient) ReTarget(target url.URL) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.target = target
}

// Stop stops the appClient.
func (c *appClient) Stop() {
c.mtx.Lock()
Expand Down
4 changes: 3 additions & 1 deletion probe/appclient/multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func (c *multiClient) Set(hostname string, urls []url.URL) {
hostIDs := report.MakeIDList()
for tuple := range clients {
hostIDs = hostIDs.Add(tuple.ID)
if _, ok := c.clients[tuple.ID]; !ok {
if client, ok := c.clients[tuple.ID]; ok {
client.ReTarget(tuple.AppClient.Target())
} else {
c.clients[tuple.ID] = tuple.AppClient
if !c.noControls {
tuple.AppClient.ControlConnection()
Expand Down
7 changes: 7 additions & 0 deletions probe/appclient/multi_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (c *mockClient) ControlConnection() {
c.count++
}

func (c *mockClient) Target() url.URL {
return url.URL{}
}

func (c *mockClient) ReTarget(_ url.URL) {
}

func (c *mockClient) Stop() {
c.stopped++
}
Expand Down