Skip to content

Commit b809b14

Browse files
authored
feat: extend indexer with prefix matching and db persistence (#1422)
* feat: extend indexer with prefix matching and db persistence * refactor: remove in-memory index from GormStore and add operator field * fix: copilot review suggestion and service panic * update
1 parent 5c94d18 commit b809b14

25 files changed

Lines changed: 1391 additions & 587 deletions

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ toolchain go1.24.11
2222
require (
2323
dubbo.apache.org/dubbo-go/v3 v3.0.0-20260210015753-35ea886421f9
2424
github.com/apache/dubbo-go-hessian2 v1.12.5
25+
github.com/armon/go-radix v1.0.0
2526
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
2627
github.com/duke-git/lancet/v2 v2.3.6
2728
github.com/envoyproxy/go-control-plane/envoy v1.32.4

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ github.com/apolloconfig/agollo/v4 v4.4.0/go.mod h1:6WjI68IzqMk/Y6ghMtrj5AX6Uewo2
151151
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
152152
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
153153
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
154+
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
154155
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
155156
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
156157
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=

pkg/console/service/application.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ func GetApplicationDetail(ctx consolectx.Context, req *model.ApplicationDetailRe
4242
instanceResources, err := manager.ListByIndexes[*meshresource.InstanceResource](
4343
ctx.ResourceManager(),
4444
meshresource.InstanceKind,
45-
map[string]string{
46-
index.ByMeshIndex: req.Mesh,
47-
index.ByInstanceAppNameIndex: req.AppName,
45+
[]index.IndexCondition{
46+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
47+
{IndexName: index.ByInstanceAppNameIndex, Value: req.AppName, Operator: index.Equals},
4848
},
4949
)
5050
if err != nil {
@@ -68,9 +68,9 @@ func GetAppInstanceInfo(ctx consolectx.Context, req *model.ApplicationTabInstanc
6868
pageData, err := manager.PageListByIndexes[*meshresource.InstanceResource](
6969
ctx.ResourceManager(),
7070
meshresource.InstanceKind,
71-
map[string]string{
72-
index.ByMeshIndex: req.Mesh,
73-
index.ByInstanceAppNameIndex: req.AppName,
71+
[]index.IndexCondition{
72+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
73+
{IndexName: index.ByInstanceAppNameIndex, Value: req.AppName, Operator: index.Equals},
7474
},
7575
req.PageReq,
7676
)
@@ -120,23 +120,28 @@ func GetAppServiceInfo(ctx consolectx.Context, req *model.ApplicationServiceForm
120120
}
121121

122122
func getAppProvideServiceInfo(ctx consolectx.Context, req *model.ApplicationServiceFormReq) (*model.SearchPaginationResult, error) {
123-
var indexes map[string]string
123+
var conditions []index.IndexCondition
124+
conditions = append(conditions, index.IndexCondition{
125+
IndexName: index.ByMeshIndex,
126+
Value: req.Mesh,
127+
Operator: index.Equals,
128+
})
129+
conditions = append(conditions, index.IndexCondition{
130+
IndexName: index.ByServiceProviderAppName,
131+
Value: req.AppName,
132+
Operator: index.Equals,
133+
})
124134
if strutil.IsNotBlank(req.ServiceName) {
125-
indexes = map[string]string{
126-
index.ByMeshIndex: req.Mesh,
127-
index.ByServiceProviderAppName: req.AppName,
128-
index.ByServiceProviderServiceName: req.ServiceName,
129-
}
130-
} else {
131-
indexes = map[string]string{
132-
index.ByMeshIndex: req.Mesh,
133-
index.ByServiceProviderAppName: req.AppName,
134-
}
135+
conditions = append(conditions, index.IndexCondition{
136+
IndexName: index.ByServiceProviderServiceName,
137+
Value: req.ServiceName,
138+
Operator: index.Equals,
139+
})
135140
}
136141
pageData, err := manager.PageListByIndexes[*meshresource.ServiceProviderMetadataResource](
137142
ctx.ResourceManager(),
138143
meshresource.ServiceProviderMetadataKind,
139-
indexes,
144+
conditions,
140145
req.PageReq,
141146
)
142147
if err != nil {
@@ -167,9 +172,9 @@ func getAppConsumeServiceInfo(ctx consolectx.Context, req *model.ApplicationServ
167172
pageData, err := manager.PageListByIndexes[*meshresource.ServiceConsumerMetadataResource](
168173
ctx.ResourceManager(),
169174
meshresource.ServiceConsumerMetadataKind,
170-
map[string]string{
171-
index.ByMeshIndex: req.Mesh,
172-
index.ByServiceConsumerAppName: req.AppName,
175+
[]index.IndexCondition{
176+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
177+
{IndexName: index.ByServiceConsumerAppName, Value: req.AppName, Operator: index.Equals},
173178
},
174179
req.PageReq,
175180
)
@@ -220,8 +225,8 @@ func SearchApplications(ctx consolectx.Context, req *model.ApplicationSearchReq)
220225
pageData, err := manager.PageListByIndexes[*meshresource.ApplicationResource](
221226
ctx.ResourceManager(),
222227
meshresource.ApplicationKind,
223-
map[string]string{
224-
index.ByMeshIndex: req.Mesh,
228+
[]index.IndexCondition{
229+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
225230
},
226231
req.PageReq,
227232
)

pkg/console/service/condition_rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func SearchConditionRules(ctx context.Context, req *model.SearchConditionRuleReq
4040
pageData, err := manager.PageListByIndexes[*meshresource.ConditionRouteResource](
4141
ctx.ResourceManager(),
4242
meshresource.ConditionRouteKind,
43-
map[string]string{
44-
index.ByMeshIndex: req.Mesh,
43+
[]index.IndexCondition{
44+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
4545
},
4646
req.PageReq)
4747
if err != nil {

pkg/console/service/configurator_rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func PageListConfiguratorRule(ctx consolectx.Context, req *model.SearchReq) (*mo
3636
pageData, err := manager.PageListByIndexes[*meshresource.DynamicConfigResource](
3737
ctx.ResourceManager(),
3838
meshresource.DynamicConfigKind,
39-
map[string]string{
40-
index.ByMeshIndex: req.Mesh,
39+
[]index.IndexCondition{
40+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
4141
},
4242
req.PageReq)
4343
if err != nil {

pkg/console/service/instance.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ func SearchInstanceByIp(ctx consolectx.Context, req *model.SearchReq) (*model.Se
4444
pageData, err := manager.PageListByIndexes[*meshresource.InstanceResource](
4545
ctx.ResourceManager(),
4646
meshresource.InstanceKind,
47-
map[string]string{
48-
index.ByMeshIndex: req.Mesh,
49-
index.ByInstanceIpIndex: req.Keywords,
47+
[]index.IndexCondition{
48+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
49+
{IndexName: index.ByInstanceIpIndex, Value: req.Keywords, Operator: index.HasPrefix},
5050
},
5151
req.PageReq)
5252
if err != nil {
5353
return nil, err
5454
}
5555
if pageData.Data == nil || len(pageData.Data) == 0 {
5656
return &model.SearchPaginationResult{
57-
List: []*meshresource.ServiceProviderMetadataResourceList{},
57+
List: []*model.SearchInstanceResp{},
5858
PageInfo: coremodel.Pagination{
5959
Total: 0,
6060
PageSize: req.PageReq.PageSize,
@@ -63,8 +63,8 @@ func SearchInstanceByIp(ctx consolectx.Context, req *model.SearchReq) (*model.Se
6363
}, nil
6464
}
6565
return &model.SearchPaginationResult{
66-
List: slice.Map(pageData.Data, func(_ int, item *meshresource.InstanceResource) *model.AppInstanceInfoResp {
67-
return buildAppInstanceInfoResp(item, ctx.Config())
66+
List: slice.Map(pageData.Data, func(_ int, item *meshresource.InstanceResource) *model.SearchInstanceResp {
67+
return model.NewSearchInstanceResp().FromInstanceResource(item, ctx.Config())
6868
}),
6969
PageInfo: pageData.Pagination,
7070
}, nil
@@ -75,17 +75,17 @@ func SearchInstanceByName(ctx consolectx.Context, req *model.SearchReq) (*model.
7575
pageData, err := manager.PageListByIndexes[*meshresource.InstanceResource](
7676
ctx.ResourceManager(),
7777
meshresource.InstanceKind,
78-
map[string]string{
79-
index.ByMeshIndex: req.Mesh,
80-
index.ByInstanceNameIndex: req.Keywords,
78+
[]index.IndexCondition{
79+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
80+
{IndexName: index.ByInstanceNameIndex, Value: req.Keywords, Operator: index.HasPrefix},
8181
},
8282
req.PageReq)
8383
if err != nil {
8484
return nil, err
8585
}
8686
if pageData.Data == nil || len(pageData.Data) == 0 {
8787
return &model.SearchPaginationResult{
88-
List: []*meshresource.ServiceProviderMetadataResourceList{},
88+
List: []*model.SearchInstanceResp{},
8989
PageInfo: coremodel.Pagination{
9090
Total: 0,
9191
PageSize: req.PageReq.PageSize,
@@ -94,8 +94,8 @@ func SearchInstanceByName(ctx consolectx.Context, req *model.SearchReq) (*model.
9494
}, nil
9595
}
9696
return &model.SearchPaginationResult{
97-
List: slice.Map(pageData.Data, func(_ int, item *meshresource.InstanceResource) *model.AppInstanceInfoResp {
98-
return buildAppInstanceInfoResp(item, ctx.Config())
97+
List: slice.Map(pageData.Data, func(_ int, item *meshresource.InstanceResource) *model.SearchInstanceResp {
98+
return model.NewSearchInstanceResp().FromInstanceResource(item, ctx.Config())
9999
}),
100100
PageInfo: pageData.Pagination,
101101
}, nil
@@ -113,8 +113,8 @@ func SearchInstances(ctx consolectx.Context, req *model.SearchInstanceReq) (*mod
113113
pageData, err := manager.PageListByIndexes[*meshresource.InstanceResource](
114114
ctx.ResourceManager(),
115115
meshresource.InstanceKind,
116-
map[string]string{
117-
index.ByMeshIndex: req.Mesh,
116+
[]index.IndexCondition{
117+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
118118
},
119119
req.PageReq)
120120
if err != nil {

pkg/console/service/service.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ import (
4141

4242
// GetServiceTabDistribution get service distribution
4343
func GetServiceTabDistribution(ctx consolectx.Context, req *model.ServiceTabDistributionReq) (*model.SearchPaginationResult, error) {
44-
indexes := map[string]string{
45-
index.ByServiceConsumerServiceName: req.ServiceName,
44+
conditions := []index.IndexCondition{
45+
{IndexName: index.ByServiceConsumerServiceName, Value: req.ServiceName, Operator: index.Equals},
4646
}
4747
// for now, only support accurate name match
4848
if strutil.IsNotBlank(req.Keywords) {
49-
indexes[index.ByServiceConsumerAppName] = req.Keywords
49+
conditions = append(conditions, index.IndexCondition{
50+
IndexName: index.ByServiceConsumerAppName,
51+
Value: req.Keywords,
52+
Operator: index.Equals,
53+
})
5054
}
5155
pageData, err := manager.PageListByIndexes[*meshresource.ServiceConsumerMetadataResource](
5256
ctx.ResourceManager(),
5357
meshresource.ServiceConsumerMetadataKind,
54-
indexes,
58+
conditions,
5559
req.PageReq)
5660
if err != nil {
5761
logger.Errorf("get service consumer %s failed, cause: %v", req.ServiceName, err)
@@ -98,8 +102,8 @@ func SearchServices(ctx consolectx.Context, req *model.ServiceSearchReq) (*model
98102
pageData, err := manager.PageListByIndexes[*meshresource.ServiceProviderMetadataResource](
99103
ctx.ResourceManager(),
100104
meshresource.ServiceProviderMetadataKind,
101-
map[string]string{
102-
index.ByMeshIndex: req.Mesh,
105+
[]index.IndexCondition{
106+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
103107
},
104108
req.PageReq,
105109
)
@@ -120,14 +124,14 @@ func SearchServices(ctx consolectx.Context, req *model.ServiceSearchReq) (*model
120124
}, nil
121125
}
122126

123-
// SearchServicesByKeywords search services by keywords, for now only support accurate search
127+
// SearchServicesByKeywords search services by keywords with prefix matching
124128
func SearchServicesByKeywords(ctx consolectx.Context, req *model.ServiceSearchReq) (*model.SearchPaginationResult, error) {
125129
pageData, err := manager.PageListByIndexes[*meshresource.ServiceProviderMetadataResource](
126130
ctx.ResourceManager(),
127131
meshresource.ServiceProviderMetadataKind,
128-
map[string]string{
129-
index.ByMeshIndex: req.Mesh,
130-
index.ByServiceProviderServiceName: req.Keywords,
132+
[]index.IndexCondition{
133+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
134+
{IndexName: index.ByServiceProviderServiceName, Value: req.Keywords, Operator: index.HasPrefix},
131135
},
132136
req.PageReq,
133137
)
@@ -190,10 +194,10 @@ func GetServiceMethodDetail(ctx consolectx.Context, req model.ServiceMethodDetai
190194
}
191195

192196
// providerIndexes defines the canonical indexes for provider metadata
193-
func providerIndexes(req model.BaseServiceReq) map[string]string {
194-
return map[string]string{
195-
index.ByMeshIndex: req.Mesh,
196-
index.ByServiceProviderServiceKey: req.ServiceKey(),
197+
func providerIndexes(req model.BaseServiceReq) []index.IndexCondition {
198+
return []index.IndexCondition{
199+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
200+
{IndexName: index.ByServiceProviderServiceKey, Value: req.ServiceKey(), Operator: index.Equals},
197201
}
198202
}
199203

pkg/console/service/service_provider_instances.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func GetServiceProviderInstances(ctx consolectx.Context, req model.BaseServiceRe
5050
instanceList, err := manager.ListByIndexes[*meshresource.InstanceResource](
5151
ctx.ResourceManager(),
5252
meshresource.InstanceKind,
53-
map[string]string{
54-
index.ByMeshIndex: req.Mesh,
55-
index.ByInstanceAppNameIndex: providerAppName,
53+
[]index.IndexCondition{
54+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
55+
{IndexName: index.ByInstanceAppNameIndex, Value: providerAppName, Operator: index.Equals},
5656
},
5757
)
5858
if err != nil {

pkg/console/service/tag_rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func PageListTagRule(ctx consolectx.Context, req *model.SearchReq) (*model.Searc
3636
pageData, err := manager.PageListByIndexes[*meshresource.TagRouteResource](
3737
ctx.ResourceManager(),
3838
meshresource.TagRouteKind,
39-
map[string]string{
40-
index.ByMeshIndex: req.Mesh,
39+
[]index.IndexCondition{
40+
{IndexName: index.ByMeshIndex, Value: req.Mesh, Operator: index.Equals},
4141
},
4242
req.PageReq)
4343
if err != nil {

pkg/core/bootstrap/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
_ "github.com/apache/dubbo-admin/pkg/discovery/zk"
3333
_ "github.com/apache/dubbo-admin/pkg/engine/kubernetes"
3434
_ "github.com/apache/dubbo-admin/pkg/engine/mock"
35+
_ "github.com/apache/dubbo-admin/pkg/governor/mock"
3536
_ "github.com/apache/dubbo-admin/pkg/governor/nacos2"
3637
_ "github.com/apache/dubbo-admin/pkg/governor/zk"
3738
_ "github.com/apache/dubbo-admin/pkg/store/memory"

0 commit comments

Comments
 (0)