forked from hudl/fargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hudl#55 from seh/schedule-updates-by-vip-address
Schedule updates to the set of instances registered with a VIP address
- Loading branch information
Showing
6 changed files
with
214 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fargo_test | ||
|
||
// MIT Licensed (see README.md) - Copyright (c) 2013 Hudl <@Hudl> | ||
|
||
import "github.com/hudl/fargo" | ||
|
||
func makeConnection() fargo.EurekaConnection { | ||
var c fargo.Config | ||
c.Eureka.ServiceUrls = []string{"http://172.17.0.2:8080/eureka/v2"} | ||
c.Eureka.ConnectTimeoutSeconds = 10 | ||
c.Eureka.PollIntervalSeconds = 30 | ||
c.Eureka.Retries = 3 | ||
return fargo.NewConnFromConfig(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package fargo_test | ||
|
||
// MIT Licensed (see README.md) - Copyright (c) 2013 Hudl <@Hudl> | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hudl/fargo" | ||
) | ||
|
||
func ExampleEurekaConnection_ScheduleVIPAddressUpdates_manual() { | ||
e := makeConnection() | ||
done := make(chan struct{}) | ||
time.AfterFunc(2*time.Minute, func() { | ||
close(done) | ||
}) | ||
vipAddress := "my_vip" | ||
// We only care about those instances that are available to receive requests. | ||
updates, err := e.ScheduleVIPAddressUpdates(vipAddress, true, done, fargo.ThatAreUp, fargo.Shuffled) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Printf("Monitoring VIP address %q.\n", vipAddress) | ||
for update := range updates { | ||
if update.Err != nil { | ||
fmt.Printf("Most recent request for VIP address %q's instances failed: %v\n", vipAddress, update.Err) | ||
continue | ||
} | ||
fmt.Printf("VIP address %q has %d instances available.\n", vipAddress, len(update.Instances)) | ||
} | ||
fmt.Printf("Done monitoring VIP address %q.\n", vipAddress) | ||
} | ||
|
||
func ExampleEurekaConnection_ScheduleVIPAddressUpdates_context() { | ||
e := makeConnection() | ||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||
defer cancel() | ||
vipAddress := "my_vip" | ||
// Look for instances that are in trouble. | ||
updates, err := e.ScheduleVIPAddressUpdates(vipAddress, true, ctx.Done(), fargo.WithStatus(fargo.DOWN), fargo.WithStatus(fargo.OUTOFSERVICE)) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Printf("Monitoring VIP address %q.\n", vipAddress) | ||
for update := range updates { | ||
if update.Err != nil { | ||
fmt.Printf("Most recent request for VIP address %q's instances failed: %v\n", vipAddress, update.Err) | ||
continue | ||
} | ||
fmt.Printf("VIP address %q has %d instances in trouble.\n", vipAddress, len(update.Instances)) | ||
} | ||
fmt.Printf("Done monitoring VIP address %q.\n", vipAddress) | ||
} | ||
|
||
func ExampleEurekaConnection_ScheduleSecureVIPAddressUpdates_context() { | ||
e := makeConnection() | ||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||
defer cancel() | ||
svipAddress := "my_vip" | ||
updates, err := e.ScheduleSecureVIPAddressUpdates(svipAddress, true, ctx.Done(), fargo.ThatAreUp) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Printf("Monitoring secure VIP address %q.\n", svipAddress) | ||
for update := range updates { | ||
if update.Err != nil { | ||
fmt.Printf("Most recent request for secure VIP address %q's instances failed: %v\n", svipAddress, update.Err) | ||
continue | ||
} | ||
fmt.Printf("Secure VIP address %q has %d instances.\n", svipAddress, len(update.Instances)) | ||
} | ||
fmt.Printf("Done monitoring secure VIP address %q.\n", svipAddress) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters