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

feat: BMW: SPACE_TO_RESULT_TABLE_KEY中针对非二段式TableId,补充.__default__ --story=122006276 #701

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/bk-monitor-worker/internal/metadata/service/spaceredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,19 @@ func (s *SpacePusher) composeData(spaceType, spaceId string, tableIdList []strin
}
for _, tid := range tableIds {
// NOTE: 特殊逻辑,忽略跨空间类型的 bkci 的结果表
parts := strings.Split(tid, ".")

// 针对非二段式TableId,补充.__default__
if len(parts) == 1 {
// 如果长度为 1,补充 `.__default__`
logger.Infof("composeData: table_id [%s] is missing '.', adding '.__default__'", tid)
tid = fmt.Sprintf("%s.__default__", tid)
} else if len(parts) != 2 {
// 如果长度不是 2,记录错误日志并跳过此 tableId
logger.Errorf("composeData: table_id [%s] is invalid, contains too many dots", tid)
continue
}

if strings.HasPrefix(tid, models.Bkci1001TableIdPrefix) {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ func TestSpacePusher_ComposeData(t *testing.T) {
spaceType := "bkcc"
spaceId := "1001"
tableID1 := "1001_bkmonitor_time_series_50010.__default__"
tableID2 := "1001_bkmonitor_time_series_50011.__default__"
tableID2 := "1001_bkmonitor_time_series_50011"
tableID3 := "1001_bkmonitor_time_series_50012.__default__"
var defaultFilters []map[string]interface{}

Expand Down Expand Up @@ -1305,7 +1305,7 @@ func TestSpacePusher_ComposeData(t *testing.T) {

expectedForCreator := map[string]map[string]interface{}{
tableID1: {"filters": []map[string]interface{}{}},
tableID2: {"filters": []map[string]interface{}{}},
"1001_bkmonitor_time_series_50011.__default__": {"filters": []map[string]interface{}{}},
}
assert.Equal(t, expectedForCreator, valuesForCreator, "Unexpected result for space 1001")

Expand All @@ -1315,7 +1315,7 @@ func TestSpacePusher_ComposeData(t *testing.T) {

expectedForOthers := map[string]map[string]interface{}{
tableID1: {"filters": []map[string]interface{}{{"appid": "1003"}}},
tableID2: {"filters": []map[string]interface{}{{"bk_biz_id": "1003"}}},
"1001_bkmonitor_time_series_50011.__default__": {"filters": []map[string]interface{}{{"bk_biz_id": "1003"}}},
}
assert.Equal(t, expectedForOthers, valuesForOthers, "Unexpected result for space 1003")
}
Expand Down