Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
017e6fb
feat: 支持surrealDB图关联查询 --story=133245352
Zhaoyikaiii Jul 7, 2026
e13fe30
refactor: remove unused v1beta3 path response code
Zhaoyikaiii Jul 7, 2026
b7c2da5
fix: align v1beta3 path compatibility
Zhaoyikaiii Jul 7, 2026
23e205b
fix: split v1beta3 range path queries
Zhaoyikaiii Jul 7, 2026
c9c235b
refactor: simplify v1beta3 resource paths
Zhaoyikaiii Jul 8, 2026
05b5e34
test: add surrealdb path split query mock coverage
Zhaoyikaiii Jul 8, 2026
92abcf0
fix: address v1beta3 path split review comments
Zhaoyikaiii Jul 8, 2026
ff3124f
fix: address remaining v1beta3 codex review threads
Zhaoyikaiii Jul 8, 2026
35f6075
docs: clarify v1beta3 graph query path handling
Zhaoyikaiii Jul 8, 2026
4ccaf3b
feat: merge v1beta3 path split graph results
Zhaoyikaiii Jul 8, 2026
5301071
perf: reduce v1beta3 path query overhead
Zhaoyikaiii Jul 8, 2026
1c4b9bd
perf: omit instant graph liveness projection
Zhaoyikaiii Jul 8, 2026
21ebeba
feat(unify-query): add active edge serving relation routing
Zhaoyikaiii Jul 21, 2026
4c776f9
fix(unify-query): restore instant relation targets
Zhaoyikaiii Jul 21, 2026
1e2d0cd
fix(unify-query): address v1beta3 review findings
Zhaoyikaiii Jul 21, 2026
11761cc
fix(unify-query): harden v1beta3 relation queries
Zhaoyikaiii Jul 22, 2026
42d6e66
fix(unify-query): address v1beta3 review findings
Zhaoyikaiii Aug 7, 2026
2ed3058
fix(unify-query): adapt bkbase direct graph rows
Zhaoyikaiii Aug 10, 2026
8095d8c
fix(unify-query): normalize bkbase graph rows
Zhaoyikaiii Aug 10, 2026
6e3d58f
fix(unify-query): handle missing surreal root records
Zhaoyikaiii Aug 10, 2026
48c8b0e
feat(unify-query): expose surreal dsl in trace
Zhaoyikaiii Aug 11, 2026
c2b2564
fix(unify-query): 完善 v1beta3 物化关系路由
Zhaoyikaiii Aug 12, 2026
76eae77
feat(unify-query): 支持单跳关系优先查询 VM
Zhaoyikaiii Aug 12, 2026
b56c224
Merge remote-tracking branch 'upstream/master' into codex/pr-1282-act…
Zhaoyikaiii Aug 12, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,42 @@ func (m *MockSchemaProvider) ListResourceDefinitions(namespace string) ([]*relat
return result, nil
}

func (m *MockSchemaProvider) Name() string {
return "mock"
}

func (m *MockSchemaProvider) ListNamespaces() ([]string, error) {
seen := make(map[string]struct{})
for _, def := range m.resourceDefs {
seen[def.Namespace] = struct{}{}
}
for _, def := range m.relationDefs {
seen[def.Namespace] = struct{}{}
}
result := make([]string, 0, len(seen))
for namespace := range seen {
result = append(result, namespace)
}
sort.Strings(result)
return result, nil
}

func (m *MockSchemaProvider) ListAllResourceDefinitions() (map[string][]*relation.ResourceDefinition, error) {
result := make(map[string][]*relation.ResourceDefinition)
for _, def := range m.resourceDefs {
result[def.Namespace] = append(result[def.Namespace], def)
}
return result, nil
}

func (m *MockSchemaProvider) ListAllRelationDefinitions() (map[string][]*relation.RelationDefinition, error) {
result := make(map[string][]*relation.RelationDefinition)
for _, def := range m.relationDefs {
result[def.Namespace] = append(result[def.Namespace], def)
}
return result, nil
}

