Skip to content

Commit

Permalink
fix: 修复解压文件时提示的文字存在错误以及客户端统计返回目标版本配置 (TencentBlueKing#3400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambition9186 authored Jul 25, 2024
1 parent c99e410 commit bd3f870
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 24 deletions.
10 changes: 5 additions & 5 deletions bcs-services/bcs-bscp/cmd/data-service/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,16 @@ func (s *Service) clientConfigVersionChart(kit *kit.Kit, bizID, appID uint32, he
search *pbclient.ClientQueryCondition) ([]interface{}, error) {

// 获取客户端当前的配置数据
items, err := s.dao.Client().ListClientGroupByCurrentReleaseID(kit, bizID, appID, heartbeatTime, search)
items, err := s.dao.Client().ListClientGroupByTargetReleaseID(kit, bizID, appID, heartbeatTime, search)
if err != nil {
return nil, err
}

// 获取版本名称以及计算占比
releaseIDs := []uint32{}
for _, v := range items {
if v.CurrentReleaseID > 0 {
releaseIDs = append(releaseIDs, v.CurrentReleaseID)
if v.TargetReleaseID > 0 {
releaseIDs = append(releaseIDs, v.TargetReleaseID)
}
}
releases, err := s.dao.Release().ListAllByIDs(kit, releaseIDs, bizID)
Expand All @@ -619,8 +619,8 @@ func (s *Service) clientConfigVersionChart(kit *kit.Kit, bizID, appID uint32, he
for _, v := range items {
chart := make(map[string]interface{})
ratio := float64(v.Count) / float64(totalSum)
chart["current_release_id"] = v.CurrentReleaseID
chart["current_release_name"] = releaseNames[v.CurrentReleaseID]
chart["target_release_id"] = v.TargetReleaseID
chart["target_release_name"] = releaseNames[v.TargetReleaseID]
chart["count"] = v.Count
chart["percent"] = ratio
charts = append(charts, chart)
Expand Down
57 changes: 54 additions & 3 deletions bcs-services/bcs-bscp/pkg/dal/dao/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Client interface {
order *pbds.ListClientsReq_Order, opt *types.BasePage) ([]*table.Client, int64, error)
// ListClientGroupByCurrentReleaseID 按当前版本 ID 列出客户端组
ListClientGroupByCurrentReleaseID(kit *kit.Kit, bizID, appID uint32, heartbeatTime int64,
search *pbclient.ClientQueryCondition) ([]types.ClientConfigVersionChart, error)
search *pbclient.ClientQueryCondition) ([]types.CurrentConfigVersionChart, error)
// ListClientGroupByChangeStatus 按更改状态列出客户端组
ListClientGroupByChangeStatus(kit *kit.Kit, bizID, appID uint32, heartbeatTime int64,
search *pbclient.ClientQueryCondition) ([]types.ChangeStatusChart, error)
Expand All @@ -73,6 +73,11 @@ type Client interface {
// UpdateRetriedClientsStatusWithTx batch update client release change failed status to
// processing status instances with transaction.
UpdateRetriedClientsStatusWithTx(kit *kit.Kit, tx *gen.QueryTx, ids []uint32, all bool) error
// FetchIDsExcluding 获取排除指定ID后的ID
FetchIDsExcluding(kit *kit.Kit, bizID uint32, appID uint32, ids []uint32) ([]uint32, error)
// ListClientGroupByTargetReleaseID 按目标版本 ID 列出客户端组
ListClientGroupByTargetReleaseID(kit *kit.Kit, bizID, appID uint32, heartbeatTime int64,
search *pbclient.ClientQueryCondition) ([]types.TargetConfigVersionChart, error)
}

var _ Client = new(clientDao)
Expand All @@ -83,6 +88,52 @@ type clientDao struct {
auditDao AuditDao
}

// ListClientGroupByTargetReleaseID 按目标版本 ID 列出客户端组
func (dao *clientDao) ListClientGroupByTargetReleaseID(kit *kit.Kit, bizID uint32, appID uint32, heartbeatTime int64,
search *pbclient.ClientQueryCondition) ([]types.TargetConfigVersionChart, error) {
m := dao.genQ.Client
q := dao.genQ.Client.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID), m.AppID.Eq(appID), m.TargetReleaseID.Neq(0))
var err error
var conds []rawgen.Condition

if heartbeatTime > 0 {
lastHeartbeatTime := time.Now().UTC().Add(time.Duration(-heartbeatTime) * time.Minute)
conds = append(conds, q.Where(m.LastHeartbeatTime.Gte(lastHeartbeatTime)))
}

if search.String() != "" {
conds, err = dao.handleSearch(kit, bizID, appID, search)
if err != nil {
return nil, err
}
}

var items []types.TargetConfigVersionChart
err = q.Select(m.TargetReleaseID, m.ID.Count().As("count")).Where(conds...).
Group(m.TargetReleaseID).
Scan(&items)
if err != nil {
return nil, err
}
return items, nil
}

// FetchIDsExcluding 获取指定ID后排除的ID
func (dao *clientDao) FetchIDsExcluding(kit *kit.Kit, bizID uint32, appID uint32, ids []uint32) ([]uint32, error) {

m := dao.genQ.Client
q := dao.genQ.Client.WithContext(kit.Ctx)

var result []uint32
if err := q.Select(m.ID).
Where(m.BizID.Eq(bizID), m.AppID.Eq(appID), m.ID.NotIn(ids...)).
Pluck(m.ID, &result); err != nil {
return nil, err
}

return result, nil
}

// UpdateRetriedClientsStatusWithTx batch update client release change failed status to
// processing status instances with transaction.
func (dao *clientDao) UpdateRetriedClientsStatusWithTx(kit *kit.Kit, tx *gen.QueryTx, ids []uint32, all bool) error {
Expand Down Expand Up @@ -227,7 +278,7 @@ func (dao *clientDao) ListClientGroupByChangeStatus(kit *kit.Kit, bizID uint32,

// ListClientGroupByCurrentReleaseID 通过当前版本ID统计数量
func (dao *clientDao) ListClientGroupByCurrentReleaseID(kit *kit.Kit, bizID uint32, appID uint32, heartbeatTime int64,
search *pbclient.ClientQueryCondition) ([]types.ClientConfigVersionChart, error) {
search *pbclient.ClientQueryCondition) ([]types.CurrentConfigVersionChart, error) {
m := dao.genQ.Client
q := dao.genQ.Client.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID), m.AppID.Eq(appID), m.CurrentReleaseID.Neq(0))
var err error
Expand All @@ -245,7 +296,7 @@ func (dao *clientDao) ListClientGroupByCurrentReleaseID(kit *kit.Kit, bizID uint
}
}

var items []types.ClientConfigVersionChart
var items []types.CurrentConfigVersionChart
err = q.Select(m.CurrentReleaseID, m.ID.Count().As("count")).Where(conds...).
Group(m.CurrentReleaseID).
Scan(&items)
Expand Down
24 changes: 12 additions & 12 deletions bcs-services/bcs-bscp/pkg/i18n/translations/catalog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{
"id": "decompress the file. The size of file {Message} exceeds the maximum limit of {MB}",
"message": "decompress the file. The size of file {Message} exceeds the maximum limit of {MB}",
"translation": "解压文件失败,文件 {Message} 的大小超过了最大限制闽值 {MB}",
"translation": "解压文件失败,文件 {Message} 的大小超过了最大限制阈值 {MB}",
"placeholders": [
{
"id": "Message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{
"id": "decompress the file. The size of file {Message} exceeds the maximum limit of {MB}",
"message": "decompress the file. The size of file {Message} exceeds the maximum limit of {MB}",
"translation": "解压文件失败,文件 {Message} 的大小超过了最大限制闽值 {MB}",
"translation": "解压文件失败,文件 {Message} 的大小超过了最大限制阈值 {MB}",
"placeholders": [
{
"id": "Message",
Expand Down
10 changes: 8 additions & 2 deletions bcs-services/bcs-bscp/pkg/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ const (
Bar ChartType = "bar"
)

// ClientConfigVersionChart 客户端配置图表
type ClientConfigVersionChart struct {
// CurrentConfigVersionChart 当前版本配置图表
type CurrentConfigVersionChart struct {
CurrentReleaseID uint32 `json:"current_release_id"`
Count int `json:"count"`
}

// TargetConfigVersionChart 目标版本配置图表
type TargetConfigVersionChart struct {
TargetReleaseID uint32 `json:"target_release_id"`
Count int `json:"count"`
}

// ChangeStatusChart 客户端变更状态图表
type ChangeStatusChart struct {
ReleaseChangeStatus string `json:"release_change_status"`
Expand Down

0 comments on commit bd3f870

Please sign in to comment.