diff --git a/cmd/agent/app/builder.go b/cmd/agent/app/builder.go index 66ab15137cb..7e14139ed6a 100644 --- a/cmd/agent/app/builder.go +++ b/cmd/agent/app/builder.go @@ -21,6 +21,7 @@ import ( "strconv" "github.com/apache/thrift/lib/go/thrift" + "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -109,7 +110,7 @@ func (b *Builder) CreateAgent(primaryProxy CollectorProxy, logger *zap.Logger, m r := b.getReporter(primaryProxy) processors, err := b.getProcessors(r, mFactory, logger) if err != nil { - return nil, err + return nil, errors.Wrap(err, "cannot create processors") } server := b.HTTPServer.getHTTPServer(primaryProxy.GetManager(), mFactory) return NewAgent(processors, server, logger), nil @@ -149,7 +150,7 @@ func (b *Builder) getProcessors(rep reporter.Reporter, mFactory metrics.Factory, }}) processor, err := cfg.GetThriftProcessor(metrics, protoFactory, handler, logger) if err != nil { - return nil, err + return nil, errors.Wrap(err, "cannot create Thrift Processor") } retMe[idx] = processor } @@ -175,7 +176,7 @@ func (c *ProcessorConfiguration) GetThriftProcessor( server, err := c.Server.getUDPServer(mFactory) if err != nil { - return nil, err + return nil, errors.Wrap(err, "cannot create UDP Server") } return processors.NewThriftProcessor(server, c.Workers, mFactory, factory, handler, logger) @@ -199,7 +200,7 @@ func (c *ServerConfiguration) getUDPServer(mFactory metrics.Factory) (servers.Se } transport, err := thriftudp.NewTUDPServerTransport(c.HostPort) if err != nil { - return nil, err + return nil, errors.Wrap(err, "cannot create UDPServerTransport") } return servers.NewTBufferedServer(transport, c.QueueSize, c.MaxPacketSize, mFactory) diff --git a/cmd/agent/app/builder_test.go b/cmd/agent/app/builder_test.go index 864e194eae4..9a6b0e63ec6 100644 --- a/cmd/agent/app/builder_test.go +++ b/cmd/agent/app/builder_test.go @@ -144,7 +144,7 @@ func TestBuilderWithProcessorErrors(t *testing.T) { _, err := cfg.CreateAgent(&fakeCollectorProxy{}, zap.NewNop(), metrics.NullFactory) assert.Error(t, err) if testCase.err != "" { - assert.EqualError(t, err, testCase.err) + assert.Contains(t, err.Error(), testCase.err) } else if testCase.errContains != "" { assert.True(t, strings.Contains(err.Error(), testCase.errContains), "error must contain %s", testCase.errContains) } diff --git a/cmd/agent/app/flags.go b/cmd/agent/app/flags.go index 0ae62a8633d..34bb80d2598 100644 --- a/cmd/agent/app/flags.go +++ b/cmd/agent/app/flags.go @@ -66,10 +66,19 @@ func (b *Builder) InitFromViper(v *viper.Viper) *Builder { p.Workers = v.GetInt(prefix + suffixWorkers) p.Server.QueueSize = v.GetInt(prefix + suffixServerQueueSize) p.Server.MaxPacketSize = v.GetInt(prefix + suffixServerMaxPacketSize) - p.Server.HostPort = v.GetString(prefix + suffixServerHostPort) + p.Server.HostPort = portNumToHostPort(v.GetString(prefix + suffixServerHostPort)) b.Processors = append(b.Processors, *p) } - b.HTTPServer.HostPort = v.GetString(httpServerHostPort) + b.HTTPServer.HostPort = portNumToHostPort(v.GetString(httpServerHostPort)) return b } + +// portNumToHostPort checks if the value is a raw integer port number, +// and converts it to ":{port}" host-port string, otherwise leaves it as is. +func portNumToHostPort(v string) string { + if _, err := strconv.Atoi(v); err == nil { + return ":" + v + } + return v +}