func (m *MockSchemaProvider) GetResourcePrimaryKeys(resourceType relation.ResourceType) []string {
for _, def := range m.resourceDefs {
if def.Name == string(resourceType) {
Expand Down
12 changes: 11 additions & 1 deletion pkg/unify-query/cmdb/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Relation struct {
V []Resource
}

// Path 关联路径
// Path 关联路径 (v1)
type Path []Relation

// Paths 多组关联路径
Expand Down Expand Up @@ -66,6 +66,11 @@ type RelationMultiResourceResponseData struct {
TargetList Matchers `json:"target_list"`
Path []string `json:"path"`
Message string `json:"message"`

// Truncated 表示响应是否因服务端安全上限而被截断。
Truncated bool `json:"truncated,omitempty"`
// TruncatedReason 标识触发截断的具体上限,便于调用方区分处理。
TruncatedReason string `json:"truncated_reason,omitempty"`
}

// RelationMultiResourceResponse 请求返回
Expand Down Expand Up @@ -104,6 +109,11 @@ type RelationMultiResourceRangeResponseData struct {
TargetList []MatchersWithTimestamp `json:"target_list"`
Path []string `json:"path"`
Message string `json:"message"`

// Truncated 表示响应是否因服务端安全上限而被截断。
Truncated bool `json:"truncated,omitempty"`
// TruncatedReason 标识触发截断的具体上限,便于调用方区分处理。
TruncatedReason string `json:"truncated_reason,omitempty"`
}

// RelationMultiResourceRangeResponse 请求返回
Expand Down
3 changes: 3 additions & 0 deletions pkg/unify-query/cmdb/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func buildConfigData() *Config {

relations := make([]RelationConf, 0, len(relation.DefaultRelationDefinitions()))
for _, rd := range relation.DefaultRelationDefinitions() {
if relation.ToRelationCategory(rd.Category) == relation.RelationCategoryDynamic {
continue
}
relations = append(relations, RelationConf{
Resources: []cmdb.Resource{
cmdb.Resource(rd.FromResource),
Expand Down
3 changes: 3 additions & 0 deletions pkg/unify-query/cmdb/v1beta1/config_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func convertRelationDefinition(rd *relation.RelationDefinition) (RelationConf, b
if rd.FromResource == "" || rd.ToResource == "" {
return RelationConf{}, false
}
if relation.ToRelationCategory(rd.Category) == relation.RelationCategoryDynamic {
return RelationConf{}, false
}
return RelationConf{
Resources: []cmdb.Resource{
cmdb.Resource(rd.FromResource),
Expand Down
13 changes: 13 additions & 0 deletions pkg/unify-query/cmdb/v1beta1/config_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,17 @@ func TestConvertRelationDefinition(t *testing.T) {
_, ok := convertRelationDefinition(rd)
assert.False(t, ok)
})

t.Run("dynamic relation", func(t *testing.T) {
rd := &relation.RelationDefinition{
Namespace: "",
Name: "system_to_pod",
FromResource: "system",
ToResource: "pod",
Category: string(relation.RelationCategoryDynamic),
}

_, ok := convertRelationDefinition(rd)
assert.False(t, ok)
})
}
34 changes: 27 additions & 7 deletions pkg/unify-query/cmdb/v1beta1/v1beta1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ import (
"github.com/TencentBlueKing/bkmonitor-datalink/pkg/utils/relation"
)

var testModel, _ = newModel(context.Background(), configData)
var testModel = mustNewTestModel()

func mustNewTestModel() *model {
m, err := newModel(context.Background(), configData)
if err != nil {
panic(err)
}
return m
}

func TestModel_Resources(t *testing.T) {
mock.Init()
ctx := metadata.InitHashID(context.Background())
resources, err := testModel.resources(ctx)

assert.Nil(t, err)
assert.Equal(t, []cmdb.Resource{"apm_service", "apm_service_instance", "app_version", "bklogconfig", "business", "container", "daemonset", "datasource", "deployment", "domain", "git_commit", "host", "ingress", "job", "k8s_address", "module", "node", "p4_changelist", "pod", "replicaset", "service", "set", "statefulset", "svn_revision", "system"}, resources)
assert.Equal(t, []cmdb.Resource{"apm_service", "apm_service_instance", "app_version", "biz", "bklogconfig", "business", "container", "daemonset", "datasource", "deployment", "domain", "git_commit", "host", "ingress", "job", "k8s_address", "module", "node", "p4_changelist", "pod", "replicaset", "service", "set", "statefulset", "svn_revision", "system"}, resources)
}

func TestModel_GetResources(t *testing.T) {
Expand Down Expand Up @@ -79,6 +87,18 @@ func TestModel_GetPath(t *testing.T) {
{"apm_service", "apm_service_instance", "pod", "container", "app_version", "host", "system"},
},
},
"legacy business to set": {
target: "set",
matcher: cmdb.Matcher{
"bk_biz_id": "2",
},
source: "business",
indexMatcher: cmdb.Matcher{"bk_biz_id": "2"},
allMatch: true,
expected: [][]string{
{"business", "set"},
},
},
"apm_service to system through wrong service": {
target: "system",
matcher: cmdb.Matcher{
Expand Down Expand Up @@ -868,8 +888,8 @@ func TestInitSchemaProvider_MultiNamespace(t *testing.T) {
{Namespace: "bkcc__2", Name: "node", Fields: []relation.FieldDefinition{{Name: "bcs_cluster_id", Required: true}, {Name: "node", Required: true}}},
},
[]*relation.RelationDefinition{
{Namespace: "__all__", Name: "host_system", FromResource: "host", ToResource: "system"},
{Namespace: "bkcc__2", Name: "node_pod", FromResource: "node", ToResource: "pod"},
{Namespace: "__all__", Name: "host_with_system", FromResource: "host", ToResource: "system"},
{Namespace: "bkcc__2", Name: "node_with_pod", FromResource: "node", ToResource: "pod"},
},
)

Expand Down Expand Up @@ -922,7 +942,7 @@ func TestReloadNamespaceModel_AsyncUpdate(t *testing.T) {
{Namespace: "bkcc__2", Name: "node", Fields: []relation.FieldDefinition{{Name: "node", Required: true}}},
},
[]*relation.RelationDefinition{
{Namespace: "bkcc__2", Name: "pod_node", FromResource: "pod", ToResource: "node"},
{Namespace: "bkcc__2", Name: "node_with_pod", FromResource: "node", ToResource: "pod"},
},
)

Expand Down Expand Up @@ -1003,8 +1023,8 @@ func TestNamespaceIsolation_GraphIndependent(t *testing.T) {
{Namespace: "bkcc__2", Name: "node", Fields: []relation.FieldDefinition{{Name: "node", Required: true}}},
},
[]*relation.RelationDefinition{
{Namespace: "__all__", Name: "host_system", FromResource: "host", ToResource: "system"},
{Namespace: "bkcc__2", Name: "pod_node", FromResource: "pod", ToResource: "node"},
{Namespace: "__all__", Name: "host_with_system", FromResource: "host", ToResource: "system"},
{Namespace: "bkcc__2", Name: "node_with_pod", FromResource: "node", ToResource: "pod"},
},
)

Expand Down
Loading