-
Notifications
You must be signed in to change notification settings - Fork 403
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
feature: support hiding empty services #1264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,7 +373,16 @@ func (s *Server) GetServices(ctx context.Context, query map[string]string) *apis | |
var ( | ||
metaKeys, metaValues string | ||
inputInstMetaKeys, inputInstMetaValues string | ||
onlyExistHealthInstance bool | ||
) | ||
|
||
if hes, ok := query["only_exist_health_instance"]; ok { | ||
if strings.EqualFold(hes, "true") { | ||
onlyExistHealthInstance = true | ||
} | ||
delete(query, "only_exist_health_instance") | ||
} | ||
|
||
for key, value := range query { | ||
typ, ok := ServiceFilterAttributes[key] | ||
if !ok { | ||
|
@@ -446,6 +455,17 @@ func (s *Server) GetServices(ctx context.Context, query map[string]string) *apis | |
return api.NewBatchQueryResponse(commonstore.StoreCode2APICode(err)) | ||
} | ||
|
||
if onlyExistHealthInstance { | ||
onlyExistHealthInstanceServices := make([]*model.EnhancedService, 0, len(services)) | ||
for _, service := range services { | ||
if service.HealthyInstanceCount > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 参数描述和实际逻辑不符合,建议改为 only_exist_healthyinstance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个查询逻辑应该放在 s.caches.Service().GetServicesByFilter 里面,否则你这个查询是有问题的 |
||
onlyExistHealthInstanceServices = append(onlyExistHealthInstanceServices, service) | ||
} | ||
} | ||
total = uint32(len(onlyExistHealthInstanceServices)) | ||
services = onlyExistHealthInstanceServices | ||
} | ||
|
||
resp := api.NewBatchQueryResponse(apimodel.Code_ExecuteSuccess) | ||
resp.Amount = utils.NewUInt32Value(total) | ||
resp.Size = utils.NewUInt32Value(uint32(len(services))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有隐藏空服务这个逻辑了吧?