Skip to content

Commit d8ab694

Browse files
authored
Make grpc reporter default and add retry (#1384)
* Make grpc reporter default and add retry Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Polish Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Fix port Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Polish Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Use higher retry Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Increase retry to 100 Signed-off-by: Pavol Loffay <ploffay@redhat.com>
1 parent 189cf70 commit d8ab694

File tree

9 files changed

+46
-21
lines changed

9 files changed

+46
-21
lines changed

Gopkg.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,7 @@ required = [
122122
[[constraint]]
123123
name = "github.com/Shopify/sarama"
124124
version = "1.20.1"
125+
126+
[[constraint]]
127+
name = "github.com/grpc-ecosystem/go-grpc-middleware"
128+
version = "1.0.0"

cmd/agent/app/reporter/flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Options struct {
3939

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

4545
// InitFromViper initializes Options with properties retrieved from Viper.

cmd/agent/app/reporter/grpc/collector_proxy.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package grpc
1717
import (
1818
"errors"
1919

20+
"github.com/grpc-ecosystem/go-grpc-middleware/retry"
2021
"github.com/uber/jaeger-lib/metrics"
2122
"go.uber.org/zap"
2223
"google.golang.org/grpc"
@@ -41,19 +42,23 @@ func NewCollectorProxy(o *Options, mFactory metrics.Factory, logger *zap.Logger)
4142
if len(o.CollectorHostPort) == 0 {
4243
return nil, errors.New("could not create collector proxy, address is missing")
4344
}
44-
var conn *grpc.ClientConn
45+
var target string
4546
if len(o.CollectorHostPort) > 1 {
4647
r, _ := manual.GenerateAndRegisterManualResolver()
4748
var resolvedAddrs []resolver.Address
4849
for _, addr := range o.CollectorHostPort {
4950
resolvedAddrs = append(resolvedAddrs, resolver.Address{Addr: addr})
5051
}
5152
r.InitialAddrs(resolvedAddrs)
52-
conn, _ = grpc.Dial(r.Scheme()+":///round_robin", grpc.WithInsecure(), grpc.WithBalancerName(roundrobin.Name))
53+
target = r.Scheme() + ":///round_robin"
5354
} else {
54-
// It does not return error if the collector is not running
55-
conn, _ = grpc.Dial(o.CollectorHostPort[0], grpc.WithInsecure(), grpc.WithBalancerName(roundrobin.Name))
55+
target = o.CollectorHostPort[0]
5656
}
57+
// It does not return error if the collector is not running
58+
conn, _ := grpc.Dial(target,
59+
grpc.WithInsecure(),
60+
grpc.WithBalancerName(roundrobin.Name),
61+
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(o.MaxRetry))))
5762
grpcMetrics := mFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"protocol": "grpc"}})
5863
return &ProxyBuilder{
5964
conn: conn,

cmd/agent/app/reporter/grpc/flags.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ import (
2424
const (
2525
gRPCPrefix = "reporter.grpc."
2626
collectorHostPort = gRPCPrefix + "host-port"
27+
retry = gRPCPrefix + "retry.max"
28+
defaultMaxRetry = 3
2729
)
2830

2931
// Options Struct to hold configurations
3032
type Options struct {
3133
// CollectorHostPort is list of host:port Jaeger Collectors.
3234
CollectorHostPort []string
35+
MaxRetry uint
3336
}
3437

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

4044
// InitFromViper initializes Options with properties retrieved from Viper.
@@ -43,5 +47,6 @@ func (o *Options) InitFromViper(v *viper.Viper) *Options {
4347
if hostPorts != "" {
4448
o.CollectorHostPort = strings.Split(hostPorts, ",")
4549
}
50+
o.MaxRetry = uint(v.GetInt(retry))
4651
return o
4752
}

cmd/agent/app/reporter/grpc/flags_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ import (
2525
)
2626

2727
func TestBingFlags(t *testing.T) {
28-
v := viper.New()
29-
command := cobra.Command{}
30-
flags := &flag.FlagSet{}
31-
AddFlags(flags)
32-
command.PersistentFlags().AddGoFlagSet(flags)
33-
v.BindPFlags(command.PersistentFlags())
34-
3528
tests := []struct {
3629
cOpts []string
3730
expected *Options
3831
}{
39-
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111"},
40-
expected: &Options{CollectorHostPort: []string{"localhost:1111"}}},
32+
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111", "--reporter.grpc.retry.max=15"},
33+
expected: &Options{CollectorHostPort: []string{"localhost:1111"}, MaxRetry:15}},
4134
{cOpts: []string{"--reporter.grpc.host-port=localhost:1111,localhost:2222"},
42-
expected: &Options{CollectorHostPort: []string{"localhost:1111", "localhost:2222"}}},
35+
expected: &Options{CollectorHostPort: []string{"localhost:1111", "localhost:2222"}, MaxRetry:defaultMaxRetry}},
4336
}
4437
for _, test := range tests {
38+
v := viper.New()
39+
command := cobra.Command{}
40+
flags := &flag.FlagSet{}
41+
AddFlags(flags)
42+
command.PersistentFlags().AddGoFlagSet(flags)
43+
v.BindPFlags(command.PersistentFlags())
44+
4545
err := command.ParseFlags(test.cOpts)
4646
require.NoError(t, err)
4747
b := new(Options).InitFromViper(v)

cmd/collector/app/builder/builder_flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func AddFlags(flags *flag.FlagSet) {
5959
flags.Int(collectorNumWorkers, app.DefaultNumWorkers, "The number of workers pulling items from the queue")
6060
flags.Int(collectorPort, defaultTChannelPort, "The TChannel port for the collector service")
6161
flags.Int(collectorHTTPPort, defaultHTTPPort, "The HTTP port for the collector service")
62-
flags.Int(collectorGRPCPort, defaultGRPCPort, "(experimental) The gRPC port for the collector service")
62+
flags.Int(collectorGRPCPort, defaultGRPCPort, "The gRPC port for the collector service")
6363
flags.Int(collectorZipkinHTTPort, 0, "The HTTP port for the Zipkin collector service e.g. 9411")
6464
}
6565

crossdock/jaeger-docker-compose.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ services:
3030

3131
jaeger-agent:
3232
image: jaegertracing/jaeger-agent
33-
# FIXME temporarily switching back to tchannel
34-
# https://github.com/jaegertracing/jaeger/issues/1229
35-
command: ["--reporter.tchannel.host-port=jaeger-collector:14267"]
33+
command: ["--reporter.grpc.host-port=jaeger-collector:14250", "--reporter.grpc.retry.max=100"]
3634
ports:
3735
- "5775:5775/udp"
3836
- "6831:6831/udp"

docker-compose/jaeger-docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ services:
2626

2727
jaeger-agent:
2828
image: jaegertracing/jaeger-agent
29-
command: ["--reporter.type=grpc", "--reporter.grpc.host-port=jaeger-collector:14250"]
29+
command: ["--reporter.grpc.host-port=jaeger-collector:14250"]
3030
ports:
3131
- "5775:5775/udp"
3232
- "6831:6831/udp"

0 commit comments

Comments
 (0)