Skip to content

Commit

Permalink
Add event id to router events
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Jan 23, 2020
1 parent 1c19678 commit 77c2a02
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 48 deletions.
99 changes: 54 additions & 45 deletions router/service/proto/router.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions router/service/proto/router.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions router/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions router/service/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions router/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions router/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77c2a02

Please sign in to comment.