Add event id to router events

This commit is contained in:
Asim Aslam 2020-01-23 11:44:06 +00:00
parent 1c19678d04
commit 77c2a021da
6 changed files with 68 additions and 48 deletions

View File

@ -578,12 +578,14 @@ var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo
// Event is routing table event
type Event struct {
// the unique event id
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// type of event
Type EventType `protobuf:"varint,1,opt,name=type,proto3,enum=go.micro.router.EventType" json:"type,omitempty"`
Type EventType `protobuf:"varint,2,opt,name=type,proto3,enum=go.micro.router.EventType" json:"type,omitempty"`
// unix timestamp of event
Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
// service route
Route *Route `protobuf:"bytes,3,opt,name=route,proto3" json:"route,omitempty"`
Route *Route `protobuf:"bytes,4,opt,name=route,proto3" json:"route,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -614,6 +616,13 @@ func (m *Event) XXX_DiscardUnknown() {
var xxx_messageInfo_Event proto.InternalMessageInfo
func (m *Event) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Event) GetType() EventType {
if m != nil {
return m.Type
@ -815,46 +824,46 @@ func init() {
}
var fileDescriptor_c2b04f200fb3e806 = []byte{
// 646 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x4e, 0xdb, 0x4c,
0x14, 0xb6, 0x9d, 0xd8, 0xf9, 0x7d, 0xfe, 0x10, 0xdc, 0xb3, 0xa0, 0x56, 0x5a, 0x68, 0xe4, 0x15,
0x42, 0xd4, 0x41, 0xe9, 0xb6, 0x37, 0xa0, 0xad, 0x2a, 0x95, 0x45, 0x6b, 0x81, 0xba, 0x36,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8, 0x0f, 0x6d, 0xf9, 0xf5, 0xb8, 0x67, 0xbe, 0xf5, 0x0d,
0x2e, 0x7f, 0x6e, 0x22, 0x0b, 0x3f, 0x57, 0xac, 0xdd, 0x6c, 0xf8, 0xa7, 0x36, 0x40, 0x5b, 0x4d,
0xe6, 0x0a, 0xe9, 0xd4, 0x53, 0x5f, 0xbe, 0x57, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x53, 0xd8,
0xc9, 0xf6, 0x2d, 0x07, 0x00, 0x00,
// 645 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x4e, 0xdb, 0x40,
0x10, 0xb6, 0x93, 0xd8, 0xa9, 0xa7, 0x21, 0xb8, 0x73, 0xa0, 0x56, 0x5a, 0x68, 0xe4, 0x13, 0x42,
0xd4, 0x41, 0xe9, 0xb5, 0x7f, 0x40, 0x5b, 0x55, 0x2a, 0x87, 0xd6, 0x02, 0xf5, 0x6c, 0x92, 0x11,
0xb5, 0x48, 0x6c, 0xb3, 0xbb, 0x01, 0xe5, 0x39, 0xfa, 0x0c, 0x3d, 0xf4, 0xdc, 0x47, 0xea, 0x8b,
0x54, 0xfb, 0x63, 0x48, 0x62, 0x8c, 0x0a, 0x27, 0xef, 0xfc, 0x7d, 0x33, 0x3b, 0x33, 0x9f, 0x17,
0xf6, 0xa6, 0xe9, 0x88, 0xe5, 0x83, 0xb3, 0xfc, 0xa5, 0x3e, 0xb0, 0x7c, 0x26, 0x88, 0x0d, 0x38,
0xb1, 0xcb, 0x74, 0x44, 0x83, 0x82, 0xe5, 0xa2, 0x54, 0x46, 0x4a, 0xc0, 0xf5, 0xb3, 0x3c, 0x52,
0xbe, 0x91, 0x56, 0x87, 0x1e, 0xb4, 0x63, 0xba, 0x98, 0x11, 0x17, 0x21, 0xc0, 0xa3, 0x98, 0x78,
0x91, 0x67, 0x9c, 0xc2, 0xb7, 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a6, 0xb4, 0xf4, 0xc3, 0xe8, 0xbd, 0xa8, 0xb5, 0x9b, 0xed, 0xb2, 0xf0,
0x00, 0x1c, 0x45, 0x32, 0xdc, 0xac, 0xf8, 0x2e, 0x92, 0xaf, 0x57, 0xb3, 0xf0, 0xa1, 0xb5, 0x67,
0xe3, 0x01, 0x78, 0xfa, 0x7a, 0x29, 0x27, 0x0c, 0xaa, 0x9b, 0x63, 0x20, 0x9e, 0xd6, 0xd0, 0x52,
0x61, 0x7c, 0x82, 0xb6, 0x21, 0x0c, 0xd6, 0xf9, 0xf5, 0xfa, 0x15, 0xc3, 0x2a, 0xc7, 0xac, 0xe1,
0xdf, 0x06, 0x38, 0xc7, 0xc9, 0xe9, 0x84, 0xf0, 0xb0, 0xec, 0x2a, 0xd6, 0x2c, 0xf3, 0x2d, 0xed,
0x59, 0x21, 0xa8, 0x25, 0x41, 0xf4, 0x38, 0xee, 0x01, 0xb2, 0xc2, 0x69, 0x05, 0xa2, 0xe7, 0x78,
0x0f, 0x90, 0x95, 0xdf, 0x80, 0x85, 0xfb, 0xd0, 0x92, 0xaf, 0xc9, 0x1d, 0xfd, 0xad, 0x4e, 0x70,
0xf1, 0xf9, 0x09, 0x2d, 0xfc, 0x5c, 0xb2, 0x76, 0xb3, 0xe6, 0xcf, 0x6d, 0x80, 0xb6, 0xea, 0xcc,
0x25, 0xd2, 0xa9, 0xab, 0x5e, 0xc2, 0x57, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x08, 0x7e,
0xf4, 0x3d, 0x07, 0x00, 0x00,
}

View File

@ -93,12 +93,14 @@ enum EventType {
// Event is routing table event
message Event {
// the unique event id
string id = 1;
// type of event
EventType type = 1;
EventType type = 2;
// unix timestamp of event
int64 timestamp = 2;
int64 timestamp = 3;
// service route
Route route = 3;
Route route = 4;
}
// Query is passed in a LookupRequest

View File

@ -121,6 +121,7 @@ func (s *svc) advertiseEvents(advertChan chan *router.Advert, stream pb.Router_A
}
events[i] = &router.Event{
Id: event.Id,
Type: router.EventType(event.Type),
Timestamp: time.Unix(0, event.Timestamp),
Route: route,
@ -179,6 +180,7 @@ func (s *svc) Process(advert *router.Advert) error {
Metric: event.Route.Metric,
}
e := &pb.Event{
Id: event.Id,
Type: pb.EventType(event.Type),
Timestamp: event.Timestamp.UnixNano(),
Route: route,

View File

@ -65,6 +65,7 @@ func (w *watcher) watch(stream pb.Router_WatchService) error {
}
event := &router.Event{
Id: resp.Id,
Type: router.EventType(resp.Type),
Timestamp: time.Unix(0, resp.Timestamp),
Route: route,

View File

@ -38,6 +38,10 @@ func (t *table) sendEvent(e *Event) {
t.RLock()
defer t.RUnlock()
if len(e.Id) == 0 {
e.Id = uuid.New().String()
}
for _, w := range t.watchers {
select {
case w.resChan <- e:

View File

@ -39,6 +39,8 @@ func (t EventType) String() string {
// Event is returned by a call to Next on the watcher.
type Event struct {
// Unique id of the event
Id string
// Type defines type of event
Type EventType
// Timestamp is event timestamp