robocanic commented on code in PR #1440:
URL: https://github.com/apache/dubbo-admin/pull/1440#discussion_r3005615941
##########
pkg/core/discovery/subscriber/rpc_instance.go:
##########
@@ -184,7 +208,8 @@ func (s *RPCInstanceEventSubscriber)
findRelatedRuntimeInstanceAndMerge(instance
}
}
-func (s *RPCInstanceEventSubscriber) getRuntimeInstanceByIp(ip string)
*meshresource.RuntimeInstanceResource {
+func (s *RPCInstanceEventSubscriber) getRuntimeInstanceForInstance(instanceRes
*meshresource.InstanceResource) *meshresource.RuntimeInstanceResource {
Review Comment:
Discussion:
这里用ip查出来之后,再用mesh,appName,rpcPort来做一个过滤选择,但可能都会被过滤掉,因为mesh,appName,rpcPort这些属性是需要用户在k8s
pod部署时手动打上的。在之前的代码逻辑里面,确定engine
type是k8s后用ip来查询,这是因为k8s中ip是唯一的,ip能够将pod和注册中心上的rpc
instance一一关联起来,是没有问题的。所以这里建议是加一个兜底返回,或者还是用之前的逻辑
##########
ui-vue3/src/views/resources/applications/tabs/instance.vue:
##########
@@ -126,6 +142,12 @@ const columns = [
// sorter: true,
width: 150
},
+ {
Review Comment:
Discussion:生命周期状态是registerState和DeployState共同决定的,如果把这个生命周期的状态给放到顶部,挨着instanceName,会不会好一点?<img
width="2123" height="990" alt="Image"
src="https://github.com/user-attachments/assets/95bf249e-3735-4aac-9029-64c53dfc8d36"
/>
##########
pkg/core/engine/subscriber/runtime_instance.go:
##########
@@ -129,31 +131,110 @@ func (s *RuntimeInstanceEventSubscriber)
processUpsert(rtInstanceRes *meshresour
// processDelete when runtime instance deleted, we should delete the
corresponding instance resource
func (s *RuntimeInstanceEventSubscriber) processDelete(rtInstanceRes
*meshresource.RuntimeInstanceResource) error {
- var instanceResource *meshresource.InstanceResource
- var err error
- switch rtInstanceRes.Spec.SourceEngineType {
- case string(enginecfg.Kubernetes):
- instanceResource, err = s.getRelatedInstanceByIP(rtInstanceRes)
- default:
- instanceResource, err =
s.getRelatedInstanceByName(rtInstanceRes)
- }
+ instanceResource, err := s.getRelatedInstance(rtInstanceRes)
if err != nil {
return err
}
if instanceResource == nil {
logger.Warnf("cannot find instance resource by runtime instance
%s, skipped deleting instance", rtInstanceRes.ResourceKey())
return nil
}
+ meshresource.ClearRuntimeInstanceFromInstance(instanceResource)
+ if meshresource.HasRPCInstanceSource(instanceResource) {
+ if err = s.instanceStore.Update(instanceResource); err != nil {
+ logger.Errorf("update instance resource failed after
runtime delete, instance: %s, err: %s",
+ instanceResource.ResourceKey(), err.Error())
+ return err
+ }
+ logger.Infof("instance lifecycle runtime source removed, keep
instance by rpc source, instance: %s, runtime: %s, registerState: registered",
+ instanceResource.ResourceKey(),
rtInstanceRes.ResourceKey())
+ instanceUpdateEvent :=
events.NewResourceChangedEvent(cache.Updated, instanceResource,
instanceResource)
+ s.eventEmitter.Send(instanceUpdateEvent)
+ logger.Debugf("runtime instance delete trigger instance update
event, event: %s", instanceUpdateEvent.String())
+ return nil
+ }
if err = s.instanceStore.Delete(instanceResource); err != nil {
logger.Errorf("delete instance resource failed, instance: %s,
err: %s", instanceResource.ResourceKey(), err.Error())
return err
}
+ logger.Infof("instance lifecycle runtime source removed and no rpc
source remains, deleted instance: %s, runtime: %s",
+ instanceResource.ResourceKey(), rtInstanceRes.ResourceKey())
instanceDeleteEvent := events.NewResourceChangedEvent(cache.Deleted,
instanceResource, nil)
s.eventEmitter.Send(instanceDeleteEvent)
logger.Debugf("runtime instance delete trigger instance delete event,
event: %s", instanceDeleteEvent.String())
return nil
}
+func (s *RuntimeInstanceEventSubscriber) getRelatedInstance(
+ rtInstanceRes *meshresource.RuntimeInstanceResource)
(*meshresource.InstanceResource, error) {
+ if rtInstanceRes == nil || rtInstanceRes.Spec == nil {
+ return nil, nil
+ }
+ switch rtInstanceRes.Spec.SourceEngineType {
+ case string(enginecfg.Kubernetes):
+ return s.getRelatedKubernetesInstance(rtInstanceRes)
+ default:
+ return s.getRelatedInstanceByName(rtInstanceRes)
+ }
+}
+
+func (s *RuntimeInstanceEventSubscriber) getRelatedKubernetesInstance(
Review Comment:
Discussion: 这里用两种方式来获取runtime
instance对应的instance实例,但可能都获取不到,因为用户如果不在pod上打上对应的label/annotions,我们就不知道这个pod是对应哪个dubbo实例。但在k8s中,ip是唯一的,所以可以通过ip的唯一来关联到rpc
instance和k8s pod。所以在之前的代码逻辑里,在确定engine type是k8s之后,就会通过runtime
instance的ip来反查instance,这是没问题的。现在先用reskey,再用resName,但可以都获取不到。建议是加个通过ip查询来兜底或者是还是用之前的逻辑
##########
pkg/console/model/instance.go:
##########
@@ -196,3 +189,64 @@ func FromInstanceResource(res
*meshresource.InstanceResource, cfg app.AdminConfi
}
return r
}
+
+func DeriveInstanceDeployState(instance *meshproto.Instance) string {
+ if instance == nil || strutil.IsBlank(instance.DeployState) {
+ return "Unknown"
+ }
+ switch instance.DeployState {
Review Comment:
Suggestion:
看能不能把DeployState,RegisterState,LifecycleState统统定义成枚举/自定义类型,定义在一个地方,再写上对应的注释,就能清楚每个state的具体含义
--
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]