router: add metadata to routes (#1763)

* router: add metadata to route

* router/registry: set node metadata in route

* router/service: pass metadata to/from router service
This commit is contained in:
ben-toogood 2020-06-30 14:10:13 +01:00 committed by GitHub
parent 6532b6208b
commit a95accad56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 79 deletions

View File

@ -135,6 +135,7 @@ func (r *router) manageRoutes(service *registry.Service, action, network string)
Router: r.options.Id,
Link: DefaultLink,
Metric: DefaultLocalMetric,
Metadata: service.Metadata,
}
if err := r.manageRoute(route, action); err != nil {

View File

@ -27,6 +27,8 @@ type Route struct {
Link string
// Metric is the route cost metric
Metric int64
// Metadata for the route
Metadata map[string]string
}
// Hash returns route hash sum.

View File

@ -723,6 +723,8 @@ type Route struct {
Link string `protobuf:"bytes,6,opt,name=link,proto3" json:"link,omitempty"`
// the metric / score of this route
Metric int64 `protobuf:"varint,7,opt,name=metric,proto3" json:"metric,omitempty"`
// metadata for the route
Metadata map[string]string `protobuf:"bytes,8,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -802,6 +804,13 @@ func (m *Route) GetMetric() int64 {
return 0
}
func (m *Route) GetMetadata() map[string]string {
if m != nil {
return m.Metadata
}
return nil
}
func init() {
proto.RegisterEnum("go.micro.router.AdvertType", AdvertType_name, AdvertType_value)
proto.RegisterEnum("go.micro.router.EventType", EventType_name, EventType_value)
@ -821,55 +830,59 @@ func init() {
proto.RegisterType((*Event)(nil), "go.micro.router.Event")
proto.RegisterType((*Query)(nil), "go.micro.router.Query")
proto.RegisterType((*Route)(nil), "go.micro.router.Route")
proto.RegisterMapType((map[string]string)(nil), "go.micro.router.Route.MetadataEntry")
}
func init() { proto.RegisterFile("router/service/proto/router.proto", fileDescriptor_3123ad01af3cc940) }
var fileDescriptor_3123ad01af3cc940 = []byte{
// 673 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6e, 0xdb, 0x38,
0x10, 0x96, 0x6c, 0x4b, 0x5e, 0xcd, 0x3a, 0x8e, 0x96, 0x87, 0xac, 0xe0, 0xdd, 0xa4, 0xae, 0x4e,
0x41, 0x90, 0x4a, 0x85, 0x7b, 0x29, 0xfa, 0x9f, 0xa4, 0x2d, 0x0a, 0x34, 0x87, 0x56, 0x48, 0x50,
0xa0, 0x37, 0x45, 0x1e, 0x38, 0x42, 0x6c, 0x51, 0x21, 0x69, 0x07, 0x7e, 0x8e, 0x3e, 0x43, 0x0f,
0x3d, 0xf7, 0x91, 0xfa, 0x22, 0x85, 0x48, 0x2a, 0xb1, 0x2d, 0x2b, 0x68, 0x72, 0x12, 0xe7, 0xef,
0x9b, 0xe1, 0xcc, 0x7c, 0x22, 0x3c, 0x64, 0x74, 0x2a, 0x90, 0x85, 0x1c, 0xd9, 0x2c, 0x4d, 0x30,
0xcc, 0x19, 0x15, 0x34, 0x54, 0xca, 0x40, 0x0a, 0x64, 0x73, 0x44, 0x83, 0x49, 0x9a, 0x30, 0x1a,
0x28, 0xb5, 0xef, 0x40, 0x3b, 0xc2, 0xcb, 0x29, 0x72, 0xe1, 0x03, 0xfc, 0x15, 0x21, 0xcf, 0x69,
0xc6, 0xd1, 0x7f, 0x05, 0x9d, 0xe3, 0x94, 0x8b, 0x52, 0x26, 0x01, 0xd8, 0x32, 0x80, 0x7b, 0x66,
0xbf, 0xb9, 0xfb, 0xf7, 0x60, 0x2b, 0x58, 0x01, 0x0a, 0xa2, 0xe2, 0x13, 0x69, 0x2f, 0xff, 0x25,
0x6c, 0x1c, 0x53, 0x7a, 0x31, 0xcd, 0x35, 0x38, 0xd9, 0x07, 0xeb, 0x72, 0x8a, 0x6c, 0xee, 0x99,
0x7d, 0x73, 0x6d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, 0x09, 0x43, 0xea, 0xfc, 0x7a, 0xfd, 0x8a, 0x61, 0x95, 0x63, 0xc6,
0xe0, 0x57, 0x03, 0xac, 0x93, 0xf8, 0x6c, 0x8c, 0xe4, 0xa8, 0xec, 0x2a, 0xa9, 0x59, 0xe6, 0x35,
0xed, 0x59, 0x21, 0xa8, 0x51, 0x80, 0xa8, 0x71, 0xdc, 0x01, 0x64, 0x85, 0xd3, 0x12, 0x44, 0xcd,
0xf1, 0x0e, 0x20, 0x2b, 0xbf, 0x01, 0x83, 0x1c, 0x40, 0xab, 0x78, 0x4d, 0x6e, 0xe9, 0x6f, 0x75,
0x82, 0x8b, 0xcf, 0x8f, 0x6f, 0x90, 0x0f, 0x25, 0x6b, 0xb7, 0x6b, 0xfe, 0xdc, 0x1a, 0x68, 0xa7,
0xce, 0x5c, 0x22, 0x1d, 0x3e, 0xfb, 0xfa, 0x74, 0x94, 0x8a, 0xf3, 0xe9, 0x59, 0x90, 0xd0, 0x49,
0x28, 0x5d, 0xc3, 0x11, 0x7d, 0xa4, 0x0e, 0xb3, 0x41, 0xb8, 0xee, 0x11, 0x7d, 0xae, 0x94, 0x67,
0xb6, 0x94, 0x9e, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x14, 0x01, 0x1d, 0x6a, 0x07, 0x00,
0x00,
// 728 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x4e, 0xdb, 0x5c,
0x10, 0xb6, 0x9d, 0x38, 0x21, 0xf3, 0x87, 0x90, 0xff, 0xe8, 0x17, 0xbf, 0x95, 0x16, 0x9a, 0x5a,
0x5d, 0x20, 0x44, 0xed, 0x2a, 0xdd, 0x20, 0xe8, 0x85, 0x4b, 0xa9, 0x2a, 0x95, 0x4a, 0xad, 0x05,
0xaa, 0xd4, 0x9d, 0x89, 0x47, 0xc1, 0x4a, 0x62, 0x9b, 0x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71, 0xc5, 0xb5, 0xde, 0x6f, 0x03, 0xcc, 0x33, 0xff, 0x62, 0x84, 0xe4, 0x38,
0xef, 0x2a, 0x29, 0xd9, 0xa5, 0x25, 0xed, 0x59, 0xb8, 0x0f, 0x1a, 0x07, 0x91, 0xcf, 0x71, 0x0f,
0x90, 0x85, 0x93, 0x22, 0x40, 0xe4, 0x3b, 0xde, 0x03, 0x64, 0xe1, 0x0a, 0x69, 0xe4, 0x10, 0xaa,
0xfc, 0x67, 0x76, 0x47, 0x7f, 0x8b, 0x2f, 0x38, 0xfb, 0xf7, 0xb3, 0x35, 0xf2, 0x21, 0x3f, 0x1a,
0x1b, 0x25, 0x3f, 0x0e, 0x05, 0xb4, 0x59, 0xa6, 0xce, 0x91, 0x8e, 0xf6, 0xbe, 0xed, 0x0e, 0x42,
0x76, 0x99, 0x5d, 0x38, 0xfd, 0x78, 0xec, 0x0a, 0x53, 0x77, 0x10, 0x3f, 0x97, 0xc4, 0xa4, 0xe7,
0x2e, 0xfb, 0x87, 0xef, 0x4b, 0xe1, 0x45, 0x4d, 0x70, 0x2f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff,
0xce, 0x3b, 0xf2, 0x50, 0xe9, 0x07, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

View File

@ -130,4 +130,6 @@ message Route {
string link = 6;
// the metric / score of this route
int64 metric = 7;
// metadata for the route
map<string,string> metadata = 8;
}

View File

@ -112,6 +112,7 @@ func (s *svc) advertiseEvents(advertChan chan *router.Advert, stream pb.Router_A
Network: event.Route.Network,
Link: event.Route.Link,
Metric: event.Route.Metric,
Metadata: event.Route.Metadata,
}
events[i] = &router.Event{
@ -172,6 +173,7 @@ func (s *svc) Process(advert *router.Advert) error {
Network: event.Route.Network,
Link: event.Route.Link,
Metric: event.Route.Metric,
Metadata: event.Route.Metadata,
}
e := &pb.Event{
Id: event.Id,
@ -238,6 +240,7 @@ func (s *svc) Lookup(q ...router.QueryOption) ([]router.Route, error) {
Network: route.Network,
Link: route.Link,
Metric: route.Metric,
Metadata: route.Metadata,
}
}

View File

@ -62,6 +62,7 @@ func (w *watcher) watch(stream pb.Router_WatchService) error {
Network: resp.Route.Network,
Link: resp.Route.Link,
Metric: resp.Route.Metric,
Metadata: resp.Route.Metadata,
}
event := &router.Event{