Skip to content

Commit

Permalink
feat:save old service info (apache#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
FinalT authored Jan 5, 2024
1 parent d2ed4f5 commit 7341d50
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion protocol/triple/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
import (
"github.com/dubbogo/gost/log/logger"

grpc_go "github.com/dubbogo/grpc-go"

"github.com/dustin/go-humanize"

"google.golang.org/grpc"
Expand Down Expand Up @@ -174,9 +176,10 @@ func (s *Server) compatHandleService(interfaceName string, group, version string
if !ok {
info := createServiceInfoWithReflection(service)
s.handleServiceWithInfo(interfaceName, invoker, info, opts...)
s.saveServiceInfo(interfaceName, info)
continue
}

s.compatSaveServiceInfo(ds.XXX_ServiceDesc())
// inject invoker, it has all invocation logics
ds.XXX_SetProxyImpl(invoker)
s.compatRegisterHandler(interfaceName, ds, opts...)
Expand Down Expand Up @@ -318,6 +321,31 @@ func (s *Server) saveServiceInfo(interfaceName string, info *server.ServiceInfo)
s.services[interfaceName] = ret
}

func (s *Server) compatSaveServiceInfo(desc *grpc_go.ServiceDesc) {
ret := grpc.ServiceInfo{}
ret.Methods = make([]grpc.MethodInfo, 0, len(desc.Streams)+len(desc.Methods))
for _, method := range desc.Methods {
md := grpc.MethodInfo{
Name: method.MethodName,
IsClientStream: false,
IsServerStream: false,
}
ret.Methods = append(ret.Methods, md)
}
for _, stream := range desc.Streams {
md := grpc.MethodInfo{
Name: stream.StreamName,
IsClientStream: stream.ClientStreams,
IsServerStream: stream.ServerStreams,
}
ret.Methods = append(ret.Methods, md)
}
ret.Metadata = desc.Metadata
s.mu.Lock()
defer s.mu.Unlock()
s.services[desc.ServiceName] = ret
}

func (s *Server) GetServiceInfo() map[string]grpc.ServiceInfo {
s.mu.RLock()
defer s.mu.RUnlock()
Expand Down

0 comments on commit 7341d50

Please sign in to comment.