Skip to content

Commit

Permalink
feat: BCS共享集群-添加更多日志 --story=119412655 (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
EASYGOING45 authored Aug 28, 2024
1 parent cac7eb4 commit dfed0e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestSpacePusher_composeBcsSpaceClusterTableIds(t *testing.T) {
{"cluster_id": "BCS-K8S-00003", "namespace": [], "cluster_type": "shared"}]`
spaceResource := space.SpaceResource{
Id: 207,
SpaceTypeId: "bkci",
SpaceTypeId: models.SpaceTypeBKCI,
SpaceId: "monitor",
ResourceType: "bcs",
ResourceId: &resourceId,
Expand Down Expand Up @@ -760,11 +760,12 @@ func TestComposeEsTableIdOptions(t *testing.T) {
assert.NoError(t, rtOp3.Create(db))

// 获取正常数据
data := SpacePusher{}.composeEsTableIdOptions([]string{rt1, rt2, rt3})
spacePusher := NewSpacePusher()
data := spacePusher.composeEsTableIdOptions([]string{rt1, rt2, rt3})
assert.Equal(t, 3, len(data))
assert.Equal(t, map[string]interface{}{"name": "v1"}, data[rt1][rtOp1.Name])

// 获取不存在的rt数据
data = SpacePusher{}.composeEsTableIdOptions([]string{"not_exist"})
data = spacePusher.composeEsTableIdOptions([]string{"not_exist"})
assert.Equal(t, 0, len(data))
}
8 changes: 6 additions & 2 deletions pkg/bk-monitor-worker/utils/optionx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (o *Options) GetStringSlice(key string) ([]string, bool) {
if !ok {
return nil, false
}
// 针对Single集群,namespace存在为None的场景
if value == nil {
return nil, true
}

switch v := value.(type) {
case []string:
Expand All @@ -104,14 +108,14 @@ func (o *Options) GetStringSlice(key string) ([]string, bool) {
for i, item := range v {
str, ok := item.(string)
if !ok {
logger.Errorf("Invalid type for key %s, slice failed", key)
logger.Errorf("Invalid type for key %s, got %T; overall value: %#v", key, item, v)
return nil, false
}
strSlice[i] = str
}
return strSlice, true
default:
logger.Errorf("Invalid type for key %s, slice failed", key)
logger.Errorf("Invalid type for key %s, got %T", key, value)
return nil, false
}
}
Expand Down

0 comments on commit dfed0e7

Please sign in to comment.