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

[ISSUE #371] 补充单元测试 & 修复boltdb问题 #372

Merged
merged 9 commits into from
May 15, 2022
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ polaris-server-release.tar.gz
*.swp
*.code-workspace

.vscode/*
.vscode
*.bolt
*.bolt.lock
/vendor
.codecc
2 changes: 1 addition & 1 deletion apiserver/eurekaserver/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ import (
* @brief 自注册到API服务器插槽
*/
func init() {
_ = apiserver.Register("eurekaserver", &EurekaServer{})
_ = apiserver.Register("service-eureka", &EurekaServer{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package configgrpcserver
package config

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions apiserver/grpcserver/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* specific language governing permissions and limitations under the License.
*/

package configgrpcserver
package config

import (
"github.com/polarismesh/polaris-server/apiserver"
)

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("configgrpcserver", &ConfigGRPCServer{})
_ = apiserver.Register("config-grpc", &ConfigGRPCServer{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package configgrpcserver
package config

import (
"context"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (g *ConfigGRPCServer) Run(errCh chan error) {
g.BaseGrpcServer.Run(errCh, g.GetProtocol(), func(server *grpc.Server) error {
for name, apiConfig := range g.openAPI {
switch name {
case "configClient":
case "client":
if apiConfig.Enable {
api.RegisterPolarisConfigGRPCServer(server, g)
openMethod, getErr := getConfigClientOpenMethod(g.GetProtocol())
Expand All @@ -82,7 +82,7 @@ func (g *ConfigGRPCServer) Run(errCh chan error) {
}
}
var err error
if g.configServer, err = config.GetConfigServer(); err != nil {
if g.configServer, err = config.GetServer(); err != nil {
log.Errorf("[Config] %v", err)
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package grpcserver
package discover

import (
"context"
Expand All @@ -27,19 +27,21 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/peer"

"github.com/polarismesh/polaris-server/apiserver/grpcserver"
api "github.com/polarismesh/polaris-server/common/api/v1"
"github.com/polarismesh/polaris-server/common/log"
"github.com/polarismesh/polaris-server/common/utils"
)

// ReportClient 客户端上报
func (g *GRPCServer) ReportClient(ctx context.Context, in *api.Client) (*api.Response, error) {
return g.namingServer.ReportClient(ConvertContext(ctx), in), nil
return g.namingServer.ReportClient(grpcserver.ConvertContext(ctx), in), nil
}

// RegisterInstance 注册服务实例
func (g *GRPCServer) RegisterInstance(ctx context.Context, in *api.Instance) (*api.Response, error) {
// 需要记录操作来源,提高效率,只针对特殊接口添加operator
rCtx := ConvertContext(ctx)
rCtx := grpcserver.ConvertContext(ctx)
rCtx = context.WithValue(rCtx, utils.StringContext("operator"), ParseGrpcOperator(ctx))

// 客户端请求中带了 token 的,优先已请求中的为准
Expand All @@ -54,7 +56,7 @@ func (g *GRPCServer) RegisterInstance(ctx context.Context, in *api.Instance) (*a
// DeregisterInstance 反注册服务实例
func (g *GRPCServer) DeregisterInstance(ctx context.Context, in *api.Instance) (*api.Response, error) {
// 需要记录操作来源,提高效率,只针对特殊接口添加operator
rCtx := ConvertContext(ctx)
rCtx := grpcserver.ConvertContext(ctx)
rCtx = context.WithValue(rCtx, utils.StringContext("operator"), ParseGrpcOperator(ctx))

// 客户端请求中带了 token 的,优先已请求中的为准
Expand All @@ -68,7 +70,7 @@ func (g *GRPCServer) DeregisterInstance(ctx context.Context, in *api.Instance) (

// Discover 统一发现接口
func (g *GRPCServer) Discover(server api.PolarisGRPC_DiscoverServer) error {
ctx := ConvertContext(server.Context())
ctx := grpcserver.ConvertContext(server.Context())
clientIP, _ := ctx.Value(utils.StringContext("client-ip")).(string)
clientAddress, _ := ctx.Value(utils.StringContext("client-address")).(string)
requestID, _ := ctx.Value(utils.StringContext("request-id")).(string)
Expand Down Expand Up @@ -135,7 +137,7 @@ func (g *GRPCServer) Discover(server api.PolarisGRPC_DiscoverServer) error {

// Heartbeat 上报心跳
func (g *GRPCServer) Heartbeat(ctx context.Context, in *api.Instance) (*api.Response, error) {
return g.healthCheckServer.Report(ConvertContext(ctx), in), nil
return g.healthCheckServer.Report(grpcserver.ConvertContext(ctx), in), nil
}

// ParseGrpcOperator 构造请求源
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* specific language governing permissions and limitations under the License.
*/

package grpcserver
package discover

import (
"github.com/polarismesh/polaris-server/apiserver"
)

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("grpcserver", &GRPCServer{})
_ = apiserver.Register("service-grpc", &GRPCServer{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package grpcserver
package discover

import (
"context"
Expand All @@ -24,14 +24,16 @@ import (
"google.golang.org/grpc"

"github.com/polarismesh/polaris-server/apiserver"
"github.com/polarismesh/polaris-server/apiserver/grpcserver"
api "github.com/polarismesh/polaris-server/common/api/v1"
"github.com/polarismesh/polaris-server/common/log"
"github.com/polarismesh/polaris-server/service"
"github.com/polarismesh/polaris-server/service/healthcheck"
)

// GRPCServer GRPC API服务器
type GRPCServer struct {
BaseGrpcServer
grpcserver.BaseGrpcServer
namingServer service.DiscoverServer
healthCheckServer *healthcheck.Server
openAPI map[string]apiserver.APIConfig
Expand Down
2 changes: 1 addition & 1 deletion apiserver/httpserver/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import (

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("httpserver", &HTTPServer{})
_ = apiserver.Register("api-http", &HTTPServer{})
}
2 changes: 1 addition & 1 deletion apiserver/httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (h *HTTPServer) Run(errCh chan error) {
h.statis = plugin.GetStatis()

// 初始化配置中心模块
h.configServer, err = config.GetConfigServer()
h.configServer, err = config.GetServer()
if err != nil {
log.Errorf("set config server to http server error. %v", err)
errCh <- err
Expand Down
2 changes: 1 addition & 1 deletion apiserver/l5pbserver/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import (

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("l5pbserver", &L5pbserver{})
_ = apiserver.Register("service-l5", &L5pbserver{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* specific language governing permissions and limitations under the License.
*/

package prometheusserver
package prometheussd

import (
"github.com/polarismesh/polaris-server/apiserver"
)

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("prometheusserver", &PrometheusServer{})
_ = apiserver.Register("prometheus-sd", &PrometheusServer{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package prometheusserver
package prometheussd

import (
"github.com/emicklei/go-restful"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package prometheusserver
package prometheussd

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/xdsserverv3/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import (

// init 自注册到API服务器插槽
func init() {
_ = apiserver.Register("xdsserverv3", &XDSServer{})
_ = apiserver.Register("xds-v3", &XDSServer{})
}
6 changes: 3 additions & 3 deletions apiserver/xdsserverv3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ func (x *XDSServer) getRegistryInfoWithCache(ctx context.Context, registryInfo m

routeResp := x.namingServer.GetRoutingConfigWithCache(ctx, s)
if routeResp.GetCode().Value != api.ExecuteSuccess {
log.Errorf("error sync instances for %s", svc.Name)
return fmt.Errorf("error sync instances for %s", svc.Name)
log.Errorf("error sync routing for %s, info : %s", svc.Name, routeResp.Info.GetValue())
return fmt.Errorf("error sync routing for %s", svc.Name)
}

if routeResp.Routing != nil {
Expand All @@ -660,7 +660,7 @@ func (x *XDSServer) getRegistryInfoWithCache(ctx context.Context, registryInfo m

resp := x.namingServer.ServiceInstancesCache(nil, s)
if resp.GetCode().Value != api.ExecuteSuccess {
log.Errorf("error sync instances for %s", svc.Name)
log.Errorf("error sync instances for %s, info : %s", svc.Name, resp.Info.GetValue())
return fmt.Errorf("error sync instances for %s", svc.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions auth/defaultauth/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (svr *server) GetGroup(ctx context.Context, req *api.UserGroup) *api.Respon
isGroupOwner := group.Owner == userID
_, find := group.UserIds[userID]
if !isGroupOwner && !find {
log.AuthScope().Error("can't see group token", zap.String("user", userID),
log.AuthScope().Error("can't see group info", zap.String("user", userID),
zap.String("group", req.GetId().GetValue()), zap.Bool("group-owner", isGroupOwner),
zap.Bool("in-group", find))
return api.NewResponse(api.NotAllowedAccess)
Expand Down Expand Up @@ -343,7 +343,7 @@ func (svr *server) UpdateGroupToken(ctx context.Context, req *api.UserGroup) *ap
return api.NewGroupResponse(api.ExecuteSuccess, req)
}

// ResetGroupToken 刷新用户组的token,刷新时会重置 token 的状态为 enable
// ResetGroupToken 刷新用户组的token
func (svr *server) ResetGroupToken(ctx context.Context, req *api.UserGroup) *api.Response {
var (
requestID = utils.ParseRequestID(ctx)
Expand Down
Loading