Skip to content

Commit

Permalink
Merge pull request #162 from nacos-group/debug-prom
Browse files Browse the repository at this point in the history
fix: get  empty server list from endpoint
  • Loading branch information
lzp0412 authored Dec 8, 2020
2 parents 762827f + 5a038dd commit fab32c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion clients/config_client/config_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

type ConfigProxy struct {
nacosServer nacos_server.NacosServer
nacosServer *nacos_server.NacosServer
clientConfig constant.ClientConfig
}

Expand Down
6 changes: 4 additions & 2 deletions clients/naming_client/beat_reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package naming_client
import (
"testing"

"github.com/nacos-group/nacos-sdk-go/common/nacos_server"

"github.com/nacos-group/nacos-sdk-go/model"
"github.com/nacos-group/nacos-sdk-go/util"
"github.com/stretchr/testify/assert"
)

func TestBeatReactor_AddBeatInfo(t *testing.T) {
br := NewBeatReactor(NamingProxy{}, 5000)
br := NewBeatReactor(NamingProxy{nacosServer: &nacos_server.NacosServer{}}, 5000)
serviceName := "Test"
groupName := "public"
beatInfo := model.BeatInfo{
Expand All @@ -44,7 +46,7 @@ func TestBeatReactor_AddBeatInfo(t *testing.T) {
}

func TestBeatReactor_RemoveBeatInfo(t *testing.T) {
br := NewBeatReactor(NamingProxy{}, 5000)
br := NewBeatReactor(NamingProxy{nacosServer: &nacos_server.NacosServer{}}, 5000)
serviceName := "Test"
groupName := "public"
beatInfo1 := model.BeatInfo{
Expand Down
2 changes: 1 addition & 1 deletion clients/naming_client/naming_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

type NamingProxy struct {
clientConfig constant.ClientConfig
nacosServer nacos_server.NacosServer
nacosServer *nacos_server.NacosServer
}

func NewNamingProxy(clientCfg constant.ClientConfig, serverCfgs []constant.ServerConfig, httpAgent http_agent.IHttpAgent) (NamingProxy, error) {
Expand Down
15 changes: 8 additions & 7 deletions common/nacos_server/nacos_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ type NacosServer struct {
vipSrvRefInterMills int64
}

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

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

if err != nil {
return ns, err
return &ns, err
}

securityLogin.AutoRefresh()
return ns, nil
return &ns, nil
}

func (server *NacosServer) callConfigServer(api string, params map[string]string, newHeaders map[string]string,
Expand Down Expand Up @@ -246,8 +246,10 @@ func (server *NacosServer) initRefreshSrvIfNeed() {
}
server.refreshServerSrvIfNeed()
go func() {
time.Sleep(time.Duration(1) * time.Second)
server.refreshServerSrvIfNeed()
for {
time.Sleep(time.Duration(1) * time.Second)
server.refreshServerSrvIfNeed()
}
}()

}
Expand Down Expand Up @@ -289,7 +291,6 @@ func (server *NacosServer) refreshServerSrvIfNeed() {
}

}

return
}

Expand Down

0 comments on commit fab32c8

Please sign in to comment.