This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for global rate limiting with load balancing (#224)
* test: Add test for global rate limiting with load balancing * Fix holster dependency. * Allow test to pass when run with `-count n`; n > 1. * Tidy code. * DRY; `NewStaticBuidler()` --------- Co-authored-by: Philip Gough <[email protected]>
- Loading branch information
1 parent
68f7715
commit 1b5f31d
Showing
3 changed files
with
114 additions
and
40 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
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,45 @@ | ||
package gubernator | ||
|
||
import ( | ||
"strings" | ||
|
||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
type staticBuilder struct{} | ||
|
||
var _ resolver.Builder = (*staticBuilder)(nil) | ||
|
||
func (sb *staticBuilder) Scheme() string { | ||
return "static" | ||
} | ||
|
||
func (sb *staticBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) { | ||
var resolverAddrs []resolver.Address | ||
for _, address := range strings.Split(target.Endpoint(), ",") { | ||
resolverAddrs = append(resolverAddrs, resolver.Address{ | ||
Addr: address, | ||
ServerName: address, | ||
}) | ||
} | ||
if err := cc.UpdateState(resolver.State{Addresses: resolverAddrs}); err != nil { | ||
return nil, err | ||
} | ||
return &staticResolver{cc: cc}, nil | ||
} | ||
|
||
// NewStaticBuilder returns a builder which returns a staticResolver that tells GRPC | ||
// to connect a specific peer in the cluster. | ||
func NewStaticBuilder() resolver.Builder { | ||
return &staticBuilder{} | ||
} | ||
|
||
type staticResolver struct { | ||
cc resolver.ClientConn | ||
} | ||
|
||
func (sr *staticResolver) ResolveNow(_ resolver.ResolveNowOptions) {} | ||
|
||
func (sr *staticResolver) Close() {} | ||
|
||
var _ resolver.Resolver = (*staticResolver)(nil) |