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

Make grpc reporter default and add retry #1384

Merged
merged 6 commits into from
Feb 27, 2019
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
13 changes: 13 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ required = [
[[constraint]]
name = "github.com/Shopify/sarama"
version = "1.20.1"

[[constraint]]
name = "github.com/grpc-ecosystem/go-grpc-middleware"
version = "1.0.0"
2 changes: 1 addition & 1 deletion cmd/agent/app/reporter/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Options struct {

// AddFlags adds flags for Options.
func AddFlags(flags *flag.FlagSet) {
flags.String(reporterType, string(TCHANNEL), fmt.Sprintf("Reporter type to use e.g. %s, %s", string(TCHANNEL), string(GRPC)))
flags.String(reporterType, string(GRPC), fmt.Sprintf("Reporter type to use e.g. %s, %s", string(GRPC), string(TCHANNEL)))
}

// InitFromViper initializes Options with properties retrieved from Viper.
Expand Down
13 changes: 9 additions & 4 deletions cmd/agent/app/reporter/grpc/collector_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package grpc
import (
"errors"

"github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand All @@ -41,19 +42,23 @@ func NewCollectorProxy(o *Options, mFactory metrics.Factory, logger *zap.Logger)
if len(o.CollectorHostPort) == 0 {
return nil, errors.New("could not create collector proxy, address is missing")
}
var conn *grpc.ClientConn
var target string
if len(o.CollectorHostPort) > 1 {
r, _ := manual.GenerateAndRegisterManualResolver()
var resolvedAddrs []resolver.Address
for _, addr := range o.CollectorHostPort {
resolvedAddrs = append(resolvedAddrs, resolver.Address{Addr: addr})
}
r.InitialAddrs(resolvedAddrs)
conn, _ = grpc.Dial(r.Scheme()+":///round_robin", grpc.WithInsecure(), grpc.WithBalancerName(roundrobin.Name))
target = r.Scheme() + ":///round_robin"
} else {
// It does not return error if the collector is not running
conn, _ = grpc.Dial(o.CollectorHostPort[0], grpc.WithInsecure(), grpc.WithBalancerName(roundrobin.Name))
target = o.CollectorHostPort[0]
}
// It does not return error if the collector is not running
conn, _ := grpc.Dial(target,
grpc.WithInsecure(),
grpc.WithBalancerName(roundrobin.Name),
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(o.MaxRetry))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this retry work? Is it possible to configure it with exponential backoff, or some backoff for e.g.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default it is using BackoffLinearWithJitter. Which can be changed.

https://github.com/grpc-ecosystem/go-grpc-middleware/blob/master/retry/options.go#L26

grpcMetrics := mFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"protocol": "grpc"}})
return &ProxyBuilder{
conn: conn,
Expand Down
7 changes: 6 additions & 1 deletion cmd/agent/app/reporter/grpc/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ import (
const (
gRPCPrefix = "reporter.grpc."
collectorHostPort = gRPCPrefix + "host-port"
retry = gRPCPrefix + "retry.max"
defaultMaxRetry = 3
)

// Options Struct to hold configurations
type Options struct {
// CollectorHostPort is list of host:port Jaeger Collectors.
CollectorHostPort []string
MaxRetry uint
}

// AddFlags adds flags for Options.
func AddFlags(flags *flag.FlagSet) {
flags.String(collectorHostPort, "", "(experimental) Comma-separated string representing host:port of a static list of collectors to connect to directly.")
flags.String(collectorHostPort, "", "Comma-separated string representing host:port of a static list of collectors to connect to directly.")
flags.Uint(retry, defaultMaxRetry, "Sets the maximum number of retries for a call.")
}

// InitFromViper initializes Options with properties retrieved from Viper.
Expand All @@ -43,5 +47,6 @@ func (o *Options) InitFromViper(v *viper.Viper) *Options {
if hostPorts != "" {
o.CollectorHostPort = strings.Split(hostPorts, ",")
}
o.MaxRetry = uint(v.GetInt(retry))
return o
}
20 changes: 10 additions & 10 deletions cmd/agent/app/reporter/grpc/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ import (
)

func TestBingFlags(t *testing.T) {
v := viper.New()
command := cobra.Command{}
flags := &flag.FlagSet{}
AddFlags(flags)
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

tests := []struct {
cOpts []string
expected *Options
}{
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111"},
expected: &Options{CollectorHostPort: []string{"localhost:1111"}}},
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111", "--reporter.grpc.retry.max=15"},
expected: &Options{CollectorHostPort: []string{"localhost:1111"}, MaxRetry:15}},
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111,localhost:2222"},
expected: &Options{CollectorHostPort: []string{"localhost:1111", "localhost:2222"}}},
expected: &Options{CollectorHostPort: []string{"localhost:1111", "localhost:2222"}, MaxRetry:defaultMaxRetry}},
}
for _, test := range tests {
v := viper.New()
command := cobra.Command{}
flags := &flag.FlagSet{}
AddFlags(flags)
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

err := command.ParseFlags(test.cOpts)
require.NoError(t, err)
b := new(Options).InitFromViper(v)
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/builder/builder_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func AddFlags(flags *flag.FlagSet) {
flags.Int(collectorNumWorkers, app.DefaultNumWorkers, "The number of workers pulling items from the queue")
flags.Int(collectorPort, defaultTChannelPort, "The TChannel port for the collector service")
flags.Int(collectorHTTPPort, defaultHTTPPort, "The HTTP port for the collector service")
flags.Int(collectorGRPCPort, defaultGRPCPort, "(experimental) The gRPC port for the collector service")
flags.Int(collectorGRPCPort, defaultGRPCPort, "The gRPC port for the collector service")
flags.Int(collectorZipkinHTTPort, 0, "The HTTP port for the Zipkin collector service e.g. 9411")
}

Expand Down
4 changes: 1 addition & 3 deletions crossdock/jaeger-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ services:

jaeger-agent:
image: jaegertracing/jaeger-agent
# FIXME temporarily switching back to tchannel
# https://github.com/jaegertracing/jaeger/issues/1229
command: ["--reporter.tchannel.host-port=jaeger-collector:14267"]
command: ["--reporter.grpc.host-port=jaeger-collector:14250", "--reporter.grpc.retry.max=100"]
ports:
- "5775:5775/udp"
- "6831:6831/udp"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose/jaeger-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:

jaeger-agent:
image: jaegertracing/jaeger-agent
command: ["--reporter.type=grpc", "--reporter.grpc.host-port=jaeger-collector:14250"]
command: ["--reporter.grpc.host-port=jaeger-collector:14250"]
ports:
- "5775:5775/udp"
- "6831:6831/udp"
Expand Down