Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
664e03f
refact metadata
FoghostCn Nov 22, 2023
bf150ce
fix cycle import
FoghostCn Nov 24, 2023
54116b3
Initially completed
FoghostCn Nov 25, 2023
dda0ba8
register success
FoghostCn Nov 28, 2023
f2134b4
refect serviceDiscoveryRegistry Server size api
FoghostCn Nov 29, 2023
20d02c0
move customizer to service discovery dir
FoghostCn Nov 29, 2023
d13afea
client call success
FoghostCn Dec 2, 2023
77983e5
mv metadata client to metadata dir
FoghostCn Dec 2, 2023
41f7474
refactor
FoghostCn Dec 5, 2023
5eadaae
refactor metadata exporter
FoghostCn Dec 11, 2023
2ac1b8e
mv metadata client to metadata dir
FoghostCn Dec 11, 2023
6b2fd9d
mv metadata info to metadata module
FoghostCn Dec 11, 2023
157e9c2
associate metadataReport with registry
FoghostCn Jan 2, 2024
8ab3557
unit test not done
FoghostCn Jan 4, 2024
a179a3d
update warn log
FoghostCn Jan 5, 2024
1a11af1
unit test tmp fix
FoghostCn Jan 5, 2024
c29963b
fix integrate_test
FoghostCn Jan 5, 2024
25d8711
fix some logic
FoghostCn Jan 8, 2024
e3ef66e
change RegistryType default value
FoghostCn Jan 9, 2024
88a537d
code review fix
FoghostCn Jan 15, 2024
328eeeb
change metadata to options style
FoghostCn Jan 16, 2024
d7097b1
fix unit test
FoghostCn Jan 16, 2024
5c6e8d7
fix integration test
FoghostCn Jan 16, 2024
e461a39
add doc for metadata report option WithAddress
FoghostCn Jan 22, 2024
ee77794
Merge branch 'main' into refect-metadata
FoghostCn Jan 23, 2024
b0c75a5
modify README.md (#2585)
FinalT Jan 26, 2024
a134e1b
feat:add internal service extension (#2577)
FinalT Jan 26, 2024
23bdc04
Merge remote-tracking branch 'origin/main' into refect-metadata
FoghostCn Jan 29, 2024
38a1cf0
Merge branch 'main' into refect-metadata
FoghostCn Jan 29, 2024
e283246
Merge branch 'dev-3.3' into refect-metadata
FoghostCn Feb 18, 2024
da7de7f
Merge branch 'dev-3.3' into refect-metadata
chickenlj Feb 29, 2024
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
6 changes: 3 additions & 3 deletions cmd/protoc-gen-go-triple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Make sure to add the resulting binary to your system's PATH.
To generate Triple code from your Protocol Buffer files, use the `protoc` compiler with the `protoc-gen-go-triple` plugin. Here's an example command:

```shell
protoc --go_out=. --go_opt=paths=source_relative --triple-go_out=. your_file.proto
protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. your_file.proto
```

Both the `--go_out` flag and `--triple-go_out` flag should be set to `.`. Please set the generated file path in the proto file using the `go_package` option.
Both the `--go_out` flag and `--go-triple_out` flag should be set to `.`. Please set the generated file path in the proto file using the `go_package` option.

## Example

Expand Down Expand Up @@ -94,7 +94,7 @@ The package for `greet.pb.go` and `greet.triple.go` are `greet`
You can use the following command to generate the Go code:

```shell
protoc --go_out=. --go_opt=paths=source_relative --triple-go_out=. greet.proto
protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. greet.proto
```

This will generate the Go code for the Protobuf code in `greet.pb.go` and the Triple code in `greet.triple.go`.
Expand Down
10 changes: 10 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package constant

import "math"

type DubboCtxKey string

const (
Expand Down Expand Up @@ -441,3 +443,11 @@ const (
DefaultMetaFileName = "dubbo.metadata."
DefaultEntrySize = 100
)

// priority
const (
DefaultPriority = 0
HighestPriority = math.MinInt32
// LowestPriority for metadata service
LowestPriority = math.MaxInt32
)
18 changes: 11 additions & 7 deletions protocol/triple/health/healthServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,18 @@ func (srv *HealthTripleServer) Resume() {

func init() {
healthServer = NewServer()

internal.HealthSetServingStatusServing = SetServingStatusServing

server.SetProServices(&server.ServiceDefinition{
Handler: healthServer,
Info: &triple_health.Health_ServiceInfo,
Opts: []server.ServiceOption{server.WithNotRegister(),
server.WithInterface(constant.HealthCheckServiceInterface)},
server.SetProServices(&server.InternalService{
Name: "healthCheck",
Init: func(options *server.ServiceOptions) (*server.ServiceDefinition, bool) {
return &server.ServiceDefinition{
Handler: healthServer,
Info: &triple_health.Health_ServiceInfo,
Opts: []server.ServiceOption{server.WithNotRegister(),
server.WithInterface(constant.HealthCheckServiceInterface)},
}, true
},
Priority: constant.DefaultPriority,
})

// In order to adapt config.Load
Expand Down
16 changes: 11 additions & 5 deletions protocol/triple/reflection/serverreflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,17 @@ var reflectionServer *ReflectionServer
func init() {
reflectionServer = NewServer()
internal.ReflectionRegister = Register
server.SetProServices(&server.ServiceDefinition{
Handler: reflectionServer,
Info: &rpb.ServerReflection_ServiceInfo,
Opts: []server.ServiceOption{server.WithNotRegister(),
server.WithInterface(constant.ReflectionServiceInterface)},
server.SetProServices(&server.InternalService{
Name: "reflection",
Init: func(options *server.ServiceOptions) (*server.ServiceDefinition, bool) {
return &server.ServiceDefinition{
Handler: reflectionServer,
Info: &rpb.ServerReflection_ServiceInfo,
Opts: []server.ServiceOption{server.WithNotRegister(),
server.WithInterface(constant.ReflectionServiceInterface)},
}, true
},
Priority: constant.DefaultPriority,
})
// In order to adapt config.Load
// Plans for future removal
Expand Down
118 changes: 100 additions & 18 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package server
import (
"context"
"fmt"
"sort"
"strconv"
"sync"
"time"
Expand All @@ -42,7 +43,8 @@ import (
)

// proServices are for internal services
var proServices = map[string]*ServiceDefinition{}
var proServices = make([]*InternalService, 0, 16)
var proLock sync.Mutex

type Server struct {
invoker protocol.Invoker
Expand Down Expand Up @@ -127,8 +129,17 @@ func newInfoInvoker(url *common.URL, info *ServiceInfo, svc common.RPCService) p

// Register assemble invoker chains like ProviderConfig.Load, init a service per call
func (s *Server) Register(handler interface{}, info *ServiceInfo, opts ...ServiceOption) error {
newSvcOpts, err := s.genSvcOpts(handler, opts...)
if err != nil {
return err
}
s.svcOptsMap.Store(newSvcOpts, info)
return nil
}

func (s *Server) genSvcOpts(handler interface{}, opts ...ServiceOption) (*ServiceOptions, error) {
if s.cfg == nil {
return errors.New("Server has not been initialized, please use NewServer() to create Server")
return nil, errors.New("Server has not been initialized, please use NewServer() to create Server")
}
var svcOpts []ServiceOption
appCfg := s.cfg.Application
Expand Down Expand Up @@ -157,16 +168,13 @@ func (s *Server) Register(handler interface{}, info *ServiceInfo, opts ...Servic
SetRegistries(regsCfg),
)
}

// options passed by users have higher priority
svcOpts = append(svcOpts, opts...)
if err := newSvcOpts.init(s, svcOpts...); err != nil {
return err
return nil, err
}
newSvcOpts.Implement(handler)
s.svcOptsMap.Store(newSvcOpts, info)

return nil
return newSvcOpts, nil
}

func (s *Server) exportServices() (err error) {
Expand Down Expand Up @@ -204,13 +212,89 @@ func (s *Server) Serve() error {
if err := s.exportServices(); err != nil {
return err
}

if err := s.exportInternalServices(); err != nil {
return err
}
if err := exposed_tmp.RegisterServiceInstance(); err != nil {
return err
}
select {}
}

// In order to expose internal services
func (s *Server) exportInternalServices() error {
cfg := &ServiceOptions{}
cfg.Application = s.cfg.Application
cfg.Provider = s.cfg.Provider
cfg.Protocols = s.cfg.Protocols
cfg.Registries = s.cfg.Registries

services := make([]*InternalService, 0, len(proServices))

proLock.Lock()
defer proLock.Unlock()
for _, service := range proServices {
if service.Init == nil {
return errors.New("[internal service]internal service init func is empty, please set the init func correctly")
}
sd, ok := service.Init(cfg)
if !ok {
logger.Infof("[internal service]%s service will not expose", service.Name)
continue
}
newSvcOpts, err := s.genSvcOpts(sd.Handler, sd.Opts...)
if err != nil {
return err
}
service.svcOpts = newSvcOpts
service.info = sd.Info
services = append(services, service)
}

sort.Slice(services, func(i, j int) bool {
return services[i].Priority < services[j].Priority
})

for _, service := range services {
if service.BeforeExport != nil {
service.BeforeExport(service.svcOpts)
}
err := service.svcOpts.ExportWithInfo(service.info)
if service.AfterExport != nil {
service.AfterExport(service.svcOpts, err)
}
if err != nil {
logger.Errorf("[internal service]export %s service failed, err: %s", service.Name, err)
return err
}
}

return nil
}

// InternalService for dubbo internal services
type InternalService struct {
// This is required
// internal service name
Name string
svcOpts *ServiceOptions
info *ServiceInfo
// This is required
// This options is service configuration
// Return serviceDefinition and bool, where bool indicates whether it is exported
Init func(options *ServiceOptions) (*ServiceDefinition, bool)
// This options is InternalService.svcOpts itself
BeforeExport func(options *ServiceOptions)
// This options is InternalService.svcOpts itself
AfterExport func(options *ServiceOptions, err error)
// Priority of service exposure
// Lower numbers have the higher priority
// The default priority is 0
// The metadata service is exposed at the end
// If you have no requirements for the order of service exposure, you can use the default priority or not set
Priority int
}

func getMetadataPort(opts *ServerOptions) int {
port := opts.Application.MetadataServicePort
if port == "" {
Expand Down Expand Up @@ -290,17 +374,15 @@ func NewServer(opts ...ServerOption) (*Server, error) {
srv := &Server{
cfg: newSrvOpts,
}

for _, service := range proServices {
err := srv.Register(service.Handler, service.Info, service.Opts...)
if err != nil {
return nil, err
}
}

return srv, nil
}

func SetProServices(sd *ServiceDefinition) {
proServices[sd.Info.InterfaceName] = sd
func SetProServices(sd *InternalService) {
if sd.Name == "" {
logger.Warnf("[internal service]internal name is empty, please set internal name")
return
}
proLock.Lock()
defer proLock.Unlock()
proServices = append(proServices, sd)
}