Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  feat: 配置示例:1.配置项区分配置项名称和配置文件名...--story=120240982 (#3586)
  fix: 分组列表展示优化 (#3582)
  feat: 文件型http(s)接口的shell方法,labels添加转义符--story=120052427 (#3583)
  feat: 文件型http(s)接口:1.路径调整;2.shell的服务名和空间id改为变量--story=120052427 (#3580)
  fix: ha metadata (#3579)
  feat: bcs-user-manager 支持 redis 哨兵和集群模式 (#3548)
  feat: cluster-resource 支持redis哨兵和集群模式 (#3547)
  feat: bcs-webconsole 支持共享集群(命名空间模式) (#3282)
  feat: 客户端查询页面新增刷新客户端列表按钮--story=120142905  (#3576)
  feat: 换行符常显--story=120052427 (#3577)
  feat:  新建脚本时新增一个空行--story=120143087 (#3575)
  fix: panic caused by grpc reflection (#3574)
  feat: 配置示例文件型新增http(s)接口调用 50%进度 --story=120052427 (#3572)
  • Loading branch information
wenxinlee2015 committed Oct 23, 2024
2 parents e6dcb94 + 3bfec00 commit 873e28f
Show file tree
Hide file tree
Showing 49 changed files with 4,417 additions and 3,728 deletions.
7 changes: 6 additions & 1 deletion bcs-services/bcs-bscp/cmd/config-server/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *Service) UpdateGroup(ctx context.Context, req *pbcs.UpdateGroupReq) (*p
}

// ListAllGroups list all groups in biz
// nolint:funlen
func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq) (*pbcs.ListAllGroupsResp, error) {
grpcKit := kit.FromGrpcContext(ctx)
resp := new(pbcs.ListAllGroupsResp)
Expand All @@ -206,7 +207,10 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
}

// 1. list all groups
lgResp, err := s.client.DS.ListAllGroups(grpcKit.RpcCtx(), &pbds.ListAllGroupsReq{BizId: req.BizId})
lgResp, err := s.client.DS.ListAllGroups(grpcKit.RpcCtx(), &pbds.ListAllGroupsReq{
BizId: req.BizId,
TopIds: req.TopIds,
})
if err != nil {
logs.Errorf("list groups failed, err: %v, rid: %s", err, grpcKit.Rid)
return nil, err
Expand Down Expand Up @@ -282,6 +286,7 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbcs.ListAllGroupsReq)
}
respData = append(respData, data)
}

resp.Details = respData

return resp, nil
Expand Down
4 changes: 3 additions & 1 deletion bcs-services/bcs-bscp/cmd/data-service/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (s *Service) ListAllGroups(ctx context.Context, req *pbds.ListAllGroupsReq)

resp := new(pbds.ListAllGroupsResp)

details, err := s.dao.Group().ListAll(kt, req.BizId)
// StrToUint32Slice the comma separated string goes to uint32 slice
topIds, _ := tools.StrToUint32Slice(req.TopIds)
details, err := s.dao.Group().ListAll(kt, req.BizId, topIds)
if err != nil {
logs.Errorf("list group failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
Expand Down
27 changes: 21 additions & 6 deletions bcs-services/bcs-bscp/cmd/feed-server/service/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ func FeedUnaryAuthInterceptor(

ctx = context.WithValue(ctx, constant.BizIDKey, bizID) //nolint:staticcheck

svr := info.Server.(*Service)
ctx, err := svr.authorize(ctx, bizID)
svc, ok := info.Server.(*Service)
// 处理非业务 Service 时不鉴权,如 GRPC Reflection
if !ok {
return handler(ctx, req)
}

ctx, err := svc.authorize(ctx, bizID)
if err != nil {
return nil, err
}
Expand All @@ -128,6 +133,12 @@ func FeedUnaryAuthInterceptor(
func FeedUnaryUpdateLastConsumedTimeInterceptor(ctx context.Context, req interface{},
info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {

svc, ok := info.Server.(*Service)
// 跳过非业务 Service,如 GRPC Reflection
if !ok {
return handler(ctx, req)
}

type lastConsumedTime struct {
BizID uint32
AppNames []string
Expand Down Expand Up @@ -185,11 +196,10 @@ func FeedUnaryUpdateLastConsumedTimeInterceptor(ctx context.Context, req interfa

if param.BizID != 0 {
ctx = context.WithValue(ctx, constant.BizIDKey, param.BizID) //nolint:staticcheck
svr := info.Server.(*Service)

if len(param.AppIDs) == 0 {
for _, appName := range param.AppNames {
appID, err := svr.bll.AppCache().GetAppID(kit.FromGrpcContext(ctx), param.BizID, appName)
appID, err := svc.bll.AppCache().GetAppID(kit.FromGrpcContext(ctx), param.BizID, appName)
if err != nil {
logs.Errorf("get app id failed, err: %v", err)
return handler(ctx, req)
Expand All @@ -198,7 +208,7 @@ func FeedUnaryUpdateLastConsumedTimeInterceptor(ctx context.Context, req interfa
}
}

if err := svr.bll.AppCache().BatchUpdateLastConsumedTime(kit.FromGrpcContext(ctx),
if err := svc.bll.AppCache().BatchUpdateLastConsumedTime(kit.FromGrpcContext(ctx),
param.BizID, param.AppIDs); err != nil {
logs.Errorf("batch update app last consumed failed, err: %v", err)
return handler(ctx, req)
Expand Down Expand Up @@ -229,7 +239,12 @@ func FeedStreamAuthInterceptor(
}

var bizID uint32
ctx, err := srv.(*Service).authorize(ss.Context(), bizID)
svc, ok := srv.(*Service)
// 处理非业务 Service 时不鉴权,如 GRPC Reflection
if !ok {
return handler(srv, ss)
}
ctx, err := svc.authorize(ss.Context(), bizID)
if err != nil {
return err
}
Expand Down
15 changes: 12 additions & 3 deletions bcs-services/bcs-bscp/pkg/dal/dao/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/utils"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
)
Expand All @@ -35,7 +36,7 @@ type Group interface {
// GetByName get group by name.
GetByName(kit *kit.Kit, bizID uint32, name string) (*table.Group, error)
// ListAll list all the groups in biz.
ListAll(kit *kit.Kit, bizID uint32) ([]*table.Group, error)
ListAll(kit *kit.Kit, bizID uint32, topIds []uint32) ([]*table.Group, error)
// DeleteWithTx delete one group instance with transaction.
DeleteWithTx(kit *kit.Kit, tx *gen.QueryTx, group *table.Group) error
// ListAppGroups list all the groups of the app.
Expand Down Expand Up @@ -158,13 +159,21 @@ func (dao *groupDao) GetByName(kit *kit.Kit, bizID uint32, name string) (*table.
}

// ListAll list all the groups in biz.
func (dao *groupDao) ListAll(kit *kit.Kit, bizID uint32) ([]*table.Group, error) {
func (dao *groupDao) ListAll(kit *kit.Kit, bizID uint32, topIds []uint32) ([]*table.Group, error) {

if bizID == 0 {
return nil, errf.New(errf.InvalidParameter, "biz id is 0")
}
m := dao.genQ.Group
return m.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID)).Find()
q := dao.genQ.Group.WithContext(kit.Ctx)

if len(topIds) != 0 {
q = q.Order(utils.NewCustomExpr(`CASE WHEN id IN (?) THEN 0 ELSE 1 END,name ASC`, []interface{}{topIds}))
} else {
q = q.Order(m.Name)
}

return q.Where(m.BizID.Eq(bizID)).Find()

}

Expand Down
15 changes: 3 additions & 12 deletions bcs-services/bcs-bscp/pkg/dal/repository/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,10 @@ func (c *haClient) Download(kt *kit.Kit, sign string) (io.ReadCloser, int64, err
return nil, 0, haErr(masterErr, slaveErr)
}

// Metadata ha repo file metadata
// Metadata only get metadata from master repo
// !Note: slave repo only used for download
func (c *haClient) Metadata(kt *kit.Kit, sign string) (*ObjectMetadata, error) {
masterMD, masterErr := c.master.Metadata(kt, sign)
if masterErr == nil {
return masterMD, nil
}

slaveMD, slaveErr := c.slave.Metadata(kt, sign)
if slaveErr == nil {
return slaveMD, nil
}

return nil, haErr(masterErr, slaveErr)
return c.master.Metadata(kt, sign)
}

// InitMultipartUpload init multipart upload file for ha repo master
Expand Down
Loading

0 comments on commit 873e28f

Please sign in to comment.