Skip to content

Commit

Permalink
feature: event query support tags filter (#2772)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakorse authored Nov 2, 2021
1 parent 13539c0 commit 5e3aebd
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 44 deletions.
106 changes: 62 additions & 44 deletions api/proto-go/core/monitor/event/pb/event_query.pb.go

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

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

1 change: 1 addition & 0 deletions api/proto/core/monitor/event/event_query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message GetEventsRequest {
int64 pageNo = 7;
int64 pageSize = 8;
bool debug = 9;
map<string,string> tags = 10;
}

message GetEventsResponse {
Expand Down
9 changes: 9 additions & 0 deletions modules/core/monitor/event/query/event.query.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func (s *eventQueryService) GetEvents(ctx context.Context, req *pb.GetEventsRequ
Value: req.RelationId,
})
}
if len(req.Tags) > 0 {
for key, val := range req.Tags {
sel.Filters = append(sel.Filters, &storage.Filter{
Key: "tags." + key,
Op: storage.EQ,
Value: val,
})
}
}
list, err := s.storageReader.QueryPaged(ctx, sel, int(req.PageNo), int(req.PageSize))
if err != nil {
return nil, err
Expand Down
32 changes: 32 additions & 0 deletions modules/core/monitor/event/query/event.query.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ func Test_eventQueryService_GetEvents_WithValidParams_Should_Return_NonEmptyList
{EventID: "event-id-1"},
}, nil)

querySvc := &eventQueryService{
storageReader: storage,
}
result, err := querySvc.GetEvents(context.Background(), &pb.GetEventsRequest{
Start: 1,
End: 2,
TraceId: "trace-id",
RelationId: "res-id",
RelationType: "res-type",
Tags: map[string]string{
"key-1": "val-1",
},
})
if err != nil {
t.Errorf("should not throw error")
}
if result == nil || len(result.Data.Items) != 1 {
t.Errorf("assert result failed")
}

}

func Test_eventQueryService_GetEvents_WithNilTags_Should_Not_Throw(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
storage := NewMockStorage(ctrl)
storage.EXPECT().
QueryPaged(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return([]*event.Event{
{EventID: "event-id-1"},
}, nil)

querySvc := &eventQueryService{
storageReader: storage,
}
Expand Down

0 comments on commit 5e3aebd

Please sign in to comment.