Skip to content

Commit fab32c8

Browse files
authored
Merge pull request #162 from nacos-group/debug-prom
fix: get empty server list from endpoint
2 parents 762827f + 5a038dd commit fab32c8

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

clients/config_client/config_proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
type ConfigProxy struct {
36-
nacosServer nacos_server.NacosServer
36+
nacosServer *nacos_server.NacosServer
3737
clientConfig constant.ClientConfig
3838
}
3939

clients/naming_client/beat_reactor_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package naming_client
1919
import (
2020
"testing"
2121

22+
"github.com/nacos-group/nacos-sdk-go/common/nacos_server"
23+
2224
"github.com/nacos-group/nacos-sdk-go/model"
2325
"github.com/nacos-group/nacos-sdk-go/util"
2426
"github.com/stretchr/testify/assert"
2527
)
2628

2729
func TestBeatReactor_AddBeatInfo(t *testing.T) {
28-
br := NewBeatReactor(NamingProxy{}, 5000)
30+
br := NewBeatReactor(NamingProxy{nacosServer: &nacos_server.NacosServer{}}, 5000)
2931
serviceName := "Test"
3032
groupName := "public"
3133
beatInfo := model.BeatInfo{
@@ -44,7 +46,7 @@ func TestBeatReactor_AddBeatInfo(t *testing.T) {
4446
}
4547

4648
func TestBeatReactor_RemoveBeatInfo(t *testing.T) {
47-
br := NewBeatReactor(NamingProxy{}, 5000)
49+
br := NewBeatReactor(NamingProxy{nacosServer: &nacos_server.NacosServer{}}, 5000)
4850
serviceName := "Test"
4951
groupName := "public"
5052
beatInfo1 := model.BeatInfo{

clients/naming_client/naming_proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
type NamingProxy struct {
3535
clientConfig constant.ClientConfig
36-
nacosServer nacos_server.NacosServer
36+
nacosServer *nacos_server.NacosServer
3737
}
3838

3939
func NewNamingProxy(clientCfg constant.ClientConfig, serverCfgs []constant.ServerConfig, httpAgent http_agent.IHttpAgent) (NamingProxy, error) {

common/nacos_server/nacos_server.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ type NacosServer struct {
5151
vipSrvRefInterMills int64
5252
}
5353

54-
func NewNacosServer(serverList []constant.ServerConfig, clientCfg constant.ClientConfig, httpAgent http_agent.IHttpAgent, timeoutMs uint64, endpoint string) (NacosServer, error) {
54+
func NewNacosServer(serverList []constant.ServerConfig, clientCfg constant.ClientConfig, httpAgent http_agent.IHttpAgent, timeoutMs uint64, endpoint string) (*NacosServer, error) {
5555
if len(serverList) == 0 && endpoint == "" {
56-
return NacosServer{}, errors.New("both serverlist and endpoint are empty")
56+
return &NacosServer{}, errors.New("both serverlist and endpoint are empty")
5757
}
5858

5959
securityLogin := security.NewAuthClient(clientCfg, serverList, httpAgent)
@@ -70,11 +70,11 @@ func NewNacosServer(serverList []constant.ServerConfig, clientCfg constant.Clien
7070
_, err := securityLogin.Login()
7171

7272
if err != nil {
73-
return ns, err
73+
return &ns, err
7474
}
7575

7676
securityLogin.AutoRefresh()
77-
return ns, nil
77+
return &ns, nil
7878
}
7979

8080
func (server *NacosServer) callConfigServer(api string, params map[string]string, newHeaders map[string]string,
@@ -246,8 +246,10 @@ func (server *NacosServer) initRefreshSrvIfNeed() {
246246
}
247247
server.refreshServerSrvIfNeed()
248248
go func() {
249-
time.Sleep(time.Duration(1) * time.Second)
250-
server.refreshServerSrvIfNeed()
249+
for {
250+
time.Sleep(time.Duration(1) * time.Second)
251+
server.refreshServerSrvIfNeed()
252+
}
251253
}()
252254

253255
}
@@ -289,7 +291,6 @@ func (server *NacosServer) refreshServerSrvIfNeed() {
289291
}
290292

291293
}
292-
293294
return
294295
}
295296

0 commit comments

Comments
 (0)