Skip to content

Commit

Permalink
move from cmd/zoekt-webserver to grpc/protos
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilmore committed Sep 12, 2023
1 parent a74bcd9 commit 736c674
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 41 deletions.
2 changes: 1 addition & 1 deletion api_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions api_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-webserver/grpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
40 changes: 20 additions & 20 deletions cmd/zoekt-webserver/grpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand All @@ -66,17 +66,17 @@ 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)
}
if !proto.Equal(r, mock.SearchResult.ToProto()) {
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)
}
Expand All @@ -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)
Expand All @@ -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()...)
}
Expand Down Expand Up @@ -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
Expand All @@ -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()...)
Expand All @@ -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 != "" {
Expand All @@ -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}

Expand All @@ -207,15 +207,15 @@ 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

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) {
Expand All @@ -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")
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.

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

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion query/query_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 736c674

Please sign in to comment.