Skip to content

Commit

Permalink
Merge pull request #10 from BuoyantIO/siggy/respect-authority
Browse files Browse the repository at this point in the history
Introduce grpc-downstream-authority flag
  • Loading branch information
siggy authored Sep 10, 2018
2 parents c89b095 + 6b97f59 commit 9b82cf0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.0.4

* Introduce `grpc-downstream-authority` flag, to enable setting authority
separately from `grpc-downstream-server`.

## v0.0.3

* Update docs and example files to latest release.
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ A test run using the Docker CLI should return usage information and confirm that
$ docker run buoyantio/bb:v0.0.3
Building Blocks or `bb` is a tool that can simulate many of the typical scenarios of a cloud-native Service-Oriented Architecture based on microservices.


Usage:
bb [command]

Expand All @@ -98,18 +97,19 @@ A test run using the Docker CLI should return usage information and confirm that
terminus Receives the request and returns a pre-defined response

Flags:
--downstream-timeout duration timeout to use when making downstream connections. (default 1m0s)
--fire-and-forget do not wait for a response when contacting downstream services.
--grpc-downstream-server stringSlice list of servers (hostname:port) to send messages to using gRPC, can be repeated
--grpc-server-port int port to bind a gRPC server to (default -1)
--h1-downstream-server stringSlice list of servers (protocol://hostname:port) to send messages to using HTTP 1.1, can be repeated
--h1-server-port int port to bind a HTTP 1.1 server to (default -1)
-h, --help help for bb
--id string identifier for this container
--log-level string log level, must be one of: panic, fatal, error, warn, info, debug (default "debug")
--percent-failure int percentage of requests that this service will automatically fail
--sleep-in-millis int amount of milliseconds to wait before actually start processing a request
--terminate-after int terminate the process after this many requests
--downstream-timeout duration timeout to use when making downstream connections. (default 1m0s)
--fire-and-forget do not wait for a response when contacting downstream services.
--grpc-downstream-authority stringSlice list of authority headers to specify routing, if set, ordering and count should match grpc-downstream-server
--grpc-downstream-server stringSlice list of servers (hostname:port) to send messages to using gRPC, can be repeated
--grpc-server-port int port to bind a gRPC server to (default -1)
--h1-downstream-server stringSlice list of servers (protocol://hostname:port) to send messages to using HTTP 1.1, can be repeated
--h1-server-port int port to bind a HTTP 1.1 server to (default -1)
-h, --help help for bb
--id string identifier for this container
--log-level string log level, must be one of: panic, fatal, error, warn, info, debug (default "debug")
--percent-failure int percentage of requests that this service will automatically fail
--sleep-in-millis int amount of milliseconds to wait before actually start processing a request
--terminate-after int terminate the process after this many requests

Use "bb [command] --help" for more information about a command.

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func init() {
RootCmd.PersistentFlags().IntVar(&config.TerminateAfter, "terminate-after", 0, "terminate the process after this many requests")
RootCmd.PersistentFlags().BoolVar(&config.FireAndForget, "fire-and-forget", false, "do not wait for a response when contacting downstream services.")
RootCmd.PersistentFlags().StringSliceVar(&config.GRPCDownstreamServers, "grpc-downstream-server", []string{}, "list of servers (hostname:port) to send messages to using gRPC, can be repeated")
RootCmd.PersistentFlags().StringSliceVar(&config.GRPCDownstreamAuthorities, "grpc-downstream-authority", []string{}, "list of authority headers to specify routing, if set, ordering and count should match grpc-downstream-server")
RootCmd.PersistentFlags().StringSliceVar(&config.H1DownstreamServers, "h1-downstream-server", []string{}, "list of servers (protocol://hostname:port) to send messages to using HTTP 1.1, can be repeated")
RootCmd.PersistentFlags().DurationVar(&config.DownstreamConnectionTimeout, "downstream-timeout", time.Minute*1, "timeout to use when making downstream connections.")
RootCmd.PersistentFlags().StringVar(&logLevel, "log-level", log.DebugLevel.String(), "log level, must be one of: panic, fatal, error, warn, info, debug")
Expand Down
20 changes: 18 additions & 2 deletions protocols/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,24 @@ func NewGrpcServerIfConfigured(config *service.Config, serviceHandler *service.R
// downstream service
func NewGrpcClientsIfConfigured(config *service.Config) ([]service.Client, error) {
clients := make([]service.Client, 0)
for _, serverURL := range config.GRPCDownstreamServers {
conn, err := grpc.Dial(serverURL, grpc.WithInsecure())

withAuthorities := false
if len(config.GRPCDownstreamAuthorities) > 0 {
if len(config.GRPCDownstreamAuthorities) != len(config.GRPCDownstreamServers) {
err := fmt.Errorf("Authorities count (%d) does not match gRPC downstream server count (%d)", len(config.GRPCDownstreamAuthorities), len(config.GRPCDownstreamServers))
log.Error(err)
return nil, err
}

withAuthorities = true
}

for i, serverURL := range config.GRPCDownstreamServers {
authority := ""
if withAuthorities {
authority = config.GRPCDownstreamAuthorities[i]
}
conn, err := grpc.Dial(serverURL, grpc.WithInsecure(), grpc.WithAuthority(authority))
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
GRPCServerPort int
H1ServerPort int
GRPCDownstreamServers []string
GRPCDownstreamAuthorities []string
H1DownstreamServers []string
PercentageFailedRequests int
SleepInMillis int
Expand Down

0 comments on commit 9b82cf0

Please sign in to comment.