Skip to content

Commit f7db42d

Browse files
committed
feat: export LongPool Config
1 parent 590f088 commit f7db42d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

client/option_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import (
4444
"github.com/cloudwego/kitex/pkg/http"
4545
"github.com/cloudwego/kitex/pkg/loadbalance"
4646
"github.com/cloudwego/kitex/pkg/proxy"
47+
connpool2 "github.com/cloudwego/kitex/pkg/remote/connpool"
48+
"github.com/cloudwego/kitex/pkg/remote/trans/gonet"
49+
"github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
4750
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
4851
"github.com/cloudwego/kitex/pkg/retry"
4952
"github.com/cloudwego/kitex/pkg/rpcinfo"
@@ -764,6 +767,20 @@ func TestTailOption(t *testing.T) {
764767
test.Assert(t, opts.RemoteOpt.Dialer != nil)
765768
}
766769

770+
func TestGonetOption(t *testing.T) {
771+
// gonet
772+
opt := client.NewOptions([]Option{WithDialer(gonet.NewDialer()), WithLongConnection(connpool.IdleConfig{MaxIdlePerAddress: 10})})
773+
d := opt.RemoteOpt.ConnPool.(*connpool2.LongPool)
774+
pcfg := d.Config()
775+
test.Assert(t, pcfg.Enable)
776+
777+
// netpoll
778+
opt = client.NewOptions([]Option{WithDialer(netpoll.NewDialer()), WithLongConnection(connpool.IdleConfig{MaxIdlePerAddress: 10})})
779+
d = opt.RemoteOpt.ConnPool.(*connpool2.LongPool)
780+
pcfg = d.Config()
781+
test.Assert(t, !pcfg.Enable)
782+
}
783+
767784
func checkOneOptionDebugInfo(t *testing.T, opt Option, expectStr string) error {
768785
o := &Options{}
769786
o.Apply([]Option{opt})

pkg/remote/connpool/long_pool.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var (
4242

4343
const (
4444
DefaultProactiveConnCheckInterval = 3 * time.Second
45-
ConfigDumpKey = "longpool_config"
45+
idleConfigDumpKey = "idle_config"
4646
)
4747

4848
func getSharedTicker(p *LongPool, refreshInterval time.Duration) *utils.SharedTicker {
@@ -461,7 +461,7 @@ func (lp *LongPool) Clean(network, address string) {
461461
// Dump is used to dump current long pool info when needed, like debug query.
462462
func (lp *LongPool) Dump() interface{} {
463463
m := make(map[string]interface{})
464-
m[ConfigDumpKey] = lp.config
464+
m[idleConfigDumpKey] = lp.config.IdleConfig
465465
lp.peerMap.Range(func(key, value interface{}) bool {
466466
t := value.(*peer).pool.Dump()
467467
m[key.(netAddr).String()] = t
@@ -470,6 +470,11 @@ func (lp *LongPool) Dump() interface{} {
470470
return m
471471
}
472472

473+
// Config returns the config of the long pool
474+
func (lp *LongPool) Config() LongPoolConfig {
475+
return lp.config
476+
}
477+
473478
// Close releases all peers in the pool, it is executed when client is closed.
474479
func (lp *LongPool) Close() error {
475480
if !atomic.CompareAndSwapInt32(&lp.closed, 0, 1) {

0 commit comments

Comments
 (0)