Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: event query support tags filter #2772

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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