From 736c674089f35dad52dab50d4fe5d5938432d894 Mon Sep 17 00:00:00 2001 From: ggilmore Date: Tue, 12 Sep 2023 07:49:27 -0700 Subject: [PATCH] move from cmd/zoekt-webserver to grpc/protos --- api_proto.go | 2 +- api_proto_test.go | 8 ++-- cmd/zoekt-webserver/grpc/server/server.go | 2 +- .../grpc/server/server_test.go | 40 +++++++++---------- cmd/zoekt-webserver/main.go | 2 +- .../grpc => grpc}/protos/buf.gen.yaml | 0 .../grpc => grpc}/protos/buf.yaml | 0 .../protos/zoekt/webserver/v1/query.pb.go | 10 ++--- .../protos/zoekt/webserver/v1/query.proto | 2 +- .../protos/zoekt/webserver/v1/webserver.pb.go | 9 ++--- .../protos/zoekt/webserver/v1/webserver.proto | 2 +- .../zoekt/webserver/v1/webserver_grpc.pb.go | 0 query/query_proto.go | 2 +- 13 files changed, 38 insertions(+), 41 deletions(-) rename {cmd/zoekt-webserver/grpc => grpc}/protos/buf.gen.yaml (100%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/buf.yaml (100%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/zoekt/webserver/v1/query.pb.go (99%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/zoekt/webserver/v1/query.proto (96%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/zoekt/webserver/v1/webserver.pb.go (99%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/zoekt/webserver/v1/webserver.proto (99%) rename {cmd/zoekt-webserver/grpc => grpc}/protos/zoekt/webserver/v1/webserver_grpc.pb.go (100%) diff --git a/api_proto.go b/api_proto.go index 34ba50148..d9b0efcc8 100644 --- a/api_proto.go +++ b/api_proto.go @@ -18,7 +18,7 @@ import ( "math/rand" "reflect" - proto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" + proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/api_proto_test.go b/api_proto_test.go index 45ba83bc7..13061c25c 100644 --- a/api_proto_test.go +++ b/api_proto_test.go @@ -27,7 +27,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - webserverproto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" + webproto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" "google.golang.org/protobuf/proto" ) @@ -417,8 +417,8 @@ var ( exampleSearchResultBytes []byte // The proto struct representation of the search result - exampleSearchResultProto = func() *webserverproto.SearchResponse { - sr := new(webserverproto.SearchResponse) + exampleSearchResultProto = func() *webproto.SearchResponse { + sr := new(webproto.SearchResponse) err := proto.Unmarshal(exampleSearchResultBytes, sr) if err != nil { panic(err) @@ -472,7 +472,7 @@ func BenchmarkProtoRoundtrip(b *testing.B) { } for _, buf := range buffers { - res := new(webserverproto.SearchResponse) + res := new(webproto.SearchResponse) err := proto.Unmarshal(buf, res) if err != nil { b.Fatal(err) diff --git a/cmd/zoekt-webserver/grpc/server/server.go b/cmd/zoekt-webserver/grpc/server/server.go index e704eea67..6a1392710 100644 --- a/cmd/zoekt-webserver/grpc/server/server.go +++ b/cmd/zoekt-webserver/grpc/server/server.go @@ -4,8 +4,8 @@ import ( "context" "math" - proto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" "github.com/sourcegraph/zoekt/grpc/chunk" + proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/cmd/zoekt-webserver/grpc/server/server_test.go b/cmd/zoekt-webserver/grpc/server/server_test.go index dc9f48062..acce877b9 100644 --- a/cmd/zoekt-webserver/grpc/server/server_test.go +++ b/cmd/zoekt-webserver/grpc/server/server_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - webserverproto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" + "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" "go.uber.org/atomic" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" @@ -52,7 +52,7 @@ func TestClientServer(t *testing.T) { gs := grpc.NewServer() defer gs.Stop() - webserverproto.RegisterWebserverServiceServer(gs, NewServer(adapter{mock})) + v1.RegisterWebserverServiceServer(gs, NewServer(adapter{mock})) ts := httptest.NewServer(h2c.NewHandler(gs, &http2.Server{})) defer ts.Close() @@ -66,9 +66,9 @@ func TestClientServer(t *testing.T) { } defer cc.Close() - client := webserverproto.NewWebserverServiceClient(cc) + client := v1.NewWebserverServiceClient(cc) - r, err := client.Search(context.Background(), &webserverproto.SearchRequest{Query: query.QToProto(mock.WantSearch)}) + r, err := client.Search(context.Background(), &v1.SearchRequest{Query: query.QToProto(mock.WantSearch)}) if err != nil { t.Fatal(err) } @@ -76,7 +76,7 @@ func TestClientServer(t *testing.T) { t.Fatalf("got %+v, want %+v", r, mock.SearchResult.ToProto()) } - l, err := client.List(context.Background(), &webserverproto.ListRequest{Query: query.QToProto(mock.WantList)}) + l, err := client.List(context.Background(), &v1.ListRequest{Query: query.QToProto(mock.WantList)}) if err != nil { t.Fatal(err) } @@ -85,8 +85,8 @@ func TestClientServer(t *testing.T) { t.Fatalf("got %+v, want %+v", l, mock.RepoList.ToProto()) } - request := webserverproto.StreamSearchRequest{ - Request: &webserverproto.SearchRequest{Query: query.QToProto(mock.WantSearch)}, + request := v1.StreamSearchRequest{ + Request: &v1.SearchRequest{Query: query.QToProto(mock.WantSearch)}, } cs, err := client.StreamSearch(context.Background(), &request) @@ -97,7 +97,7 @@ func TestClientServer(t *testing.T) { allResponses := readAllStream(t, cs) // check to make sure that we get the same set of file matches back - var receivedFileMatches []*webserverproto.FileMatch + var receivedFileMatches []*v1.FileMatch for _, r := range allResponses { receivedFileMatches = append(receivedFileMatches, r.GetFiles()...) } @@ -147,7 +147,7 @@ func TestFuzzGRPCChunkSender(t *testing.T) { // Safety, ensure that all other fields are echoed back correctly if the schema ever changes opts := []cmp.Option{ protocmp.Transform(), - protocmp.IgnoreFields(&webserverproto.SearchResponse{}, + protocmp.IgnoreFields(&v1.SearchResponse{}, "progress", // progress is tested above "stats", // aggregated stats are tested below "files", // files are tested separately @@ -161,7 +161,7 @@ func TestFuzzGRPCChunkSender(t *testing.T) { receivedStats := &zoekt.Stats{} - var receivedFileMatches []*webserverproto.FileMatch + var receivedFileMatches []*v1.FileMatch for _, r := range allResponses { receivedStats.Add(zoekt.StatsFromProto(r.GetStats())) receivedFileMatches = append(receivedFileMatches, r.GetFiles()...) @@ -170,7 +170,7 @@ func TestFuzzGRPCChunkSender(t *testing.T) { // Check to make sure that we get one set of stats back if diff := cmp.Diff(expectedResult.GetStats(), receivedStats.ToProto(), protocmp.Transform(), - protocmp.IgnoreFields(&webserverproto.Stats{}, + protocmp.IgnoreFields(&v1.Stats{}, "duration", // for whatever the duration field isn't updated when zoekt.Stats.Add is called ), ); diff != "" { @@ -197,7 +197,7 @@ func TestFuzzGRPCChunkSender(t *testing.T) { } // newPairedSearchStream returns a pair of client and server search streams that are connected to each other. -func newPairedSearchStream(t *testing.T) (webserverproto.WebserverService_StreamSearchClient, webserverproto.WebserverService_StreamSearchServer) { +func newPairedSearchStream(t *testing.T) (v1.WebserverService_StreamSearchClient, v1.WebserverService_StreamSearchServer) { client := &mockSearchStreamClient{t: t} server := &mockSearchStreamServer{t: t, pairedClient: client} @@ -207,7 +207,7 @@ func newPairedSearchStream(t *testing.T) (webserverproto.WebserverService_Stream type mockSearchStreamClient struct { t *testing.T - storedResponses []*webserverproto.StreamSearchResponse + storedResponses []*v1.StreamSearchResponse index int startedReading atomic.Bool @@ -215,7 +215,7 @@ type mockSearchStreamClient struct { grpc.ClientStream } -func (m *mockSearchStreamClient) Recv() (*webserverproto.StreamSearchResponse, error) { +func (m *mockSearchStreamClient) Recv() (*v1.StreamSearchResponse, error) { m.startedReading.Store(true) if m.index >= len(m.storedResponses) { @@ -227,7 +227,7 @@ func (m *mockSearchStreamClient) Recv() (*webserverproto.StreamSearchResponse, e return r, nil } -func (m *mockSearchStreamClient) storeResponse(r *webserverproto.StreamSearchResponse) { +func (m *mockSearchStreamClient) storeResponse(r *v1.StreamSearchResponse) { if m.startedReading.Load() { m.t.Fatalf("cannot store additional responses after starting to read from stream") } @@ -243,18 +243,18 @@ type mockSearchStreamServer struct { grpc.ServerStream } -func (m *mockSearchStreamServer) Send(r *webserverproto.StreamSearchResponse) error { +func (m *mockSearchStreamServer) Send(r *v1.StreamSearchResponse) error { m.pairedClient.storeResponse(r) return nil } var ( - _ webserverproto.WebserverService_StreamSearchServer = &mockSearchStreamServer{} - _ webserverproto.WebserverService_StreamSearchClient = &mockSearchStreamClient{} + _ v1.WebserverService_StreamSearchServer = &mockSearchStreamServer{} + _ v1.WebserverService_StreamSearchClient = &mockSearchStreamClient{} ) -func readAllStream(t *testing.T, cs webserverproto.WebserverService_StreamSearchClient) []*webserverproto.SearchResponse { - var got []*webserverproto.SearchResponse +func readAllStream(t *testing.T, cs v1.WebserverService_StreamSearchClient) []*v1.SearchResponse { + var got []*v1.SearchResponse for { // collect all responses from the stream r, err := cs.Recv() if errors.Is(err, io.EOF) { diff --git a/cmd/zoekt-webserver/main.go b/cmd/zoekt-webserver/main.go index a57e76052..c0865e010 100644 --- a/cmd/zoekt-webserver/main.go +++ b/cmd/zoekt-webserver/main.go @@ -40,10 +40,10 @@ import ( grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/openmetrics/v2" "github.com/sourcegraph/mountinfo" - proto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" zoektgrpc "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/server" "github.com/sourcegraph/zoekt/grpc/internalerrs" "github.com/sourcegraph/zoekt/grpc/messagesize" + proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" diff --git a/cmd/zoekt-webserver/grpc/protos/buf.gen.yaml b/grpc/protos/buf.gen.yaml similarity index 100% rename from cmd/zoekt-webserver/grpc/protos/buf.gen.yaml rename to grpc/protos/buf.gen.yaml diff --git a/cmd/zoekt-webserver/grpc/protos/buf.yaml b/grpc/protos/buf.yaml similarity index 100% rename from cmd/zoekt-webserver/grpc/protos/buf.yaml rename to grpc/protos/buf.yaml diff --git a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.pb.go b/grpc/protos/zoekt/webserver/v1/query.pb.go similarity index 99% rename from cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.pb.go rename to grpc/protos/zoekt/webserver/v1/query.pb.go index 10786524a..f70430513 100644 --- a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.pb.go +++ b/grpc/protos/zoekt/webserver/v1/query.pb.go @@ -1468,13 +1468,11 @@ var file_zoekt_webserver_v1_query_proto_rawDesc = []byte{ 0x38, 0x0a, 0x06, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x78, 0x61, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x05, 0x65, 0x78, 0x61, 0x63, 0x74, 0x42, 0x51, 0x5a, 0x4f, 0x67, 0x69, 0x74, + 0x28, 0x08, 0x52, 0x05, 0x65, 0x78, 0x61, 0x63, 0x74, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, - 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x7a, 0x6f, - 0x65, 0x6b, 0x74, 0x2d, 0x77, 0x65, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x67, 0x72, - 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, - 0x77, 0x65, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.proto b/grpc/protos/zoekt/webserver/v1/query.proto similarity index 96% rename from cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.proto rename to grpc/protos/zoekt/webserver/v1/query.proto index 6a8e4f5aa..4ed08af15 100644 --- a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/query.proto +++ b/grpc/protos/zoekt/webserver/v1/query.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package zoekt.webserver.v1; -option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1"; +option go_package = "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1"; message Q { oneof query { diff --git a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.pb.go b/grpc/protos/zoekt/webserver/v1/webserver.pb.go similarity index 99% rename from cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.pb.go rename to grpc/protos/zoekt/webserver/v1/webserver.pb.go index 9d7806954..5de4b3471 100644 --- a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.pb.go +++ b/grpc/protos/zoekt/webserver/v1/webserver.pb.go @@ -2798,12 +2798,11 @@ var file_zoekt_webserver_v1_webserver_proto_rawDesc = []byte{ 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x77, 0x65, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x51, 0x5a, 0x4f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x22, 0x00, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, - 0x6b, 0x74, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2d, 0x77, 0x65, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6b, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, + 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, + 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.proto b/grpc/protos/zoekt/webserver/v1/webserver.proto similarity index 99% rename from cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.proto rename to grpc/protos/zoekt/webserver/v1/webserver.proto index 3e4994ba7..e2f4abd31 100644 --- a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver.proto +++ b/grpc/protos/zoekt/webserver/v1/webserver.proto @@ -6,7 +6,7 @@ import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "zoekt/webserver/v1/query.proto"; -option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1"; +option go_package = "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1"; service WebserverService { rpc Search(SearchRequest) returns (SearchResponse) {} diff --git a/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver_grpc.pb.go b/grpc/protos/zoekt/webserver/v1/webserver_grpc.pb.go similarity index 100% rename from cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1/webserver_grpc.pb.go rename to grpc/protos/zoekt/webserver/v1/webserver_grpc.pb.go diff --git a/query/query_proto.go b/query/query_proto.go index be23f51c9..63f8a9dd4 100644 --- a/query/query_proto.go +++ b/query/query_proto.go @@ -6,7 +6,7 @@ import ( "github.com/RoaringBitmap/roaring" "github.com/grafana/regexp" - proto "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/protos/zoekt/webserver/v1" + proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" ) func QToProto(q Q) *proto.Q {