Skip to content

Commit 1a2334b

Browse files
committed
fix:服务列表支持服务可见性&修复服务可见性优先级判断
1 parent a09ba84 commit 1a2334b

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

apiserver/grpcserver/discover/v1/client_access.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (g *DiscoverServer) handleDiscoverRequest(ctx context.Context, in *apiservi
164164
case apiservice.DiscoverRequest_ROUTING:
165165
action = metrics.ActionDiscoverRouterRule
166166
out = g.namingServer.GetRoutingConfigWithCache(ctx, in.Service)
167+
case apiservice.DiscoverRequest_CUSTOM_ROUTE_RULE:
168+
action = metrics.ActionDiscoverRouterRule
169+
out = g.namingServer.GetRoutingConfigWithCache(ctx, in.Service)
167170
case apiservice.DiscoverRequest_RATE_LIMIT:
168171
action = metrics.ActionDiscoverRateLimit
169172
out = g.namingServer.GetRateLimitWithCache(ctx, in.Service)

service/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ type ClientServer interface {
222222
ReportServiceContract(ctx context.Context, req *apiservice.ServiceContract) *apiservice.Response
223223
// GetLaneRuleWithCache fetch lane rules by client
224224
GetLaneRuleWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse
225+
// GetRouterRuleWithCache fetch lane rules by client
226+
GetRouterRuleWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse
225227
}
226228

227229
// L5OperateServer L5 related operations

service/client_v1.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,36 @@ func (s *Server) GetLaneRuleWithCache(ctx context.Context, req *apiservice.Servi
499499
return resp
500500
}
501501

502+
// GetRouterRuleWithCache fetch lane rules by client
503+
func (s *Server) GetRouterRuleWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse {
504+
resp := createCommonDiscoverResponse(req, apiservice.DiscoverResponse_CUSTOM_ROUTE_RULE)
505+
aliasFor := s.findServiceAlias(req)
506+
507+
out, err := s.caches.RoutingConfig().GetRouterConfigV2(aliasFor.ID, aliasFor.Name, aliasFor.Namespace)
508+
if err != nil {
509+
log.Error("[Server][Service][Routing] discover routing", utils.RequestID(ctx), zap.Error(err))
510+
return api.NewDiscoverRoutingResponse(apimodel.Code_ExecuteException, req)
511+
}
512+
if out == nil {
513+
return resp
514+
}
515+
516+
// 获取路由数据,并对比revision
517+
if out.GetRevision().GetValue() == req.GetRevision().GetValue() {
518+
return api.NewDiscoverRoutingResponse(apimodel.Code_DataNoChange, req)
519+
}
520+
521+
// 数据不一致,发生了改变
522+
// 数据格式转换,service只需要返回二元组与routing的revision
523+
resp.Service.Revision = out.GetRevision()
524+
resp.CustomRouteRules = out.Rules
525+
resp.AliasFor = &apiservice.Service{
526+
Name: utils.NewStringValue(aliasFor.Name),
527+
Namespace: utils.NewStringValue(aliasFor.Namespace),
528+
}
529+
return resp
530+
}
531+
502532
func (s *Server) findServiceAlias(req *apiservice.Service) *model.Service {
503533
// 获取源服务
504534
aliasFor := s.getServiceCache(req.GetName().GetValue(), req.GetNamespace().GetValue())

service/interceptor/auth/client_v1.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,16 @@ func (svr *Server) GetLaneRuleWithCache(ctx context.Context, req *apiservice.Ser
236236

237237
return svr.nextSvr.GetLaneRuleWithCache(ctx, req)
238238
}
239+
240+
// GetRouterRuleWithCache .
241+
func (svr *Server) GetRouterRuleWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse {
242+
authCtx := svr.collectServiceAuthContext(
243+
ctx, []*apiservice.Service{req}, authcommon.Read, authcommon.DiscoverRouterRule)
244+
if _, err := svr.policySvr.GetAuthChecker().CheckClientPermission(authCtx); err != nil {
245+
return api.NewDiscoverResponse(authcommon.ConvertToErrCode(err))
246+
}
247+
ctx = authCtx.GetRequestContext()
248+
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
249+
250+
return svr.nextSvr.GetRouterRuleWithCache(ctx, req)
251+
}

service/interceptor/paramcheck/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ func (s *Server) GetLaneRuleWithCache(ctx context.Context, req *apiservice.Servi
162162
return s.nextSvr.GetLaneRuleWithCache(ctx, req)
163163
}
164164

165+
// GetRouterRuleWithCache .
166+
func (s *Server) GetRouterRuleWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse {
167+
resp := service.CreateCommonDiscoverResponse(req, apiservice.DiscoverResponse_CUSTOM_ROUTE_RULE)
168+
if !s.commonCheckDiscoverRequest(req, resp) {
169+
return resp
170+
}
171+
return s.nextSvr.GetRouterRuleWithCache(ctx, req)
172+
}
173+
165174
// UpdateInstance update one instance by client
166175
func (s *Server) UpdateInstance(ctx context.Context, req *apiservice.Instance) *apiservice.Response {
167176
// 参数检查

0 commit comments

Comments
 (0)