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

Allow raw port numbers for UDP servers #2025

Merged
merged 3 commits into from
Jan 16, 2020
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
9 changes: 5 additions & 4 deletions cmd/agent/app/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions cmd/agent/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}