Skip to content

Commit

Permalink
Add filter by destination module to mircat (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchalp authored Nov 3, 2022
1 parent 994bd74 commit bbec450
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 106 deletions.
2 changes: 1 addition & 1 deletion cmd/mircat/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func debug(args *arguments) error {

// If the event was selected by the user for inspection, pause before submitting it to the node.
// The processing continues after the user's interactive confirmation.
if selected(event, args.selectedEvents, args.selectedIssEvents) &&
if selected(event, args.selectedEventNames, args.selectedIssEventNames) &&
index >= args.offset &&
(args.limit == 0 || index < args.offset+args.limit) {

Expand Down
7 changes: 5 additions & 2 deletions cmd/mircat/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ func displayEvents(args *arguments) error {
for _, event := range entry.Events {
metadata.index = uint64(index)

if _, ok := args.selectedEvents[eventName(event)]; ok && index >= args.offset && (args.limit == 0 || index < args.offset+args.limit) {
_, validEvent := args.selectedEventNames[eventName(event)]
_, validDest := args.selectedEventDests[event.DestModule]

if validEvent && validDest && index >= args.offset && (args.limit == 0 || index < args.offset+args.limit) {
// If event type has been selected for displaying

switch e := event.Type.(type) {
case *eventpb.Event_Iss:
// Only display selected sub-types of the ISS Event
if _, ok := args.selectedIssEvents[issEventName(e.Iss)]; ok {
if _, validIssEvent := args.selectedIssEventNames[issEventName(e.Iss)]; validIssEvent {
displayEvent(event, metadata)
}
default:
Expand Down
12 changes: 7 additions & 5 deletions cmd/mircat/eventloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ type eventMetadata struct {
index uint64
}

// Returns the list of event names present in the given eventlog file,
// Returns the list of event names and destinations present in the given eventlog file,
// along with the total number of events present in the file.
func getEventList(file *os.File) (map[string]struct{}, map[string]struct{}, int, error) {
func getEventList(file *os.File) (map[string]struct{}, map[string]struct{}, map[string]struct{}, int, error) {
events := make(map[string]struct{})
issEvents := make(map[string]struct{})
eventDests := make(map[string]struct{})

defer func(file *os.File, offset int64, whence int) {
_, _ = file.Seek(offset, whence) // resets the file offset for successive reading
}(file, 0, 0)

reader, err := eventlog.NewReader(file)
if err != nil {
return nil, nil, 0, err
return nil, nil, nil, 0, err
}

cnt := 0 // Counts the total number of events in the event log.
Expand All @@ -48,6 +49,7 @@ func getEventList(file *os.File) (map[string]struct{}, map[string]struct{}, int,

// Add the Event name to the set of known Events.
events[eventName(event)] = struct{}{}
eventDests[event.DestModule] = struct{}{}
switch e := event.Type.(type) {
case *eventpb.Event_Iss:
// For ISS Events, also add the type of the ISS event to a set of known ISS events.
Expand All @@ -56,10 +58,10 @@ func getEventList(file *os.File) (map[string]struct{}, map[string]struct{}, int,
}
}
if errors.Is(err, io.EOF) {
return events, issEvents, cnt, fmt.Errorf("failed reading event log: %w", err)
return events, issEvents, eventDests, cnt, fmt.Errorf("failed reading event log: %w", err)
}

return events, issEvents, cnt, nil
return events, issEvents, eventDests, cnt, nil
}

// eventName returns a string name of an Event.
Expand Down
58 changes: 37 additions & 21 deletions cmd/mircat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ type arguments struct {
limit int

// Events selected by the user for displaying.
selectedEvents map[string]struct{}
selectedEventNames map[string]struct{}

// If ISS Events have been selected for displaying, this variable contains the types of ISS events to be displayed.
selectedIssEvents map[string]struct{}
selectedIssEventNames map[string]struct{}

// Events with specific destination modules selected by the user for displaying
selectedEventDests map[string]struct{}

// If set to true, start a Node in debug mode with the given event log.
debug bool
Expand Down Expand Up @@ -64,7 +67,7 @@ func main() {

// Scan the event log and collect all occurring event types.
fmt.Println("Scanning input file.")
allEvents, allISSEvents, totalEvents, err := getEventList(args.srcFile)
allEvents, allISSEvents, allDests, totalEvents, err := getEventList(args.srcFile)
if err != nil {
kingpin.Errorf("Error parsing src file", err)
fmt.Printf("\n\n!!!\nContinuing after error. Event list might be incomplete!\n!!!\n\n")
Expand All @@ -73,23 +76,30 @@ func main() {

// If no event types have been selected through command-line arguments,
// have the user interactively select the events to include in the output.
if len(args.selectedEvents) == 0 {
if len(args.selectedEventNames) == 0 {

// Select top-level events
args.selectedEvents = checkboxes("Please select the events", allEvents)
args.selectedEventNames = checkboxes("Please select the events", allEvents)

// If any ISS events occur in the event log and the user selected the ISS event type,
// have the user select which of those should be included in the output.
if _, ok := args.selectedEvents["Iss"]; ok {
args.selectedIssEvents = checkboxes("Please select the ISS events", allISSEvents)
if _, ok := args.selectedEventNames["Iss"]; ok {
args.selectedIssEventNames = checkboxes("Please select the ISS events", allISSEvents)
}
}

// // If no event destinations have been selected through command-line arguments,
// // have the user interactively select the event destinations' to include in the output.
if len(args.selectedEventDests) == 0 {

// Select top-level events
args.selectedEventDests = checkboxes("Please select the event destinations", allDests)

// Print the command-line arguments representing the user's selection of events.
// This is useful for repeated runs of mircat.
fmt.Println("Command-line arguments for selecting the chosen events:\n" +
selectionArgs(args.selectedEvents, args.selectedIssEvents))
}

fmt.Println("Command-line arguments for selecting the chosen filters:\n" +
selectionArgs(args.selectedEventNames, args.selectedIssEventNames, args.selectedEventDests))

// Display selected events or enter debug mode.
if args.debug {
err = debug(args)
Expand All @@ -115,6 +125,7 @@ func parseArgs(args []string) (*arguments, error) {
src := app.Flag("src", "The input file to read.").Required().File()
events := app.Flag("event", "Event types to be displayed.").Short('e').Strings()
issEvents := app.Flag("iss-event", "Types of ISS Events to be displayed if ISS events are selected.").Short('s').Strings()
eventDests := app.Flag("event-dest", "Event destination types to be displayed.").Short('r').Strings()
offset := app.Flag("offset", "The first offset events will not be displayed.").Default("0").Int()
limit := app.Flag("limit", "Maximum number of events to consider for display or debug").Default("0").Int()
dbg := app.Flag("debug", "Start a Node in debug mode with the given event log.").Short('d').Bool()
Expand All @@ -131,15 +142,16 @@ func parseArgs(args []string) (*arguments, error) {
}

return &arguments{
srcFile: *src,
debug: *dbg,
ownID: t.NodeID(*id),
membership: t.NodeIDSlice(*membership),
showNodeEvents: *showNodeEvents,
offset: *offset,
limit: *limit,
selectedEvents: toSet(*events),
selectedIssEvents: toSet(*issEvents),
srcFile: *src,
debug: *dbg,
ownID: t.NodeID(*id),
membership: t.NodeIDSlice(*membership),
showNodeEvents: *showNodeEvents,
offset: *offset,
limit: *limit,
selectedEventNames: toSet(*events),
selectedIssEventNames: toSet(*issEvents),
selectedEventDests: toSet(*eventDests),
}, nil
}

Expand All @@ -160,7 +172,7 @@ func checkboxes(label string, opts map[string]struct{}) map[string]struct{} {
return toSet(selected)
}

func selectionArgs(events map[string]struct{}, issEvents map[string]struct{}) string {
func selectionArgs(events map[string]struct{}, issEvents map[string]struct{}, dests map[string]struct{}) string {
argStr := ""

for _, eventName := range toList(events) {
Expand All @@ -171,5 +183,9 @@ func selectionArgs(events map[string]struct{}, issEvents map[string]struct{}) st
argStr += " --iss-event " + issEventName
}

for _, dest := range toList(dests) {
argStr += " event-dest " + dest
}

return argStr
}
3 changes: 2 additions & 1 deletion pkg/modules/mockmodules/internal/mock_internal/impl.mock.go

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

8 changes: 5 additions & 3 deletions pkg/net/grpc/grpctransport.pb.go

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

1 change: 1 addition & 0 deletions pkg/net/grpc/grpctransport_grpc.pb.go

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

10 changes: 6 additions & 4 deletions pkg/pb/availabilitypb/availabilitypb.pb.go

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

10 changes: 6 additions & 4 deletions pkg/pb/availabilitypb/batchdbpb/batchdbpb.pb.go

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

10 changes: 6 additions & 4 deletions pkg/pb/availabilitypb/mscpb/mscpb.pb.go

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

10 changes: 6 additions & 4 deletions pkg/pb/batchfetcherpb/batchfetcherpb.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 pkg/pb/bcbpb/bcbpb.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 pkg/pb/checkpointpb/checkpointpb.pb.go

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

5 changes: 3 additions & 2 deletions pkg/pb/commonpb/commonpb.pb.go

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

5 changes: 3 additions & 2 deletions pkg/pb/contextstorepb/contextstorepb.pb.go

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

5 changes: 3 additions & 2 deletions pkg/pb/dslpb/dslpb.pb.go

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

Loading

0 comments on commit bbec450

Please sign in to comment.