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

[dbnode] Add TChannel channel configuration #2989

Merged
merged 2 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/dbnode/integration/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ func NewTChannelClient(name, address string) (*TestTChannelClient, error) {
}, nil
}

// Address returns the address.
func (client *TestTChannelClient) Address() string {
return client.address
}

// Channel returns the TChannel channel.
func (client *TestTChannelClient) Channel() *tchannel.Channel {
return client.channel
}

// TChannelClientWrite writes a datapoint using a tchannel client.
func (client *TestTChannelClient) TChannelClientWrite(
timeout time.Duration, req *rpc.WriteRequest,
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type TestSetup interface {
Scope() tally.TestScope
M3DBClient() client.Client
M3DBVerificationAdminClient() client.AdminClient
TChannelClient() *TestTChannelClient
Namespaces() []namespace.Metadata
TopologyInitializer() topology.Initializer
SetTopologyInitializer(topology.Initializer)
Expand Down Expand Up @@ -789,6 +790,10 @@ func (ts *testSetup) StopServer() error {
return nil
}

func (ts *testSetup) TChannelClient() *TestTChannelClient {
return ts.tchannelClient
}

func (ts *testSetup) WriteBatch(namespace ident.ID, seriesList generate.SeriesBlock) error {
if ts.opts.UseTChannelClientForWriting() {
return ts.tchannelClient.TChannelClientWriteBatch(
Expand Down
31 changes: 31 additions & 0 deletions src/dbnode/network/server/tchannelthrift/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ import (
"github.com/uber/tchannel-go/thrift"
)

// NewTChanChannelFn creates a tchan channel.
type NewTChanChannelFn func(
channelName string,
opts *tchannel.ChannelOptions,
) (*tchannel.Channel, error)

func defaultTChanChannelFn(
channelName string,
opts *tchannel.ChannelOptions,
) (*tchannel.Channel, error) {
return tchannel.NewChannel(channelName, opts)
}

// NewTChanNodeServerFn creates a tchan node server.
type NewTChanNodeServerFn func(
service Service,
Expand All @@ -49,6 +62,12 @@ type Options interface {
// ChannelOptions returns the tchan channel options.
ChannelOptions() *tchannel.ChannelOptions

// SetTChanChannelFn sets a tchan node channel registration.
SetTChanChannelFn(value NewTChanChannelFn) Options

// TChanChannelFn returns a tchan node channel registration.
TChanChannelFn() NewTChanChannelFn

// SetTChanNodeServerFn sets a tchan node server builder.
SetTChanNodeServerFn(value NewTChanNodeServerFn) Options

Expand All @@ -65,13 +84,15 @@ type Options interface {
type options struct {
channelOptions *tchannel.ChannelOptions
instrumentOpts instrument.Options
tchanChannelFn NewTChanChannelFn
tchanNodeServerFn NewTChanNodeServerFn
}

// NewOptions creates a new options.
func NewOptions(chanOpts *tchannel.ChannelOptions) Options {
return &options{
channelOptions: chanOpts,
tchanChannelFn: defaultTChanChannelFn,
tchanNodeServerFn: defaultTChanNodeServerFn,
}
}
Expand All @@ -85,6 +106,16 @@ func (o *options) ChannelOptions() *tchannel.ChannelOptions {
return o.channelOptions
}

func (o *options) SetTChanChannelFn(value NewTChanChannelFn) Options {
opts := *o
opts.tchanChannelFn = value
return &opts
}

func (o *options) TChanChannelFn() NewTChanChannelFn {
return o.tchanChannelFn
}

func (o *options) SetTChanNodeServerFn(value NewTChanNodeServerFn) Options {
opts := *o
opts.tchanNodeServerFn = value
Expand Down
2 changes: 1 addition & 1 deletion src/dbnode/network/server/tchannelthrift/node/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *server) ListenAndServe() (ns.Close, error) {
immutableOpts := *chanOpts
opts = &immutableOpts
}
channel, err := tchannel.NewChannel(channel.ChannelName, opts)
channel, err := s.opts.TChanChannelFn()(channel.ChannelName, opts)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions src/dbnode/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ import (
// StorageOptions are options to apply to the database storage options.
type StorageOptions struct {
TChanNodeServerFn node.NewTChanNodeServerFn
TChanChannelFn node.NewTChanChannelFn
}
3 changes: 3 additions & 0 deletions src/dbnode/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ func Run(runOpts RunOptions) {
}
tchanOpts := ttnode.NewOptions(tchannelOpts).
SetInstrumentOptions(opts.InstrumentOptions())
if fn := runOpts.StorageOptions.TChanChannelFn; fn != nil {
tchanOpts = tchanOpts.SetTChanChannelFn(fn)
}
if fn := runOpts.StorageOptions.TChanNodeServerFn; fn != nil {
tchanOpts = tchanOpts.SetTChanNodeServerFn(fn)
}
Expand Down