Skip to content

Commit

Permalink
feat: add metadata for etcd registry (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq authored Nov 2, 2022
1 parent 2f5464d commit 736316e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
5 changes: 3 additions & 2 deletions pkg/registry/etcdv3/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ func (reg *etcdv3Registry) registerKey(info *server.ServiceInfo) string {

func (reg *etcdv3Registry) registerValue(info *server.ServiceInfo) string {
update := Update{
Op: Add,
Addr: info.Address,
Op: Add,
Addr: info.Address,
Metadata: info,
}

val, _ := json.Marshal(update)
Expand Down
6 changes: 5 additions & 1 deletion pkg/registry/etcdv3/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package etcdv3

import (
"github.com/douyu/jupiter/pkg/server"
)

type Operation uint8

const (
Expand All @@ -32,5 +36,5 @@ type Update struct {
Addr string
// Metadata is the updated metadata. It is nil if there is no metadata update.
// Metadata is not required for a custom naming implementation.
Metadata interface{}
Metadata *server.ServiceInfo
}
17 changes: 5 additions & 12 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type ServiceInfo struct {
Kind constant.ServiceKind `json:"kind"`
Version string `json:"version"`
Mode string `json:"mode"`
Host string `json:"hostName"`
// Deployment 部署组: 不同组的流量隔离
// 比如某些服务给内部调用和第三方调用,可以配置不同的deployment,进行流量隔离
Deployment string `json:"deployment"`
// Group 流量组: 流量在Group之间进行负载均衡
Group string `json:"group"`
Services map[string]*Service `json:"services" toml:"services"`
Group string `json:"group"`
}

func (s *ServiceInfo) RegistryName() string {
Expand All @@ -60,14 +60,6 @@ func (s *ServiceInfo) ServicePrefix() string {
return fmt.Sprintf("%s:%s:%s:%s/", s.Scheme, s.Name, "v1", pkg.AppMode())
}

// Service ...
type Service struct {
Namespace string `json:"namespace" toml:"namespace"`
Name string `json:"name" toml:"name"`
Labels map[string]string `json:"labels" toml:"labels"`
Methods []string `json:"methods" toml:"methods"`
}

// Label ...
func (si ServiceInfo) Label() string {
return fmt.Sprintf("%s:https://%s", si.Scheme, si.Address)
Expand Down Expand Up @@ -150,12 +142,13 @@ func defaultServiceInfo() ServiceInfo {
Metadata: make(map[string]string),
Region: pkg.AppRegion(),
Zone: pkg.AppZone(),
Mode: pkg.AppMode(),
Host: pkg.AppHost(),
Version: "v1",
Kind: 0,
Deployment: "",
Group: "",
}
si.Metadata["appMode"] = pkg.AppMode()
si.Metadata["appHost"] = pkg.AppHost()
si.Metadata["startTime"] = pkg.StartTime()
si.Metadata["buildTime"] = pkg.BuildTime()
si.Metadata["appVersion"] = pkg.AppVersion()
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func TestNotImplementEqual(t *testing.T) {
// 比如某些服务给内部调用和第三方调用,可以配置不同的deployment,进行流量隔离
Deployment string `json:"deployment"`
// Group 流量组: 流量在Group之间进行负载均衡
Group string `json:"group"`
Services map[string]*Service `json:"services" toml:"services"`
Group string `json:"group"`
}

info1 := ServiceInfo{
Expand Down

0 comments on commit 736316e

Please sign in to comment.