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

Support gRPC for query service #1307

Merged
merged 33 commits into from
Apr 22, 2019

Conversation

annanay25
Copy link
Member

Which problem is this PR solving?

  • Initial work to add GRPC support for the query-service.

Short description of the changes

  • Use grpc-gateway to multiplex HTTP and GRPC on the same port
  • Create GRPC server and handler for GetTrace()

Signed-off-by: Annanay annanay.a@media.net

cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
@@ -64,6 +64,22 @@ service CollectorService {
}
}

message GetTraceRequest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this proto file is getting very busy. Could you try to move the query service to api_v2_query.proto? Or even better api_v2/query.proto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will move this out.

cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved
Copy link
Member Author

@annanay25 annanay25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! @yurishkuro

I first wanted to ensure all the necessary proto definitions are in place.

cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
cmd/query/app/grpc_handler.go Outdated Show resolved Hide resolved
@@ -64,6 +64,22 @@ service CollectorService {
}
}

message GetTraceRequest {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will move this out.

model/proto/api_v2.proto Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved

message GetTraceResponse {
Trace trace = 1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the discussion in #1323. We have an internal grpc implementation of GetTrace, and our users have run into the issue of large traces exceeding grpc default message size. So I think we need to go with streaming APIs for methods that can return large data sets.

I am not sure what it would do to grpc_gateway, how does it map streaming calls to HTTP?

Also, it's been a while since the last time I checked, but if gRPC for JavaScript in the browser has advanced enough, then we won't even need grpc_gateway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what it would do to grpc_gateway, how does it map streaming calls to HTTP?

Seems like they have an open issue for sending chunked JSON responses - grpc-ecosystem/grpc-gateway/issues/562

Also, it's been a while since the last time I checked, but if gRPC for JavaScript in the browser has advanced enough, then we won't even need grpc_gateway.

Apart from streaming-support (which is on their roadmap) what other features would we need in the grpc-web library?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Went through the grpc-web readme again, and it mentions that server-side streaming is already supported. This makes it a candidate to be considered for the query UI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! We can always put a blocking/sync facade in front of grpc service if streaming to web is not supported, but since it's there already, we should go with streaming for the main API.

@annanay25
Copy link
Member Author

I would like a second review round @yurishkuro

Changes in the last commit -

  • Dropped grpc-gateway
  • Used cmux to multiplex HTTP and GRPC
  • Used stream response for GetTraceRequest

Todo -

  • Add all endpoints including FindTraceIDs etc.
  • Add tests.

model/proto/api_v2.proto Outdated Show resolved Hide resolved

// FIXME: Pass all TraceQueryParameters in SearchRequest?
message SearchRequest {
string query = 1 [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Should parameters be parsed from a string query or should the SearchRequest have all TraceQueryParameters as in -

type TraceQueryParameters struct {
ServiceName string
OperationName string
Tags map[string]string
StartTimeMin time.Time
StartTimeMax time.Time
DurationMin time.Duration
DurationMax time.Duration
NumTraces int
}

I guess the former because protobuf supports just basic data types and not time/maps etc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be structured, as in #1323

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've made the changes.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model/proto/api_v2/query.proto Outdated Show resolved Hide resolved
model/proto/api_v2/query.proto Outdated Show resolved Hide resolved
Annanay added 7 commits April 3, 2019 22:39
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
…er doc

Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
cmd/query/main.go Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved
cmd/query/main.go Outdated Show resolved Hide resolved
model/proto/api_v2/query.proto Outdated Show resolved Hide resolved
model/proto/api_v2/query.proto Outdated Show resolved Hide resolved
model/prototest/model_test.pb.go Outdated Show resolved Hide resolved
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

Thanks for the review @yurishkuro. I've addressed comments and updated.

Annanay and others added 7 commits April 7, 2019 17:29
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@codecov
Copy link

codecov bot commented Apr 8, 2019

Codecov Report

Merging #1307 into master will decrease coverage by 0.02%.
The diff coverage is 97.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1307      +/-   ##
==========================================
- Coverage   99.83%   99.81%   -0.03%     
==========================================
  Files         179      180       +1     
  Lines        8557     8631      +74     
==========================================
+ Hits         8543     8615      +72     
- Misses          7        8       +1     
- Partials        7        8       +1
Impacted Files Coverage Δ
cmd/query/app/grpc_handler.go 97.29% <97.29%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7009c98...8dfc90a. Read the comment docs.

Signed-off-by: Annanay <annanay.a@media.net>
@annanay25
Copy link
Member Author

Thanks for the changes @yurishkuro!

About tests, should I use a mock query service (as in the current commit) or an instance of query service with mock span readers / dependency readers?

@yurishkuro
Copy link
Member

yurishkuro commented Apr 9, 2019

mock QS is fine

Signed-off-by: Annanay <annanay.a@media.net>
@annanay25 annanay25 force-pushed the query-service-grpc branch from b3b446b to 86d770b Compare April 12, 2019 20:12
Annanay added 4 commits April 13, 2019 16:43
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
Signed-off-by: Annanay <annanay.a@media.net>
@annanay25 annanay25 changed the title WIP - gRPC for query service Support gRPC for query service Apr 16, 2019
@annanay25
Copy link
Member Author

@yurishkuro could you please review this? I think the last remaining lines from coverage are stream sends, which I'm not sure how to test.

Yuri Shkuro and others added 3 commits April 16, 2019 19:07
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@yurishkuro yurishkuro merged commit 5b8c1f4 into jaegertracing:master Apr 22, 2019
@yurishkuro
Copy link
Member

🎉

There is a bit of a clean-up I'd like to do in the test, I think it's leaking goroutines, but didn't want to block the PR on that.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annanay25 post-merge comments / improvements

)

var (
grpcServerPort = ":14251"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be using :0 port

go func() {
err := grpcServer.Serve(lis)
require.NoError(t, err)
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goroutine leak? Or will defer server.Stop() in the tests stop it?

return grpcServer, addr, readStorage, dependencyStorage
}

func initializeTestServerGRPCWithOptions(t *testing.T) (*grpc.Server, net.Addr, *spanstoremocks.Reader, *depsmocks.Reader, *spanstoremocks.Reader, *spanstoremocks.Writer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) any reason not to merge this with the above function?
b) instead of returning many objects it's better to return a single struct
c) to avoid server life cycle management, we typically do this

func withGRPCServer(t *testing.T, actualTest func(server *server)) {
    server := ... create ...
    defer server.close() // other life cycle mgmt
    actualTest(server)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booked #1483

Return(mockTrace, nil).Once()

client, conn := newGRPCClient(t, addr)
defer conn.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above, withServerAndClient(t *testing.T, func actualTest(server *server, client *client))

this way it would remove a lot of boilerplate code from the tests

grpcL := s.Match(
cmux.HTTP2HeaderField("content-type", "application/grpc"),
cmux.HTTP2HeaderField("content-type", "application/grpc+proto"))
httpL := s.Match(cmux.Any())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booked #1482 to refactor this out of main

@annanay25
Copy link
Member Author

annanay25 commented Apr 23, 2019

Thanks @yurishkuro! 🎊

I've been traveling but should get a chance to look at this soon :)

Edit: We should now revisit the implementation roadmap in #773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants