Skip to content

feat: support query service consumers & fix admin query bug #652

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

Merged
merged 11 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module github.com/apache/dubbo-kubernetes
go 1.23.0

require (
dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1.0.20240926033233-f03922ab1bcb
dubbo.apache.org/dubbo-go/v3 v3.3.0
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.2.1
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
Expand Down Expand Up @@ -46,7 +46,6 @@ require (
github.com/go-logr/zapr v1.3.0
github.com/go-sql-driver/mysql v1.7.0
github.com/goburrow/cache v0.1.4
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
Expand Down Expand Up @@ -133,7 +132,7 @@ require (
github.com/alibaba/sentinel-golang v1.0.4 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 // indirect
github.com/apache/dubbo-getty v1.4.10 // indirect
github.com/apache/dubbo-go-hessian2 v1.12.2 // indirect
github.com/apache/dubbo-go-hessian2 v1.12.5 // indirect
github.com/apex/log v1.9.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.27 // indirect
Expand Down Expand Up @@ -182,7 +181,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 // indirect
github.com/dubbogo/grpc-go v1.42.10 // indirect
github.com/dubbogo/triple v1.2.2-rc3 // indirect
github.com/dubbogo/triple v1.2.2-rc4 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
Expand All @@ -209,6 +208,7 @@ require (
github.com/gobuffalo/flect v1.0.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1.0.20240926033233-f03922ab1bcb h1:pcd2OAuo5NZuglupBFpXEjvH6NlWyHy6pwlPDAwVUFw=
dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1.0.20240926033233-f03922ab1bcb/go.mod h1:ECpY0g32XJMG2irWj6wttH94zA5QU70Alc5hmOyXgu4=
dubbo.apache.org/dubbo-go/v3 v3.3.0 h1:jhwK4nQ1DsKQ6H9p7icZx0jg9ulF1vpAA/c0Ly8Et4w=
dubbo.apache.org/dubbo-go/v3 v3.3.0/go.mod h1:zu2m9tUGaZYfuaMX82pLlwmq7Vl4s5eenZNBGdfAagc=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
Expand Down Expand Up @@ -134,8 +134,8 @@ github.com/apache/dubbo-getty v1.4.10 h1:ZmkpHJa/qgS0evX2tTNqNCz6rClI/9Wwp7ctyMm
github.com/apache/dubbo-getty v1.4.10/go.mod h1:V64WqLIxksEgNu5aBJBOxNIvpOZyfUJ7J/DXBlKSUoA=
github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
github.com/apache/dubbo-go-hessian2 v1.9.3/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE=
github.com/apache/dubbo-go-hessian2 v1.12.2 h1:2/56JRPng2lnLziJF3fqmSgsg28Yt1a5YZ5RX+jHDGs=
github.com/apache/dubbo-go-hessian2 v1.12.2/go.mod h1:QP9Tc0w/B/mDopjusebo/c7GgEfl6Lz8jeuFg8JA6yw=
github.com/apache/dubbo-go-hessian2 v1.12.5 h1:19lJz2Md0EYF2bOtEvFqXEQRYvLz04GfsoocsBWlLWQ=
github.com/apache/dubbo-go-hessian2 v1.12.5/go.mod h1:QP9Tc0w/B/mDopjusebo/c7GgEfl6Lz8jeuFg8JA6yw=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
Expand Down Expand Up @@ -377,8 +377,8 @@ github.com/dubbogo/grpc-go v1.42.10/go.mod h1:JMkPt1mIHL96GAFeYsMoMjew6f1ROKycik
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc=
github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw=
github.com/dubbogo/triple v1.2.2-rc3 h1:9rxLqru35MmJkypCHJMiZb1VzwH+zmbPBend9Cq+VOI=
github.com/dubbogo/triple v1.2.2-rc3/go.mod h1:9pgEahtmsY/avYJp3dzUQE8CMMVe1NtGBmUhfICKLJk=
github.com/dubbogo/triple v1.2.2-rc4 h1:zL15Fb6W/yNAFQve5eqpTOEWWD9dpTFq78mdeSKc2pk=
github.com/dubbogo/triple v1.2.2-rc4/go.mod h1:9pgEahtmsY/avYJp3dzUQE8CMMVe1NtGBmUhfICKLJk=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
19 changes: 13 additions & 6 deletions pkg/admin/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ package constants

// Registry Constants
const (
RegistryKey = "registry"
RegistryClusterKey = "REGISTRY_CLUSTER"
RegisterModeKey = "register-mode"
RegistryClusterTypeKey = "registry-cluster-type"

RegistryKey = "registry"
RegistryClusterKey = "REGISTRY_CLUSTER"
RegisterModeKey = "register-mode"
RegistryClusterTypeKey = "registry-cluster-type"
RemoteClientNameKey = "remote-client-name"
DefaultRegisterModeInterface = "interface"
DefaultRegisterModeInstance = "instance"
DefaultRegisterModeAll = "all"
)

const (
SerializationKey = "serialization"
SerializationKey = "prefer.serialization"
)

const (
DubboVersionKey = "dubbo"
WorkLoadKey = "workLoad"
ReleaseKey = "release"
)

const (
Expand All @@ -53,3 +55,8 @@ const (
Instance = "instance"
Service = "service"
)

const (
Stateful = "有状态"
Stateless = "无状态"
)
19 changes: 13 additions & 6 deletions pkg/admin/model/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package model
import (
"encoding/json"
"fmt"
"regexp"
"strconv"
)

Expand Down Expand Up @@ -99,14 +100,21 @@ func (a *ApplicationDetail) MergeMetaData(metadata *mesh.MetaDataResource) {

func (a *ApplicationDetail) mergeServiceInfo(metadata *mesh.MetaDataResource) {
for _, serviceInfo := range metadata.Spec.Services {
a.DubboVersions.Add(fmt.Sprintf("dubbo %s", serviceInfo.Params[constants.DubboVersionKey]))
a.DubboVersions.Add(fmt.Sprintf("dubbo %s", serviceInfo.Params[constants.ReleaseKey]))
a.RPCProtocols.Add(serviceInfo.Protocol)
a.SerialProtocols.Add(serviceInfo.Params[constants.SerializationKey])

}
}

func (a *ApplicationDetail) MergeDatapalne(dataplane *mesh.DataplaneResource) {
// TODO: support more fields
a.AppTypes.Add("无状态")
func (a *ApplicationDetail) MergeDataplane(dataplane *mesh.DataplaneResource) {
if work, ok := dataplane.Spec.Extensions[constants.WorkLoadKey]; ok &&
regexp.MustCompile(`^.*-\d+$`).MatchString(work) {
a.AppTypes.Add(constants.Stateful)
} else {
a.AppTypes.Add(constants.Stateless)
}

inbounds := dataplane.Spec.Networking.Inbound
for _, inbound := range inbounds {
a.mergeInbound(inbound)
Expand All @@ -117,7 +125,6 @@ func (a *ApplicationDetail) MergeDatapalne(dataplane *mesh.DataplaneResource) {

func (a *ApplicationDetail) mergeInbound(inbound *v1alpha1.Dataplane_Networking_Inbound) {
a.DubboPorts.Add(strconv.Itoa(int(inbound.Port)))
a.RPCProtocols.Add(inbound.Tags[v1alpha1.ProtocolTag])
a.DeployClusters.Add(inbound.Tags[v1alpha1.ZoneTag])
}

Expand All @@ -135,7 +142,7 @@ func (a *ApplicationDetail) GetRegistry(rt core_runtime.Runtime) {
} else if runtimeMode == core.HalfHostMode || runtimeMode == core.UniversalMode {
// In half or universal mode, registry cluster is the zookeeper cluster or other registry center
registryURL := rt.RegistryCenter().GetURL()
registryCluster := registryURL.GetParam(constants.RegistryClusterKey, "")
registryCluster := registryURL.GetParam(constants.RemoteClientNameKey, "")
a.RegisterClusters.Add(registryCluster)

registryMode := registryURL.GetParam(constants.RegisterModeKey, constants.DefaultRegisterModeAll)
Expand Down
7 changes: 2 additions & 5 deletions pkg/admin/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,12 @@ func (r *ServiceTabDistributionResp) FromServiceDistribution(distribution *Servi
func (r *ServiceTabDistributionResp) mergeMetaData(metadata *core_mesh.MetaDataResource, req *ServiceTabDistributionReq) {
// key format is '{group}/{interface name}:{version}:{protocol}'
serviceinfos := metadata.Spec.Services
if req.Side == constants.ConsumerSide {
r.Retries = ""
r.TimeOut = ""
}

for _, serviceinfo := range serviceinfos {
if serviceinfo.Name == req.ServiceName &&
serviceinfo.Group == req.Group &&
serviceinfo.Version == req.Version &&
req.Side == constants.ProviderSide {
req.Side == serviceinfo.GetParams()[constants.ServiceInfoSide] {
r.Retries = serviceinfo.Params[constants.RetriesKey]
r.TimeOut = serviceinfo.Params[constants.TimeoutKey]
r.Params = serviceinfo.Params
Expand Down
65 changes: 38 additions & 27 deletions pkg/admin/service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package service

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"github.com/apache/dubbo-kubernetes/pkg/admin/constants"
"strconv"
"strings"
)

import (
mesh_proto "github.com/apache/dubbo-kubernetes/api/mesh/v1alpha1"
"github.com/apache/dubbo-kubernetes/pkg/admin/constants"
"github.com/apache/dubbo-kubernetes/pkg/admin/model"
"github.com/apache/dubbo-kubernetes/pkg/core/resources/apis/mesh"
"github.com/apache/dubbo-kubernetes/pkg/core/resources/store"
Expand All @@ -41,7 +43,10 @@ func GetApplicationDetail(rt core_runtime.Runtime, req *model.ApplicationDetailR
revisions := make(map[string]*mesh.MetaDataResource, 0)
applicationDetail := model.NewApplicationDetail()
for _, dataplane := range dataplaneList.Items {
rev, ok := dataplane.Spec.GetExtensions()[mesh_proto.Application]
if strings.Split(dataplane.GetMeta().GetName(), constant.KeySeparator)[1] == "0" {
continue
}
rev, ok := dataplane.Spec.GetExtensions()[mesh_proto.Revision]
if ok {
if metadata, cached := revisions[rev]; !cached {
metadata = &mesh.MetaDataResource{
Expand All @@ -54,7 +59,7 @@ func GetApplicationDetail(rt core_runtime.Runtime, req *model.ApplicationDetailR
applicationDetail.MergeMetaData(metadata)
}
}
applicationDetail.MergeDatapalne(dataplane)
applicationDetail.MergeDataplane(dataplane)
applicationDetail.GetRegistry(rt)
}

Expand All @@ -77,6 +82,9 @@ func GetApplicationTabInstanceInfo(rt core_runtime.Runtime, req *model.Applicati
res := model.NewSearchPaginationResult()
list := make([]*model.ApplicationTabInstanceInfoResp, 0, len(dataplaneList.Items))
for _, dataplane := range dataplaneList.Items {
if strings.Split(dataplane.Meta.GetName(), constant.KeySeparator)[1] == "0" {
continue
}
resItem := &model.ApplicationTabInstanceInfoResp{}
resItem.FromDataplaneResource(dataplane)
resItem.GetRegistry(rt)
Expand All @@ -102,32 +110,32 @@ func GetApplicationServiceFormInfo(rt core_runtime.Runtime, req *model.Applicati
revisions := make(map[string]*mesh.MetaDataResource, 0)
for _, dataplane := range dataplaneList.Items {
rev, ok := dataplane.Spec.GetExtensions()[mesh_proto.Revision]
if ok {
metadata, cached := revisions[rev]
if !cached {
metadata = &mesh.MetaDataResource{
Spec: &mesh_proto.MetaData{},
}
if err := manager.Get(rt.AppContext(), metadata, store.GetByRevision(rev), store.GetByType(dataplane.Spec.GetExtensions()["registry-type"])); err != nil {
return nil, err
}
revisions[rev] = metadata
if !ok {
continue
}

metadata, cached := revisions[rev]
if !cached {
metadata = &mesh.MetaDataResource{
Spec: &mesh_proto.MetaData{},
}
if err := manager.Get(rt.AppContext(), metadata, store.GetByRevision(rev), store.GetByType(dataplane.Spec.GetExtensions()["registry-type"])); err != nil {
return nil, err
}
revisions[rev] = metadata
}

for _, serviceInfo := range metadata.Spec.Services {
if serviceInfo.Params[constants.ServiceInfoSide] == req.Side {
applicationServiceForm := model.NewApplicationServiceForm(serviceInfo.Name)
if _, ok := serviceMap[serviceInfo.Name]; ok {
if err := serviceMap[serviceInfo.Name].FromServiceInfo(serviceInfo); err != nil {
return nil, err
}
} else {
if err := applicationServiceForm.FromServiceInfo(serviceInfo); err != nil {
return nil, err
}
serviceMap[serviceInfo.Name] = applicationServiceForm
}
}
for _, serviceInfo := range metadata.Spec.Services {
if serviceInfo.Params[constants.ServiceInfoSide] != req.Side {
continue
}
applicationServiceForm := model.NewApplicationServiceForm(serviceInfo.Name)
if _, ok := serviceMap[serviceInfo.Name]; !ok {
serviceMap[serviceInfo.Name] = applicationServiceForm
}

if err := applicationServiceForm.FromServiceInfo(serviceInfo); err != nil {
return nil, err
}
}
}
Expand Down Expand Up @@ -162,6 +170,9 @@ func GetApplicationSearchInfo(rt core_runtime.Runtime, req *model.ApplicationSea
res := make([]*model.ApplicationSearchResp, 0)
appMap := make(map[string]*model.ApplicationSearch)
for _, dataplane := range dataplaneList.Items {
if strings.Split(dataplane.GetMeta().GetName(), constant.KeySeparator)[1] == "0" {
continue
}
appName := dataplane.Spec.GetExtensions()[mesh_proto.Application]
if _, ok := appMap[appName]; !ok {
appMap[appName] = model.NewApplicationSearch(appName)
Expand Down
11 changes: 7 additions & 4 deletions pkg/admin/service/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package service

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -99,10 +100,12 @@ func SearchInstances(rt core_runtime.Runtime, req *model.SearchInstanceReq) (*mo
}

res := model.NewSearchPaginationResult()
list := make([]*model.SearchInstanceResp, len(dataplaneList.Items))
for i, item := range dataplaneList.Items {
list[i] = model.NewSearchInstanceResp()
list[i] = list[i].FromDataplaneResource(item)
var list []*model.SearchInstanceResp
for _, item := range dataplaneList.Items {
if strings.Split(item.Meta.GetName(), constant.KeySeparator)[1] == "0" {
continue
}
list = append(list, model.NewSearchInstanceResp().FromDataplaneResource(item))
}

res.List = list
Expand Down
15 changes: 13 additions & 2 deletions pkg/admin/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package service

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"sort"
"strconv"
)
Expand Down Expand Up @@ -63,9 +64,19 @@ func GetServiceTabDistribution(rt core_runtime.Runtime, req *model.ServiceTabDis
return nil, err
}
respItem := &model.ServiceTabDistributionResp{}
res = append(res, respItem.FromServiceDataplaneResource(dataplane, metadata, appName, req))
}

serviceInfos := metadata.GetSpec().(*v1alpha1.MetaData).Services
var sideServiceInfos []*v1alpha1.ServiceInfo
for _, serviceInfo := range serviceInfos {
if serviceInfo.GetParams()[constant.SideKey] == req.Side &&
serviceInfo.Name == req.ServiceName {
sideServiceInfos = append(sideServiceInfos, serviceInfo)
}
}
if len(sideServiceInfos) > 0 {
res = append(res, respItem.FromServiceDataplaneResource(dataplane, metadata, appName, req))
}
}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/core/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/config/instance"
"dubbo.apache.org/dubbo-go/v3/config_center"

"github.com/pkg/errors"
Expand Down Expand Up @@ -227,7 +226,7 @@ func initializeTraditional(cfg dubbo_cp.Config, builder *core_runtime.Builder) e
return err
}
builder.WithServiceDiscovery(sdDelegate)
adminRegistry := dubbo_registry.NewRegistry(delegate, sdDelegate, builder.AppRegCtx(), builder.InfRegCtx())
adminRegistry := dubbo_registry.NewRegistry(delegate, sdDelegate, builder.AppRegCtx(), builder.InfRegCtx(), configCenter)
builder.WithAdminRegistry(adminRegistry)
}
if len(metadataReportAddress) > 0 {
Expand All @@ -240,11 +239,8 @@ func initializeTraditional(cfg dubbo_cp.Config, builder *core_runtime.Builder) e
factory := extension.GetMetadataReportFactory(c.GetProtocol())
metadataReport := factory.CreateMetadataReport(addrUrl)
builder.WithMetadataReport(metadataReport)
dubbo_registry.AddMetadataReport(metadataReport, addrUrl.Address())
}
// 设置MetadataReportUrl
instance.SetMetadataReportUrl(addrUrl)
// 设置MetadataReportInstance
instance.SetMetadataReportInstanceByReg(addrUrl)

return nil
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/core/bootstrap/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
_ "dubbo.apache.org/dubbo-go/v3/imports"
_ "dubbo.apache.org/dubbo-go/v3/metadata/report/nacos"
_ "dubbo.apache.org/dubbo-go/v3/metadata/report/zookeeper"
_ "dubbo.apache.org/dubbo-go/v3/metadata/service/local"
_ "dubbo.apache.org/dubbo-go/v3/metadata/service/remote"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
)
Expand Down
Loading
Loading