Skip to content

Commit

Permalink
Allow raw port numbers for UDP servers (#2025)
Browse files Browse the repository at this point in the history
* Allow raw port numbers for UDP servers

Signed-off-by: Yuri Shkuro <[email protected]>

* Better logic

Signed-off-by: Yuri Shkuro <[email protected]>

* fix tests

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Jan 16, 2020
1 parent de47a9a commit 886b965
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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
}

0 comments on commit 886b965

Please sign in to comment.