robocanic commented on code in PR #1460:
URL: https://github.com/apache/dubbo-admin/pull/1460#discussion_r3106233944


##########
pkg/console/service/application.go:
##########
@@ -202,6 +202,140 @@ func getAppConsumeServiceInfo(ctx consolectx.Context, req 
*model.ApplicationServ
        return pageResult, nil
 }
 
+// GraphApplications returns the application-level graph for a given 
application.
+// It collects provider and consumer service relations and transforms them 
into nodes and edges.
+// The current implementation is a simplified version (provider/consumer link 
traversal).
+func GraphApplications(ctx consolectx.Context, req *model.ApplicationGraphReq) 
(*model.GraphData, error) {
+
+       // Step 1: query all services provided by this application in the 
namespace.
+       providerServiceList, err := 
manager.ListByIndexes[*meshresource.ServiceProviderMetadataResource](
+               ctx.ResourceManager(),
+               meshresource.ServiceProviderMetadataKind,
+               []index.IndexCondition{{IndexName: index.ByMeshIndex, Value: 
req.Mesh, Operator: index.Equals},
+                       {IndexName: index.ByServiceProviderAppName, Value: 
req.AppName, Operator: index.Equals},
+               },
+       )
+       if err != nil {
+               // manager.ListByIndexes 内部已经有合适的 error 返回,直接透传即可

Review Comment:
   Correction: 注释用英文



##########
pkg/core/discovery/subscriber/service_provider_metadata.go:
##########
@@ -82,8 +107,43 @@ func (s *ServiceProviderMetadataEventSubscriber) 
processUpsert(r *meshresource.S
        if r.Spec == nil {
                return bizerror.New(bizerror.UnknownError, "provider metadata 
resource spec is nil")
        }
-       if strutil.IsBlank(r.Spec.ProviderAppName) {
-               logger.Warnf("skip processing service provider metadata event 
because spec.providerAppName is blank, res:%s", r.String())
+       if err := s.ensureApplication(r); err != nil {
+               return err
+       }
+       return s.syncService(r.Mesh, r.Spec.ServiceName, r.Spec.Version, 
r.Spec.Group)
+}
+
+func (s *ServiceProviderMetadataEventSubscriber) processDelete(r 
*meshresource.ServiceProviderMetadataResource) error {
+       if r.Spec == nil {
+               return bizerror.New(bizerror.UnknownError, "provider metadata 
resource spec is nil")
+       }
+       return s.syncService(r.Mesh, r.Spec.ServiceName, r.Spec.Version, 
r.Spec.Group)
+}
+
+func (s *ServiceProviderMetadataEventSubscriber) processUpdate(oldRes, newRes 
*meshresource.ServiceProviderMetadataResource) error {
+       if newRes.Spec == nil {
+               return bizerror.New(bizerror.UnknownError, "provider metadata 
resource spec is nil")
+       }
+       if err := s.ensureApplication(newRes); err != nil {
+               return err
+       }
+
+       if oldRes != nil && oldRes.Spec != nil {

Review Comment:
   
Correction:这里oldResource和newResource的key肯定是一样的,这个判断是多余的,processUpdate和processUpsert逻辑应该是一样的,需要去掉



##########
ui-vue3/src/views/resources/services/tabs/topology.vue:
##########


Review Comment:
   Suggestion:可以多写写注释



##########
pkg/core/discovery/subscriber/service_provider_metadata.go:
##########
@@ -106,3 +166,195 @@ func (s *ServiceProviderMetadataEventSubscriber) 
processUpsert(r *meshresource.S
        s.emitter.Send(events.NewResourceChangedEvent(cache.Added, nil, appRes))
        return nil
 }
+
+func (s *ServiceProviderMetadataEventSubscriber) syncService(mesh, 
serviceName, version, group string) error {
+       serviceKey := meshresource.BuildServiceIdentityKey(serviceName, 
version, group)
+       resources, err := s.providerStore.ListByIndexes(
+               []index.IndexCondition{{IndexName: index.ByMeshIndex, Value: 
mesh, Operator: index.Equals},
+                       {IndexName: index.ByServiceProviderServiceName, Value: 
serviceName, Operator: index.Equals},

Review Comment:
   Suggestion: 这里可以直接用ServiceKey的索引,可以去掉后面的version和group的判断



##########
pkg/console/service/service.go:
##########
@@ -126,7 +129,7 @@ func SearchServices(ctx consolectx.Context, req 
*model.ServiceSearchReq) (*model
 
 // SearchServicesByKeywords search services by keywords with prefix matching
 func SearchServicesByKeywords(ctx consolectx.Context, req 
*model.ServiceSearchReq) (*model.SearchPaginationResult, error) {
-       pageData, err := 
manager.PageListByIndexes[*meshresource.ServiceProviderMetadataResource](
+       pageData, err := 
manager.PageListByIndexes[*meshresource.ServiceResource](

Review Comment:
   Correction: 泛型里面用的是ServiceResource, 
下面resourceKind传的却是ServiceProviderMetadataKind



##########
pkg/core/discovery/subscriber/service_provider_metadata.go:
##########
@@ -19,29 +19,37 @@ package subscriber
 
 import (
        "reflect"
+       "sort"
+       "strings"
 
-       "github.com/duke-git/lancet/v2/strutil"
-       "k8s.io/client-go/tools/cache"
-
+       meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"

Review Comment:
   
Suggestion:这里的导入顺序有点问题,参考这里修正一下:https://github.com/apache/dubbo-admin/wiki/%E6%96%B0%E7%89%88Dubbo-Admin%E5%BC%80%E5%8F%91%E8%80%85%E6%8C%87%E5%8D%97#goland-import%E9%85%8D%E7%BD%AE



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to