fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

sourcegraph-indexserver: add grpc server (#920)

Relates to SPLF-874

This adds a grpc server to sourcegraph-indexserver. For now it supports just one method.

The diff is quite big, so I left comments to mark the most important bits.

I used the opportunity to clean up a bit (=> hence the big diff):
- Reuse grpc logic from webserver and move those bits to "/gprc/..."
- Move "protos" inside the new "grpc" directory (=> requires changes of import statements in Sourcegraph)
- Refactor import aliases for grpc packages across the codebase

Test plan:
I tested this locally by calling the new grpc endpoint directly.

+814 -429
+86 -86
api_proto.go
··· 21 21 "google.golang.org/protobuf/types/known/durationpb" 22 22 "google.golang.org/protobuf/types/known/timestamppb" 23 23 24 - proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 24 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 25 25 ) 26 26 27 - func FileMatchFromProto(p *proto.FileMatch) FileMatch { 27 + func FileMatchFromProto(p *webserverv1.FileMatch) FileMatch { 28 28 lineMatches := make([]LineMatch, len(p.GetLineMatches())) 29 29 for i, lineMatch := range p.GetLineMatches() { 30 30 lineMatches[i] = LineMatchFromProto(lineMatch) ··· 54 54 } 55 55 } 56 56 57 - func (m *FileMatch) ToProto() *proto.FileMatch { 58 - lineMatches := make([]*proto.LineMatch, len(m.LineMatches)) 57 + func (m *FileMatch) ToProto() *webserverv1.FileMatch { 58 + lineMatches := make([]*webserverv1.LineMatch, len(m.LineMatches)) 59 59 for i, lm := range m.LineMatches { 60 60 lineMatches[i] = lm.ToProto() 61 61 } 62 62 63 - chunkMatches := make([]*proto.ChunkMatch, len(m.ChunkMatches)) 63 + chunkMatches := make([]*webserverv1.ChunkMatch, len(m.ChunkMatches)) 64 64 for i, cm := range m.ChunkMatches { 65 65 chunkMatches[i] = cm.ToProto() 66 66 } 67 67 68 - return &proto.FileMatch{ 68 + return &webserverv1.FileMatch{ 69 69 Score: m.Score, 70 70 Debug: m.Debug, 71 71 FileName: []byte(m.FileName), ··· 84 84 } 85 85 } 86 86 87 - func ChunkMatchFromProto(p *proto.ChunkMatch) ChunkMatch { 87 + func ChunkMatchFromProto(p *webserverv1.ChunkMatch) ChunkMatch { 88 88 ranges := make([]Range, len(p.GetRanges())) 89 89 for i, r := range p.GetRanges() { 90 90 ranges[i] = RangeFromProto(r) ··· 107 107 } 108 108 } 109 109 110 - func (cm *ChunkMatch) ToProto() *proto.ChunkMatch { 111 - ranges := make([]*proto.Range, len(cm.Ranges)) 110 + func (cm *ChunkMatch) ToProto() *webserverv1.ChunkMatch { 111 + ranges := make([]*webserverv1.Range, len(cm.Ranges)) 112 112 for i, r := range cm.Ranges { 113 113 ranges[i] = r.ToProto() 114 114 } 115 115 116 - symbolInfo := make([]*proto.SymbolInfo, len(cm.SymbolInfo)) 116 + symbolInfo := make([]*webserverv1.SymbolInfo, len(cm.SymbolInfo)) 117 117 for i, si := range cm.SymbolInfo { 118 118 symbolInfo[i] = si.ToProto() 119 119 } 120 120 121 - return &proto.ChunkMatch{ 121 + return &webserverv1.ChunkMatch{ 122 122 Content: cm.Content, 123 123 ContentStart: cm.ContentStart.ToProto(), 124 124 FileName: cm.FileName, ··· 130 130 } 131 131 } 132 132 133 - func RangeFromProto(p *proto.Range) Range { 133 + func RangeFromProto(p *webserverv1.Range) Range { 134 134 return Range{ 135 135 Start: LocationFromProto(p.GetStart()), 136 136 End: LocationFromProto(p.GetEnd()), 137 137 } 138 138 } 139 139 140 - func (r *Range) ToProto() *proto.Range { 141 - return &proto.Range{ 140 + func (r *Range) ToProto() *webserverv1.Range { 141 + return &webserverv1.Range{ 142 142 Start: r.Start.ToProto(), 143 143 End: r.End.ToProto(), 144 144 } 145 145 } 146 146 147 - func LocationFromProto(p *proto.Location) Location { 147 + func LocationFromProto(p *webserverv1.Location) Location { 148 148 return Location{ 149 149 ByteOffset: p.GetByteOffset(), 150 150 LineNumber: p.GetLineNumber(), ··· 152 152 } 153 153 } 154 154 155 - func (l *Location) ToProto() *proto.Location { 156 - return &proto.Location{ 155 + func (l *Location) ToProto() *webserverv1.Location { 156 + return &webserverv1.Location{ 157 157 ByteOffset: l.ByteOffset, 158 158 LineNumber: l.LineNumber, 159 159 Column: l.Column, 160 160 } 161 161 } 162 162 163 - func LineMatchFromProto(p *proto.LineMatch) LineMatch { 163 + func LineMatchFromProto(p *webserverv1.LineMatch) LineMatch { 164 164 lineFragments := make([]LineFragmentMatch, len(p.GetLineFragments())) 165 165 for i, lineFragment := range p.GetLineFragments() { 166 166 lineFragments[i] = LineFragmentMatchFromProto(lineFragment) ··· 180 180 } 181 181 } 182 182 183 - func (lm *LineMatch) ToProto() *proto.LineMatch { 184 - fragments := make([]*proto.LineFragmentMatch, len(lm.LineFragments)) 183 + func (lm *LineMatch) ToProto() *webserverv1.LineMatch { 184 + fragments := make([]*webserverv1.LineFragmentMatch, len(lm.LineFragments)) 185 185 for i, fragment := range lm.LineFragments { 186 186 fragments[i] = fragment.ToProto() 187 187 } 188 188 189 - return &proto.LineMatch{ 189 + return &webserverv1.LineMatch{ 190 190 Line: lm.Line, 191 191 LineStart: int64(lm.LineStart), 192 192 LineEnd: int64(lm.LineEnd), ··· 200 200 } 201 201 } 202 202 203 - func SymbolFromProto(p *proto.SymbolInfo) *Symbol { 203 + func SymbolFromProto(p *webserverv1.SymbolInfo) *Symbol { 204 204 if p == nil { 205 205 return nil 206 206 } ··· 213 213 } 214 214 } 215 215 216 - func (s *Symbol) ToProto() *proto.SymbolInfo { 216 + func (s *Symbol) ToProto() *webserverv1.SymbolInfo { 217 217 if s == nil { 218 218 return nil 219 219 } 220 220 221 - return &proto.SymbolInfo{ 221 + return &webserverv1.SymbolInfo{ 222 222 Sym: s.Sym, 223 223 Kind: s.Kind, 224 224 Parent: s.Parent, ··· 226 226 } 227 227 } 228 228 229 - func LineFragmentMatchFromProto(p *proto.LineFragmentMatch) LineFragmentMatch { 229 + func LineFragmentMatchFromProto(p *webserverv1.LineFragmentMatch) LineFragmentMatch { 230 230 return LineFragmentMatch{ 231 231 LineOffset: int(p.GetLineOffset()), 232 232 Offset: p.GetOffset(), ··· 235 235 } 236 236 } 237 237 238 - func (lfm *LineFragmentMatch) ToProto() *proto.LineFragmentMatch { 239 - return &proto.LineFragmentMatch{ 238 + func (lfm *LineFragmentMatch) ToProto() *webserverv1.LineFragmentMatch { 239 + return &webserverv1.LineFragmentMatch{ 240 240 LineOffset: int64(lfm.LineOffset), 241 241 Offset: lfm.Offset, 242 242 MatchLength: int64(lfm.MatchLength), ··· 244 244 } 245 245 } 246 246 247 - func FlushReasonFromProto(p proto.FlushReason) FlushReason { 247 + func FlushReasonFromProto(p webserverv1.FlushReason) FlushReason { 248 248 switch p { 249 - case proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED: 249 + case webserverv1.FlushReason_FLUSH_REASON_TIMER_EXPIRED: 250 250 return FlushReasonTimerExpired 251 - case proto.FlushReason_FLUSH_REASON_FINAL_FLUSH: 251 + case webserverv1.FlushReason_FLUSH_REASON_FINAL_FLUSH: 252 252 return FlushReasonFinalFlush 253 - case proto.FlushReason_FLUSH_REASON_MAX_SIZE: 253 + case webserverv1.FlushReason_FLUSH_REASON_MAX_SIZE: 254 254 return FlushReasonMaxSize 255 255 default: 256 256 return FlushReason(0) 257 257 } 258 258 } 259 259 260 - func (fr FlushReason) ToProto() proto.FlushReason { 260 + func (fr FlushReason) ToProto() webserverv1.FlushReason { 261 261 switch fr { 262 262 case FlushReasonTimerExpired: 263 - return proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED 263 + return webserverv1.FlushReason_FLUSH_REASON_TIMER_EXPIRED 264 264 case FlushReasonFinalFlush: 265 - return proto.FlushReason_FLUSH_REASON_FINAL_FLUSH 265 + return webserverv1.FlushReason_FLUSH_REASON_FINAL_FLUSH 266 266 case FlushReasonMaxSize: 267 - return proto.FlushReason_FLUSH_REASON_MAX_SIZE 267 + return webserverv1.FlushReason_FLUSH_REASON_MAX_SIZE 268 268 default: 269 - return proto.FlushReason_FLUSH_REASON_UNKNOWN_UNSPECIFIED 269 + return webserverv1.FlushReason_FLUSH_REASON_UNKNOWN_UNSPECIFIED 270 270 } 271 271 } 272 272 ··· 284 284 } 285 285 } 286 286 287 - func StatsFromProto(p *proto.Stats) Stats { 287 + func StatsFromProto(p *webserverv1.Stats) Stats { 288 288 return Stats{ 289 289 ContentBytesLoaded: p.GetContentBytesLoaded(), 290 290 IndexBytesLoaded: p.GetIndexBytesLoaded(), ··· 309 309 } 310 310 } 311 311 312 - func (s *Stats) ToProto() *proto.Stats { 313 - return &proto.Stats{ 312 + func (s *Stats) ToProto() *webserverv1.Stats { 313 + return &webserverv1.Stats{ 314 314 ContentBytesLoaded: s.ContentBytesLoaded, 315 315 IndexBytesLoaded: s.IndexBytesLoaded, 316 316 Crashes: int64(s.Crashes), ··· 334 334 } 335 335 } 336 336 337 - func ProgressFromProto(p *proto.Progress) Progress { 337 + func ProgressFromProto(p *webserverv1.Progress) Progress { 338 338 return Progress{ 339 339 Priority: p.GetPriority(), 340 340 MaxPendingPriority: p.GetMaxPendingPriority(), 341 341 } 342 342 } 343 343 344 - func (p *Progress) ToProto() *proto.Progress { 345 - return &proto.Progress{ 344 + func (p *Progress) ToProto() *webserverv1.Progress { 345 + return &webserverv1.Progress{ 346 346 Priority: p.Priority, 347 347 MaxPendingPriority: p.MaxPendingPriority, 348 348 } 349 349 } 350 350 351 - func SearchResultFromStreamProto(p *proto.StreamSearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 351 + func SearchResultFromStreamProto(p *webserverv1.StreamSearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 352 352 if p == nil { 353 353 return nil 354 354 } ··· 356 356 return SearchResultFromProto(p.GetResponseChunk(), repoURLs, lineFragments) 357 357 } 358 358 359 - func SearchResultFromProto(p *proto.SearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 359 + func SearchResultFromProto(p *webserverv1.SearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 360 360 if p == nil { 361 361 return nil 362 362 } ··· 377 377 } 378 378 } 379 379 380 - func (sr *SearchResult) ToProto() *proto.SearchResponse { 380 + func (sr *SearchResult) ToProto() *webserverv1.SearchResponse { 381 381 if sr == nil { 382 382 return nil 383 383 } 384 384 385 - files := make([]*proto.FileMatch, len(sr.Files)) 385 + files := make([]*webserverv1.FileMatch, len(sr.Files)) 386 386 for i, file := range sr.Files { 387 387 files[i] = file.ToProto() 388 388 } 389 389 390 - return &proto.SearchResponse{ 390 + return &webserverv1.SearchResponse{ 391 391 Stats: sr.Stats.ToProto(), 392 392 Progress: sr.Progress.ToProto(), 393 393 ··· 395 395 } 396 396 } 397 397 398 - func (sr *SearchResult) ToStreamProto() *proto.StreamSearchResponse { 398 + func (sr *SearchResult) ToStreamProto() *webserverv1.StreamSearchResponse { 399 399 if sr == nil { 400 400 return nil 401 401 } 402 402 403 - return &proto.StreamSearchResponse{ResponseChunk: sr.ToProto()} 403 + return &webserverv1.StreamSearchResponse{ResponseChunk: sr.ToProto()} 404 404 } 405 405 406 - func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch { 406 + func RepositoryBranchFromProto(p *webserverv1.RepositoryBranch) RepositoryBranch { 407 407 return RepositoryBranch{ 408 408 Name: p.GetName(), 409 409 Version: p.GetVersion(), 410 410 } 411 411 } 412 412 413 - func (r *RepositoryBranch) ToProto() *proto.RepositoryBranch { 414 - return &proto.RepositoryBranch{ 413 + func (r *RepositoryBranch) ToProto() *webserverv1.RepositoryBranch { 414 + return &webserverv1.RepositoryBranch{ 415 415 Name: r.Name, 416 416 Version: r.Version, 417 417 } 418 418 } 419 419 420 - func RepositoryFromProto(p *proto.Repository) Repository { 420 + func RepositoryFromProto(p *webserverv1.Repository) Repository { 421 421 branches := make([]RepositoryBranch, len(p.GetBranches())) 422 422 for i, branch := range p.GetBranches() { 423 423 branches[i] = RepositoryBranchFromProto(branch) ··· 456 456 } 457 457 } 458 458 459 - func (r *Repository) ToProto() *proto.Repository { 459 + func (r *Repository) ToProto() *webserverv1.Repository { 460 460 if r == nil { 461 461 return nil 462 462 } 463 463 464 - branches := make([]*proto.RepositoryBranch, len(r.Branches)) 464 + branches := make([]*webserverv1.RepositoryBranch, len(r.Branches)) 465 465 for i, branch := range r.Branches { 466 466 branches[i] = branch.ToProto() 467 467 } 468 468 469 - subRepoMap := make(map[string]*proto.Repository, len(r.SubRepoMap)) 469 + subRepoMap := make(map[string]*webserverv1.Repository, len(r.SubRepoMap)) 470 470 for name, repo := range r.SubRepoMap { 471 471 subRepoMap[name] = repo.ToProto() 472 472 } ··· 476 476 fileTombstones = append(fileTombstones, file) 477 477 } 478 478 479 - return &proto.Repository{ 479 + return &webserverv1.Repository{ 480 480 TenantId: int64(r.TenantID), 481 481 Id: r.ID, 482 482 Name: r.Name, ··· 498 498 } 499 499 } 500 500 501 - func IndexMetadataFromProto(p *proto.IndexMetadata) IndexMetadata { 501 + func IndexMetadataFromProto(p *webserverv1.IndexMetadata) IndexMetadata { 502 502 languageMap := make(map[string]uint16, len(p.GetLanguageMap())) 503 503 for language, id := range p.GetLanguageMap() { 504 504 languageMap[language] = uint16(id) ··· 516 516 } 517 517 } 518 518 519 - func (m *IndexMetadata) ToProto() *proto.IndexMetadata { 519 + func (m *IndexMetadata) ToProto() *webserverv1.IndexMetadata { 520 520 if m == nil { 521 521 return nil 522 522 } ··· 526 526 languageMap[language] = uint32(id) 527 527 } 528 528 529 - return &proto.IndexMetadata{ 529 + return &webserverv1.IndexMetadata{ 530 530 IndexFormatVersion: int64(m.IndexFormatVersion), 531 531 IndexFeatureVersion: int64(m.IndexFeatureVersion), 532 532 IndexMinReaderVersion: int64(m.IndexMinReaderVersion), ··· 538 538 } 539 539 } 540 540 541 - func RepoStatsFromProto(p *proto.RepoStats) RepoStats { 541 + func RepoStatsFromProto(p *webserverv1.RepoStats) RepoStats { 542 542 return RepoStats{ 543 543 Repos: int(p.GetRepos()), 544 544 Shards: int(p.GetShards()), ··· 551 551 } 552 552 } 553 553 554 - func (s *RepoStats) ToProto() *proto.RepoStats { 555 - return &proto.RepoStats{ 554 + func (s *RepoStats) ToProto() *webserverv1.RepoStats { 555 + return &webserverv1.RepoStats{ 556 556 Repos: int64(s.Repos), 557 557 Shards: int64(s.Shards), 558 558 Documents: int64(s.Documents), ··· 564 564 } 565 565 } 566 566 567 - func RepoListEntryFromProto(p *proto.RepoListEntry) *RepoListEntry { 567 + func RepoListEntryFromProto(p *webserverv1.RepoListEntry) *RepoListEntry { 568 568 if p == nil { 569 569 return nil 570 570 } ··· 576 576 } 577 577 } 578 578 579 - func (r *RepoListEntry) ToProto() *proto.RepoListEntry { 579 + func (r *RepoListEntry) ToProto() *webserverv1.RepoListEntry { 580 580 if r == nil { 581 581 return nil 582 582 } 583 583 584 - return &proto.RepoListEntry{ 584 + return &webserverv1.RepoListEntry{ 585 585 Repository: r.Repository.ToProto(), 586 586 IndexMetadata: r.IndexMetadata.ToProto(), 587 587 Stats: r.Stats.ToProto(), 588 588 } 589 589 } 590 590 591 - func MinimalRepoListEntryFromProto(p *proto.MinimalRepoListEntry) MinimalRepoListEntry { 591 + func MinimalRepoListEntryFromProto(p *webserverv1.MinimalRepoListEntry) MinimalRepoListEntry { 592 592 branches := make([]RepositoryBranch, len(p.GetBranches())) 593 593 for i, branch := range p.GetBranches() { 594 594 branches[i] = RepositoryBranchFromProto(branch) ··· 601 601 } 602 602 } 603 603 604 - func (m *MinimalRepoListEntry) ToProto() *proto.MinimalRepoListEntry { 605 - branches := make([]*proto.RepositoryBranch, len(m.Branches)) 604 + func (m *MinimalRepoListEntry) ToProto() *webserverv1.MinimalRepoListEntry { 605 + branches := make([]*webserverv1.RepositoryBranch, len(m.Branches)) 606 606 for i, branch := range m.Branches { 607 607 branches[i] = branch.ToProto() 608 608 } 609 - return &proto.MinimalRepoListEntry{ 609 + return &webserverv1.MinimalRepoListEntry{ 610 610 HasSymbols: m.HasSymbols, 611 611 Branches: branches, 612 612 IndexTimeUnix: m.IndexTimeUnix, 613 613 } 614 614 } 615 615 616 - func RepoListFromProto(p *proto.ListResponse) *RepoList { 616 + func RepoListFromProto(p *webserverv1.ListResponse) *RepoList { 617 617 repos := make([]*RepoListEntry, len(p.GetRepos())) 618 618 for i, repo := range p.GetRepos() { 619 619 repos[i] = RepoListEntryFromProto(repo) ··· 632 632 } 633 633 } 634 634 635 - func (r *RepoList) ToProto() *proto.ListResponse { 636 - repos := make([]*proto.RepoListEntry, len(r.Repos)) 635 + func (r *RepoList) ToProto() *webserverv1.ListResponse { 636 + repos := make([]*webserverv1.RepoListEntry, len(r.Repos)) 637 637 for i, repo := range r.Repos { 638 638 repos[i] = repo.ToProto() 639 639 } 640 640 641 - reposMap := make(map[uint32]*proto.MinimalRepoListEntry, len(r.ReposMap)) 641 + reposMap := make(map[uint32]*webserverv1.MinimalRepoListEntry, len(r.ReposMap)) 642 642 for id, repo := range r.ReposMap { 643 643 reposMap[id] = repo.ToProto() 644 644 } 645 645 646 - return &proto.ListResponse{ 646 + return &webserverv1.ListResponse{ 647 647 Repos: repos, 648 648 ReposMap: reposMap, 649 649 Crashes: int64(r.Crashes), ··· 651 651 } 652 652 } 653 653 654 - func (l *ListOptions) ToProto() *proto.ListOptions { 654 + func (l *ListOptions) ToProto() *webserverv1.ListOptions { 655 655 if l == nil { 656 656 return nil 657 657 } 658 - var field proto.ListOptions_RepoListField 658 + var field webserverv1.ListOptions_RepoListField 659 659 switch l.Field { 660 660 case RepoListFieldRepos: 661 - field = proto.ListOptions_REPO_LIST_FIELD_REPOS 661 + field = webserverv1.ListOptions_REPO_LIST_FIELD_REPOS 662 662 case RepoListFieldReposMap: 663 - field = proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP 663 + field = webserverv1.ListOptions_REPO_LIST_FIELD_REPOS_MAP 664 664 } 665 665 666 - return &proto.ListOptions{ 666 + return &webserverv1.ListOptions{ 667 667 Field: field, 668 668 } 669 669 } 670 670 671 - func ListOptionsFromProto(p *proto.ListOptions) *ListOptions { 671 + func ListOptionsFromProto(p *webserverv1.ListOptions) *ListOptions { 672 672 if p == nil { 673 673 return nil 674 674 } 675 675 var field RepoListField 676 676 switch p.GetField() { 677 - case proto.ListOptions_REPO_LIST_FIELD_REPOS: 677 + case webserverv1.ListOptions_REPO_LIST_FIELD_REPOS: 678 678 field = RepoListFieldRepos 679 - case proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP: 679 + case webserverv1.ListOptions_REPO_LIST_FIELD_REPOS_MAP: 680 680 field = RepoListFieldReposMap 681 681 } 682 682 return &ListOptions{ ··· 684 684 } 685 685 } 686 686 687 - func SearchOptionsFromProto(p *proto.SearchOptions) *SearchOptions { 687 + func SearchOptionsFromProto(p *webserverv1.SearchOptions) *SearchOptions { 688 688 if p == nil { 689 689 return nil 690 690 } ··· 707 707 } 708 708 } 709 709 710 - func (s *SearchOptions) ToProto() *proto.SearchOptions { 710 + func (s *SearchOptions) ToProto() *webserverv1.SearchOptions { 711 711 if s == nil { 712 712 return nil 713 713 } 714 714 715 - return &proto.SearchOptions{ 715 + return &webserverv1.SearchOptions{ 716 716 EstimateDocCount: s.EstimateDocCount, 717 717 Whole: s.Whole, 718 718 ShardMaxMatchCount: int64(s.ShardMaxMatchCount),
+5 -5
api_proto_test.go
··· 25 25 "testing/quick" 26 26 "time" 27 27 28 + fuzz "github.com/AdaLogics/go-fuzz-headers" 28 29 "github.com/google/go-cmp/cmp" 29 30 "github.com/google/go-cmp/cmp/cmpopts" 30 - webproto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 31 31 "google.golang.org/protobuf/proto" 32 32 33 - fuzz "github.com/AdaLogics/go-fuzz-headers" 33 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 34 34 ) 35 35 36 36 func TestProtoRoundtrip(t *testing.T) { ··· 413 413 exampleSearchResultBytes []byte 414 414 415 415 // The proto struct representation of the search result 416 - exampleSearchResultProto = func() *webproto.SearchResponse { 417 - sr := new(webproto.SearchResponse) 416 + exampleSearchResultProto = func() *webserverv1.SearchResponse { 417 + sr := new(webserverv1.SearchResponse) 418 418 err := proto.Unmarshal(exampleSearchResultBytes, sr) 419 419 if err != nil { 420 420 panic(err) ··· 468 468 } 469 469 470 470 for _, buf := range buffers { 471 - res := new(webproto.SearchResponse) 471 + res := new(webserverv1.SearchResponse) 472 472 err := proto.Unmarshal(buf, res) 473 473 if err != nil { 474 474 b.Fatal(err)
+11
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/buf.gen.yaml
··· 1 + # Configuration file for https://buf.build/, which we use for Protobuf code generation. 2 + version: v1 3 + plugins: 4 + - plugin: buf.build/protocolbuffers/go:v1.28.1 5 + out: . 6 + opt: 7 + - paths=source_relative 8 + - plugin: buf.build/grpc/go:v1.3.0 9 + out: . 10 + opt: 11 + - paths=source_relative
+202
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver.pb.go
··· 1 + // Code generated by protoc-gen-go. DO NOT EDIT. 2 + // versions: 3 + // protoc-gen-go v1.28.1 4 + // protoc (unknown) 5 + // source: indexserver.proto 6 + 7 + package v1 8 + 9 + import ( 10 + protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 + protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 + reflect "reflect" 13 + sync "sync" 14 + ) 15 + 16 + const ( 17 + // Verify that this generated code is sufficiently up-to-date. 18 + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 + // Verify that runtime/protoimpl is sufficiently up-to-date. 20 + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 + ) 22 + 23 + type DeleteAllDataRequest struct { 24 + state protoimpl.MessageState 25 + sizeCache protoimpl.SizeCache 26 + unknownFields protoimpl.UnknownFields 27 + } 28 + 29 + func (x *DeleteAllDataRequest) Reset() { 30 + *x = DeleteAllDataRequest{} 31 + if protoimpl.UnsafeEnabled { 32 + mi := &file_indexserver_proto_msgTypes[0] 33 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 34 + ms.StoreMessageInfo(mi) 35 + } 36 + } 37 + 38 + func (x *DeleteAllDataRequest) String() string { 39 + return protoimpl.X.MessageStringOf(x) 40 + } 41 + 42 + func (*DeleteAllDataRequest) ProtoMessage() {} 43 + 44 + func (x *DeleteAllDataRequest) ProtoReflect() protoreflect.Message { 45 + mi := &file_indexserver_proto_msgTypes[0] 46 + if protoimpl.UnsafeEnabled && x != nil { 47 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 48 + if ms.LoadMessageInfo() == nil { 49 + ms.StoreMessageInfo(mi) 50 + } 51 + return ms 52 + } 53 + return mi.MessageOf(x) 54 + } 55 + 56 + // Deprecated: Use DeleteAllDataRequest.ProtoReflect.Descriptor instead. 57 + func (*DeleteAllDataRequest) Descriptor() ([]byte, []int) { 58 + return file_indexserver_proto_rawDescGZIP(), []int{0} 59 + } 60 + 61 + type DeleteAllDataResponse struct { 62 + state protoimpl.MessageState 63 + sizeCache protoimpl.SizeCache 64 + unknownFields protoimpl.UnknownFields 65 + } 66 + 67 + func (x *DeleteAllDataResponse) Reset() { 68 + *x = DeleteAllDataResponse{} 69 + if protoimpl.UnsafeEnabled { 70 + mi := &file_indexserver_proto_msgTypes[1] 71 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 72 + ms.StoreMessageInfo(mi) 73 + } 74 + } 75 + 76 + func (x *DeleteAllDataResponse) String() string { 77 + return protoimpl.X.MessageStringOf(x) 78 + } 79 + 80 + func (*DeleteAllDataResponse) ProtoMessage() {} 81 + 82 + func (x *DeleteAllDataResponse) ProtoReflect() protoreflect.Message { 83 + mi := &file_indexserver_proto_msgTypes[1] 84 + if protoimpl.UnsafeEnabled && x != nil { 85 + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 86 + if ms.LoadMessageInfo() == nil { 87 + ms.StoreMessageInfo(mi) 88 + } 89 + return ms 90 + } 91 + return mi.MessageOf(x) 92 + } 93 + 94 + // Deprecated: Use DeleteAllDataResponse.ProtoReflect.Descriptor instead. 95 + func (*DeleteAllDataResponse) Descriptor() ([]byte, []int) { 96 + return file_indexserver_proto_rawDescGZIP(), []int{1} 97 + } 98 + 99 + var File_indexserver_proto protoreflect.FileDescriptor 100 + 101 + var file_indexserver_proto_rawDesc = []byte{ 102 + 0x0a, 0x11, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 103 + 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 104 + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 105 + 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 106 + 0x74, 0x22, 0x17, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 107 + 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x8e, 0x01, 0x0a, 0x1d, 0x53, 108 + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x73, 109 + 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6d, 0x0a, 0x0d, 110 + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x2a, 0x2e, 111 + 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 112 + 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 113 + 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 114 + 0x74, 0x2e, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 115 + 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x6c, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 116 + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x02, 0x42, 0x5c, 0x5a, 0x5a, 0x67, 117 + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 118 + 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 119 + 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2d, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 120 + 0x68, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 121 + 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 122 + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 123 + 0x33, 124 + } 125 + 126 + var ( 127 + file_indexserver_proto_rawDescOnce sync.Once 128 + file_indexserver_proto_rawDescData = file_indexserver_proto_rawDesc 129 + ) 130 + 131 + func file_indexserver_proto_rawDescGZIP() []byte { 132 + file_indexserver_proto_rawDescOnce.Do(func() { 133 + file_indexserver_proto_rawDescData = protoimpl.X.CompressGZIP(file_indexserver_proto_rawDescData) 134 + }) 135 + return file_indexserver_proto_rawDescData 136 + } 137 + 138 + var file_indexserver_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 139 + var file_indexserver_proto_goTypes = []interface{}{ 140 + (*DeleteAllDataRequest)(nil), // 0: zoekt.indexserver.v1.DeleteAllDataRequest 141 + (*DeleteAllDataResponse)(nil), // 1: zoekt.indexserver.v1.DeleteAllDataResponse 142 + } 143 + var file_indexserver_proto_depIdxs = []int32{ 144 + 0, // 0: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:input_type -> zoekt.indexserver.v1.DeleteAllDataRequest 145 + 1, // 1: zoekt.indexserver.v1.SourcegraphIndexserverService.DeleteAllData:output_type -> zoekt.indexserver.v1.DeleteAllDataResponse 146 + 1, // [1:2] is the sub-list for method output_type 147 + 0, // [0:1] is the sub-list for method input_type 148 + 0, // [0:0] is the sub-list for extension type_name 149 + 0, // [0:0] is the sub-list for extension extendee 150 + 0, // [0:0] is the sub-list for field type_name 151 + } 152 + 153 + func init() { file_indexserver_proto_init() } 154 + func file_indexserver_proto_init() { 155 + if File_indexserver_proto != nil { 156 + return 157 + } 158 + if !protoimpl.UnsafeEnabled { 159 + file_indexserver_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 160 + switch v := v.(*DeleteAllDataRequest); i { 161 + case 0: 162 + return &v.state 163 + case 1: 164 + return &v.sizeCache 165 + case 2: 166 + return &v.unknownFields 167 + default: 168 + return nil 169 + } 170 + } 171 + file_indexserver_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 172 + switch v := v.(*DeleteAllDataResponse); i { 173 + case 0: 174 + return &v.state 175 + case 1: 176 + return &v.sizeCache 177 + case 2: 178 + return &v.unknownFields 179 + default: 180 + return nil 181 + } 182 + } 183 + } 184 + type x struct{} 185 + out := protoimpl.TypeBuilder{ 186 + File: protoimpl.DescBuilder{ 187 + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 188 + RawDescriptor: file_indexserver_proto_rawDesc, 189 + NumEnums: 0, 190 + NumMessages: 2, 191 + NumExtensions: 0, 192 + NumServices: 1, 193 + }, 194 + GoTypes: file_indexserver_proto_goTypes, 195 + DependencyIndexes: file_indexserver_proto_depIdxs, 196 + MessageInfos: file_indexserver_proto_msgTypes, 197 + }.Build() 198 + File_indexserver_proto = out.File 199 + file_indexserver_proto_rawDesc = nil 200 + file_indexserver_proto_goTypes = nil 201 + file_indexserver_proto_depIdxs = nil 202 + }
+17
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver.proto
··· 1 + syntax = "proto3"; 2 + 3 + package zoekt.indexserver.v1; 4 + 5 + option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/zoekt/indexserver/v1"; 6 + 7 + message DeleteAllDataRequest {} 8 + 9 + message DeleteAllDataResponse {} 10 + 11 + service SourcegraphIndexserverService { 12 + // DeleteAllData deletes all data for the tenant in the request context. 13 + // This is used for pruning all data after a tenant has been deleted. 14 + rpc DeleteAllData(DeleteAllDataRequest) returns (DeleteAllDataResponse) { 15 + option idempotency_level = IDEMPOTENT; 16 + } 17 + }
+114
cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1/indexserver_grpc.pb.go
··· 1 + // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 + // versions: 3 + // - protoc-gen-go-grpc v1.3.0 4 + // - protoc (unknown) 5 + // source: indexserver.proto 6 + 7 + package v1 8 + 9 + import ( 10 + context "context" 11 + grpc "google.golang.org/grpc" 12 + codes "google.golang.org/grpc/codes" 13 + status "google.golang.org/grpc/status" 14 + ) 15 + 16 + // This is a compile-time assertion to ensure that this generated file 17 + // is compatible with the grpc package it is being compiled against. 18 + // Requires gRPC-Go v1.32.0 or later. 19 + const _ = grpc.SupportPackageIsVersion7 20 + 21 + const ( 22 + SourcegraphIndexserverService_DeleteAllData_FullMethodName = "/zoekt.indexserver.v1.SourcegraphIndexserverService/DeleteAllData" 23 + ) 24 + 25 + // SourcegraphIndexserverServiceClient is the client API for SourcegraphIndexserverService service. 26 + // 27 + // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 28 + type SourcegraphIndexserverServiceClient interface { 29 + // DeleteAllData deletes all data for the tenant in the request context. 30 + // This is used for pruning all data after a tenant has been deleted. 31 + DeleteAllData(ctx context.Context, in *DeleteAllDataRequest, opts ...grpc.CallOption) (*DeleteAllDataResponse, error) 32 + } 33 + 34 + type sourcegraphIndexserverServiceClient struct { 35 + cc grpc.ClientConnInterface 36 + } 37 + 38 + func NewSourcegraphIndexserverServiceClient(cc grpc.ClientConnInterface) SourcegraphIndexserverServiceClient { 39 + return &sourcegraphIndexserverServiceClient{cc} 40 + } 41 + 42 + func (c *sourcegraphIndexserverServiceClient) DeleteAllData(ctx context.Context, in *DeleteAllDataRequest, opts ...grpc.CallOption) (*DeleteAllDataResponse, error) { 43 + out := new(DeleteAllDataResponse) 44 + err := c.cc.Invoke(ctx, SourcegraphIndexserverService_DeleteAllData_FullMethodName, in, out, opts...) 45 + if err != nil { 46 + return nil, err 47 + } 48 + return out, nil 49 + } 50 + 51 + // SourcegraphIndexserverServiceServer is the server API for SourcegraphIndexserverService service. 52 + // All implementations must embed UnimplementedSourcegraphIndexserverServiceServer 53 + // for forward compatibility 54 + type SourcegraphIndexserverServiceServer interface { 55 + // DeleteAllData deletes all data for the tenant in the request context. 56 + // This is used for pruning all data after a tenant has been deleted. 57 + DeleteAllData(context.Context, *DeleteAllDataRequest) (*DeleteAllDataResponse, error) 58 + mustEmbedUnimplementedSourcegraphIndexserverServiceServer() 59 + } 60 + 61 + // UnimplementedSourcegraphIndexserverServiceServer must be embedded to have forward compatible implementations. 62 + type UnimplementedSourcegraphIndexserverServiceServer struct { 63 + } 64 + 65 + func (UnimplementedSourcegraphIndexserverServiceServer) DeleteAllData(context.Context, *DeleteAllDataRequest) (*DeleteAllDataResponse, error) { 66 + return nil, status.Errorf(codes.Unimplemented, "method DeleteAllData not implemented") 67 + } 68 + func (UnimplementedSourcegraphIndexserverServiceServer) mustEmbedUnimplementedSourcegraphIndexserverServiceServer() { 69 + } 70 + 71 + // UnsafeSourcegraphIndexserverServiceServer may be embedded to opt out of forward compatibility for this service. 72 + // Use of this interface is not recommended, as added methods to SourcegraphIndexserverServiceServer will 73 + // result in compilation errors. 74 + type UnsafeSourcegraphIndexserverServiceServer interface { 75 + mustEmbedUnimplementedSourcegraphIndexserverServiceServer() 76 + } 77 + 78 + func RegisterSourcegraphIndexserverServiceServer(s grpc.ServiceRegistrar, srv SourcegraphIndexserverServiceServer) { 79 + s.RegisterService(&SourcegraphIndexserverService_ServiceDesc, srv) 80 + } 81 + 82 + func _SourcegraphIndexserverService_DeleteAllData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 83 + in := new(DeleteAllDataRequest) 84 + if err := dec(in); err != nil { 85 + return nil, err 86 + } 87 + if interceptor == nil { 88 + return srv.(SourcegraphIndexserverServiceServer).DeleteAllData(ctx, in) 89 + } 90 + info := &grpc.UnaryServerInfo{ 91 + Server: srv, 92 + FullMethod: SourcegraphIndexserverService_DeleteAllData_FullMethodName, 93 + } 94 + handler := func(ctx context.Context, req interface{}) (interface{}, error) { 95 + return srv.(SourcegraphIndexserverServiceServer).DeleteAllData(ctx, req.(*DeleteAllDataRequest)) 96 + } 97 + return interceptor(ctx, in, info, handler) 98 + } 99 + 100 + // SourcegraphIndexserverService_ServiceDesc is the grpc.ServiceDesc for SourcegraphIndexserverService service. 101 + // It's only intended for direct use with grpc.RegisterService, 102 + // and not to be introspected or modified (even as a copy) 103 + var SourcegraphIndexserverService_ServiceDesc = grpc.ServiceDesc{ 104 + ServiceName: "zoekt.indexserver.v1.SourcegraphIndexserverService", 105 + HandlerType: (*SourcegraphIndexserverServiceServer)(nil), 106 + Methods: []grpc.MethodDesc{ 107 + { 108 + MethodName: "DeleteAllData", 109 + Handler: _SourcegraphIndexserverService_DeleteAllData_Handler, 110 + }, 111 + }, 112 + Streams: []grpc.StreamDesc{}, 113 + Metadata: "indexserver.proto", 114 + }
+50 -50
cmd/zoekt-sourcegraph-indexserver/index_test.go
··· 16 16 "github.com/google/go-cmp/cmp" 17 17 "github.com/google/go-cmp/cmp/cmpopts" 18 18 "github.com/sourcegraph/log/logtest" 19 - proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 20 - "github.com/sourcegraph/zoekt/internal/ctags" 21 - "github.com/sourcegraph/zoekt/internal/tenant/tenanttest" 22 19 "github.com/stretchr/testify/require" 23 20 "google.golang.org/grpc" 24 21 "google.golang.org/protobuf/testing/protocmp" 25 22 "google.golang.org/protobuf/types/known/timestamppb" 26 23 27 24 "github.com/sourcegraph/zoekt" 25 + configv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 26 + "github.com/sourcegraph/zoekt/internal/ctags" 27 + "github.com/sourcegraph/zoekt/internal/tenant/tenanttest" 28 28 ) 29 29 30 30 func TestIterateIndexOptions_Fingerprint(t *testing.T) { 31 - fingerprintV0 := &proto.Fingerprint{ 31 + fingerprintV0 := &configv1.Fingerprint{ 32 32 Identifier: 100, 33 33 GeneratedAt: timestamppb.New(time.Unix(100, 0)), 34 34 } 35 35 36 - fingerprintV1 := &proto.Fingerprint{ 36 + fingerprintV1 := &configv1.Fingerprint{ 37 37 Identifier: 101, 38 38 GeneratedAt: timestamppb.New(time.Unix(101, 0)), 39 39 } 40 40 41 - fingerprintV2 := &proto.Fingerprint{ 41 + fingerprintV2 := &configv1.Fingerprint{ 42 42 Identifier: 102, 43 43 GeneratedAt: timestamppb.New(time.Unix(102, 0)), 44 44 } 45 45 46 - mkSearchConfigurationResponse := func(fingerprint *proto.Fingerprint, repoIDs ...int32) *proto.SearchConfigurationResponse { 47 - repositories := make([]*proto.ZoektIndexOptions, 0, len(repoIDs)) 46 + mkSearchConfigurationResponse := func(fingerprint *configv1.Fingerprint, repoIDs ...int32) *configv1.SearchConfigurationResponse { 47 + repositories := make([]*configv1.ZoektIndexOptions, 0, len(repoIDs)) 48 48 for _, repoID := range repoIDs { 49 - repositories = append(repositories, &proto.ZoektIndexOptions{ 49 + repositories = append(repositories, &configv1.ZoektIndexOptions{ 50 50 RepoId: repoID, 51 51 }) 52 52 } 53 53 54 - return &proto.SearchConfigurationResponse{ 54 + return &configv1.SearchConfigurationResponse{ 55 55 UpdatedOptions: repositories, 56 56 Fingerprint: fingerprint, 57 57 } 58 58 } 59 59 60 60 grpcClient := &mockGRPCClient{ 61 - mockList: func(_ context.Context, in *proto.ListRequest, opts ...grpc.CallOption) (*proto.ListResponse, error) { 62 - return &proto.ListResponse{ 61 + mockList: func(_ context.Context, in *configv1.ListRequest, opts ...grpc.CallOption) (*configv1.ListResponse, error) { 62 + return &configv1.ListResponse{ 63 63 RepoIds: []int32{1, 2, 3}, 64 64 }, nil 65 65 }, ··· 75 75 type step struct { 76 76 name string 77 77 78 - wantFingerprint *proto.Fingerprint 79 - returnFingerprint *proto.Fingerprint 78 + wantFingerprint *configv1.Fingerprint 79 + returnFingerprint *configv1.Fingerprint 80 80 returnErr error 81 81 skipCheckingRepoIDs bool 82 82 } ··· 108 108 } { 109 109 t.Run(step.name, func(t *testing.T) { 110 110 called := false 111 - grpcClient.mockSearchConfiguration = func(_ context.Context, in *proto.SearchConfigurationRequest, opts ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { 111 + grpcClient.mockSearchConfiguration = func(_ context.Context, in *configv1.SearchConfigurationRequest, opts ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) { 112 112 called = true 113 113 114 114 diff := cmp.Diff(step.wantFingerprint, in.GetFingerprint(), protocmp.Transform()) ··· 157 157 158 158 type testCase struct { 159 159 name string 160 - response *proto.SearchConfigurationResponse 160 + response *configv1.SearchConfigurationResponse 161 161 want *IndexOptions 162 162 wantErr string 163 163 } ··· 165 165 for _, tc := range []testCase{ 166 166 { 167 167 name: "symbols, large files", 168 - response: &proto.SearchConfigurationResponse{ 169 - UpdatedOptions: []*proto.ZoektIndexOptions{ 168 + response: &configv1.SearchConfigurationResponse{ 169 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 170 170 { 171 171 Symbols: true, 172 172 LargeFiles: []string{"foo", "bar"}, ··· 180 180 }, 181 181 { 182 182 name: "no symbols , large files", 183 - response: &proto.SearchConfigurationResponse{ 184 - UpdatedOptions: []*proto.ZoektIndexOptions{ 183 + response: &configv1.SearchConfigurationResponse{ 184 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 185 185 { 186 186 Symbols: true, 187 187 LargeFiles: []string{"foo", "bar"}, ··· 202 202 203 203 { 204 204 name: "symbols", 205 - response: &proto.SearchConfigurationResponse{ 206 - UpdatedOptions: []*proto.ZoektIndexOptions{ 205 + response: &configv1.SearchConfigurationResponse{ 206 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 207 207 { 208 208 Symbols: true, 209 209 }, ··· 215 215 }, 216 216 { 217 217 name: "repoID", 218 - response: &proto.SearchConfigurationResponse{ 219 - UpdatedOptions: []*proto.ZoektIndexOptions{ 218 + response: &configv1.SearchConfigurationResponse{ 219 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 220 220 { 221 221 RepoId: 123, 222 222 }, ··· 228 228 }, 229 229 { 230 230 name: "error", 231 - response: &proto.SearchConfigurationResponse{ 232 - UpdatedOptions: []*proto.ZoektIndexOptions{ 231 + response: &configv1.SearchConfigurationResponse{ 232 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 233 233 { 234 234 Error: "boom", 235 235 }, ··· 241 241 } { 242 242 called := false 243 243 mockClient := &mockGRPCClient{ 244 - mockSearchConfiguration: func(_ context.Context, _ *proto.SearchConfigurationRequest, _ ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { 244 + mockSearchConfiguration: func(_ context.Context, _ *configv1.SearchConfigurationRequest, _ ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) { 245 245 called = true 246 246 return tc.response, nil 247 247 }, ··· 294 294 295 295 called := false 296 296 mockClient := &mockGRPCClient{ 297 - mockSearchConfiguration: func(_ context.Context, _ *proto.SearchConfigurationRequest, _ ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { 297 + mockSearchConfiguration: func(_ context.Context, _ *configv1.SearchConfigurationRequest, _ ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) { 298 298 called = true 299 299 return nil, nil 300 300 }, ··· 332 332 } 333 333 }) 334 334 335 - var response *proto.SearchConfigurationResponse 335 + var response *configv1.SearchConfigurationResponse 336 336 mockClient := &mockGRPCClient{ 337 - mockSearchConfiguration: func(_ context.Context, req *proto.SearchConfigurationRequest, _ ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { 337 + mockSearchConfiguration: func(_ context.Context, req *configv1.SearchConfigurationRequest, _ ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) { 338 338 if len(req.GetRepoIds()) == 0 || req.GetRepoIds()[0] != 123 { 339 339 return nil, errors.New("invalid repo id") 340 340 } ··· 345 345 sg := newSourcegraphClient(&url.URL{Path: "/"}, "", mockClient, WithBatchSize(0)) 346 346 347 347 cases := []struct { 348 - Response *proto.SearchConfigurationResponse 348 + Response *configv1.SearchConfigurationResponse 349 349 *IndexOptions 350 350 }{ 351 351 { 352 - Response: &proto.SearchConfigurationResponse{ 353 - UpdatedOptions: []*proto.ZoektIndexOptions{ 352 + Response: &configv1.SearchConfigurationResponse{ 353 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 354 354 { 355 355 Symbols: true, 356 356 LargeFiles: []string{"foo", "bar"}, ··· 366 366 }, 367 367 368 368 { 369 - Response: &proto.SearchConfigurationResponse{ 370 - UpdatedOptions: []*proto.ZoektIndexOptions{ 369 + Response: &configv1.SearchConfigurationResponse{ 370 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 371 371 { 372 372 Symbols: false, 373 373 LargeFiles: []string{"foo", "bar"}, ··· 382 382 }, 383 383 384 384 { 385 - Response: &proto.SearchConfigurationResponse{}, 385 + Response: &configv1.SearchConfigurationResponse{}, 386 386 }, 387 387 388 388 { 389 - Response: &proto.SearchConfigurationResponse{ 390 - UpdatedOptions: []*proto.ZoektIndexOptions{ 389 + Response: &configv1.SearchConfigurationResponse{ 390 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 391 391 { 392 392 Symbols: true, 393 393 }, ··· 401 401 }, 402 402 403 403 { 404 - Response: &proto.SearchConfigurationResponse{ 405 - UpdatedOptions: []*proto.ZoektIndexOptions{ 404 + Response: &configv1.SearchConfigurationResponse{ 405 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 406 406 { 407 407 RepoId: 123, 408 408 }, ··· 416 416 }, 417 417 418 418 { 419 - Response: &proto.SearchConfigurationResponse{ 420 - UpdatedOptions: []*proto.ZoektIndexOptions{ 419 + Response: &configv1.SearchConfigurationResponse{ 420 + UpdatedOptions: []*configv1.ZoektIndexOptions{ 421 421 { 422 422 Error: "boom", 423 423 }, ··· 454 454 // Special case our fingerprint API which doesn't return anything if the 455 455 // repo hasn't changed. 456 456 t.Run("unchanged", func(t *testing.T) { 457 - response = &proto.SearchConfigurationResponse{} 457 + response = &configv1.SearchConfigurationResponse{} 458 458 459 459 got := false 460 460 var err error ··· 724 724 }) 725 725 726 726 type mockGRPCClient struct { 727 - mockSearchConfiguration func(context.Context, *proto.SearchConfigurationRequest, ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) 728 - mockList func(context.Context, *proto.ListRequest, ...grpc.CallOption) (*proto.ListResponse, error) 729 - mockUpdateIndexStatus func(context.Context, *proto.UpdateIndexStatusRequest, ...grpc.CallOption) (*proto.UpdateIndexStatusResponse, error) 727 + mockSearchConfiguration func(context.Context, *configv1.SearchConfigurationRequest, ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) 728 + mockList func(context.Context, *configv1.ListRequest, ...grpc.CallOption) (*configv1.ListResponse, error) 729 + mockUpdateIndexStatus func(context.Context, *configv1.UpdateIndexStatusRequest, ...grpc.CallOption) (*configv1.UpdateIndexStatusResponse, error) 730 730 } 731 731 732 - func (m *mockGRPCClient) SearchConfiguration(ctx context.Context, in *proto.SearchConfigurationRequest, opts ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { 732 + func (m *mockGRPCClient) SearchConfiguration(ctx context.Context, in *configv1.SearchConfigurationRequest, opts ...grpc.CallOption) (*configv1.SearchConfigurationResponse, error) { 733 733 if m.mockSearchConfiguration != nil { 734 734 return m.mockSearchConfiguration(ctx, in, opts...) 735 735 } ··· 737 737 return nil, fmt.Errorf("mock RPC SearchConfiguration not implemented") 738 738 } 739 739 740 - func (m *mockGRPCClient) List(ctx context.Context, in *proto.ListRequest, opts ...grpc.CallOption) (*proto.ListResponse, error) { 740 + func (m *mockGRPCClient) List(ctx context.Context, in *configv1.ListRequest, opts ...grpc.CallOption) (*configv1.ListResponse, error) { 741 741 if m.mockList != nil { 742 742 return m.mockList(ctx, in, opts...) 743 743 } ··· 745 745 return nil, fmt.Errorf("mock RPC List not implemented") 746 746 } 747 747 748 - func (m *mockGRPCClient) UpdateIndexStatus(ctx context.Context, in *proto.UpdateIndexStatusRequest, opts ...grpc.CallOption) (*proto.UpdateIndexStatusResponse, error) { 748 + func (m *mockGRPCClient) UpdateIndexStatus(ctx context.Context, in *configv1.UpdateIndexStatusRequest, opts ...grpc.CallOption) (*configv1.UpdateIndexStatusResponse, error) { 749 749 if m.mockUpdateIndexStatus != nil { 750 750 return m.mockUpdateIndexStatus(ctx, in, opts...) 751 751 } ··· 753 753 return nil, fmt.Errorf("mock RPC UpdateIndexStatus not implemented") 754 754 } 755 755 756 - var _ proto.ZoektConfigurationServiceClient = &mockGRPCClient{} 756 + var _ configv1.ZoektConfigurationServiceClient = &mockGRPCClient{} 757 757 758 758 // Tests whether we can set git config values without error. 759 759 func TestSetZoektConfig(t *testing.T) {
+23 -3
cmd/zoekt-sourcegraph-indexserver/main.go
··· 51 51 "github.com/prometheus/client_golang/prometheus/promauto" 52 52 sglog "github.com/sourcegraph/log" 53 53 "github.com/sourcegraph/mountinfo" 54 + 54 55 "github.com/sourcegraph/zoekt" 55 - proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 56 + configv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 57 + indexserverv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/zoekt/indexserver/v1" 58 + "github.com/sourcegraph/zoekt/grpc/defaults" 59 + "github.com/sourcegraph/zoekt/grpc/grpcutil" 56 60 "github.com/sourcegraph/zoekt/grpc/internalerrs" 57 61 "github.com/sourcegraph/zoekt/grpc/messagesize" 58 62 "github.com/sourcegraph/zoekt/index" ··· 226 230 227 231 // timeout defines how long the index server waits before killing an indexing job. 228 232 timeout time.Duration 233 + 234 + indexserverv1.UnimplementedSourcegraphIndexserverServiceServer 229 235 } 230 236 231 237 var ( ··· 1040 1046 return fmt.Sprintf("Indexed %s with state %s", args.String(), state), nil 1041 1047 } 1042 1048 1049 + // DeleteAllData deletes all shards in the index and trash belonging to the 1050 + // tenant associated with the request. This is stubbed out for now. 1051 + func (s *Server) DeleteAllData(_ context.Context, _ *indexserverv1.DeleteAllDataRequest) (*indexserverv1.DeleteAllDataResponse, error) { 1052 + s.logger.Warn("DeleteAllData") 1053 + return &indexserverv1.DeleteAllDataResponse{}, nil 1054 + } 1055 + 1043 1056 func listIndexed(indexDir string) []uint32 { 1044 1057 index := getShards(indexDir) 1045 1058 metricNumIndexed.Set(float64(len(index))) ··· 1324 1337 1325 1338 go func() { 1326 1339 debugLog.Printf("serving HTTP on %s", conf.listen) 1340 + mux := grpcutil.MultiplexGRPC(newGRPCServer(sglog.Scoped("indexserver"), s), mux) 1327 1341 log.Fatal(http.ListenAndServe(conf.listen, mux)) 1328 1342 }() 1329 1343 ··· 1513 1527 }, err 1514 1528 } 1515 1529 1530 + func newGRPCServer(logger sglog.Logger, s *Server, additionalOpts ...grpc.ServerOption) *grpc.Server { 1531 + grpcServer := defaults.NewServer(logger, additionalOpts...) 1532 + indexserverv1.RegisterSourcegraphIndexserverServiceServer(grpcServer, s) 1533 + return grpcServer 1534 + } 1535 + 1516 1536 // defaultGRPCServiceConfigurationJSON is the default gRPC service configuration 1517 1537 // for the indexed-search-configuration gRPC service. 1518 1538 // ··· 1544 1564 // This can be overridden by providing custom Server/Dial options. 1545 1565 const defaultGRPCMessageReceiveSizeBytes = 90 * 1024 * 1024 // 90 MB 1546 1566 1547 - func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.DialOption) (proto.ZoektConfigurationServiceClient, error) { 1567 + func dialGRPCClient(addr string, logger sglog.Logger, additionalOpts ...grpc.DialOption) (configv1.ZoektConfigurationServiceClient, error) { 1548 1568 metrics := clientMetricsOnce() 1549 1569 1550 1570 // If the service seems to be unavailable, this ··· 1595 1615 return nil, fmt.Errorf("dialing %q: %w", addr, err) 1596 1616 } 1597 1617 1598 - client := proto.NewZoektConfigurationServiceClient(cc) 1618 + client := configv1.NewZoektConfigurationServiceClient(cc) 1599 1619 return client, nil 1600 1620 } 1601 1621
+3 -3
cmd/zoekt-sourcegraph-indexserver/main_test.go
··· 22 22 "github.com/google/go-cmp/cmp" 23 23 24 24 "github.com/sourcegraph/zoekt" 25 - proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 25 + configv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 26 26 "github.com/sourcegraph/zoekt/internal/tenant" 27 27 ) 28 28 ··· 150 150 s := newSourcegraphClient(&testURL, testHostname, grpcClient, clientOptions...) 151 151 152 152 listCalled := false 153 - grpcClient.mockList = func(ctx context.Context, in *proto.ListRequest, opts ...grpc.CallOption) (*proto.ListResponse, error) { 153 + grpcClient.mockList = func(ctx context.Context, in *configv1.ListRequest, opts ...grpc.CallOption) (*configv1.ListResponse, error) { 154 154 listCalled = true 155 155 156 156 gotRepoIDs := in.GetIndexedIds() ··· 172 172 t.Errorf("hostname mismatch (-want +got):\n%s", diff) 173 173 } 174 174 175 - return &proto.ListResponse{RepoIds: []int32{1, 2, 3}}, nil 175 + return &configv1.ListResponse{RepoIds: []int32{1, 2, 3}}, nil 176 176 } 177 177 178 178 ctx := context.Background()
cmd/zoekt-sourcegraph-indexserver/protos/buf.yaml cmd/zoekt-sourcegraph-indexserver/grpc/protos/buf.yaml
cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1/buf.gen.yaml cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/buf.gen.yaml
+5 -5
cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go
··· 952 952 0x68, 0x2e, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 953 953 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 954 954 0x6e, 0x64, 0x65, 0x78, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 955 - 0x73, 0x65, 0x22, 0x00, 0x42, 0x6a, 0x5a, 0x68, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 955 + 0x73, 0x65, 0x22, 0x00, 0x42, 0x6f, 0x5a, 0x6d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 956 956 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 957 957 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2d, 0x73, 958 958 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 959 - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x73, 0x6f, 960 - 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 0x6f, 0x65, 0x6b, 0x74, 0x2f, 961 - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 962 - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 959 + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 960 + 0x6f, 0x73, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x7a, 961 + 0x6f, 0x65, 0x6b, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 962 + 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 963 963 } 964 964 965 965 var (
+1 -1
cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1/configuration.proto cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.proto
··· 4 4 5 5 import "google/protobuf/timestamp.proto"; 6 6 7 - option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1"; 7 + option go_package = "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1"; 8 8 9 9 service ZoektConfigurationService { 10 10 // SearchConfiguration returns the current indexing configuration for the specified repositories.
cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1/configuration_grpc.pb.go cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration_grpc.pb.go
+23 -23
cmd/zoekt-sourcegraph-indexserver/sg.go
··· 18 18 "time" 19 19 20 20 "github.com/go-git/go-git/v5" 21 - "github.com/sourcegraph/zoekt/internal/ctags" 22 21 "golang.org/x/net/trace" 23 22 24 23 "github.com/sourcegraph/zoekt" 25 - proto "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1" 24 + configv1 "github.com/sourcegraph/zoekt/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1" 25 + "github.com/sourcegraph/zoekt/internal/ctags" 26 26 ) 27 27 28 28 // SourcegraphListResult is the return value of Sourcegraph.List. It is its ··· 82 82 } 83 83 } 84 84 85 - func newSourcegraphClient(rootURL *url.URL, hostname string, grpcClient proto.ZoektConfigurationServiceClient, opts ...SourcegraphClientOption) *sourcegraphClient { 85 + func newSourcegraphClient(rootURL *url.URL, hostname string, grpcClient configv1.ZoektConfigurationServiceClient, opts ...SourcegraphClientOption) *sourcegraphClient { 86 86 client := &sourcegraphClient{ 87 87 Root: rootURL, 88 88 Hostname: hostname, ··· 112 112 BatchSize int 113 113 114 114 // grpcClient is used to make requests to the Sourcegraph instance if gRPC is enabled. 115 - grpcClient proto.ZoektConfigurationServiceClient 115 + grpcClient configv1.ZoektConfigurationServiceClient 116 116 117 117 // configFingerprintProto is the last config fingerprint (as GRPC) returned from 118 118 // Sourcegraph. It can be used for future calls to the configuration ··· 120 120 // 121 121 // configFingerprintProto is mutually exclusive with configFingerprint - this field 122 122 // will only be used if gRPC is enabled. 123 - configFingerprintProto *proto.Fingerprint 123 + configFingerprintProto *configv1.Fingerprint 124 124 125 125 // configFingerprintReset tracks when we should zero out the 126 126 // configFingerprint. We want to periodically do this just in case our ··· 268 268 Error string 269 269 } 270 270 271 - func (o *indexOptionsItem) FromProto(x *proto.ZoektIndexOptions) { 271 + func (o *indexOptionsItem) FromProto(x *configv1.ZoektIndexOptions) { 272 272 branches := make([]zoekt.RepositoryBranch, 0, len(x.Branches)) 273 273 for _, b := range x.GetBranches() { 274 274 branches = append(branches, zoekt.RepositoryBranch{ ··· 308 308 *o = item 309 309 } 310 310 311 - func (o *indexOptionsItem) ToProto() *proto.ZoektIndexOptions { 312 - branches := make([]*proto.ZoektRepositoryBranch, 0, len(o.Branches)) 311 + func (o *indexOptionsItem) ToProto() *configv1.ZoektIndexOptions { 312 + branches := make([]*configv1.ZoektRepositoryBranch, 0, len(o.Branches)) 313 313 for _, b := range o.Branches { 314 - branches = append(branches, &proto.ZoektRepositoryBranch{ 314 + branches = append(branches, &configv1.ZoektRepositoryBranch{ 315 315 Name: b.Name, 316 316 Version: b.Version, 317 317 }) 318 318 } 319 319 320 - languageMap := make([]*proto.LanguageMapping, 0, len(o.LanguageMap)) 320 + languageMap := make([]*configv1.LanguageMapping, 0, len(o.LanguageMap)) 321 321 322 322 for lang, parser := range o.LanguageMap { 323 - languageMap = append(languageMap, &proto.LanguageMapping{ 323 + languageMap = append(languageMap, &configv1.LanguageMapping{ 324 324 Language: lang, 325 - Ctags: proto.CTagsParserType(parser), 325 + Ctags: configv1.CTagsParserType(parser), 326 326 }) 327 327 } 328 328 329 - return &proto.ZoektIndexOptions{ 329 + return &configv1.ZoektIndexOptions{ 330 330 RepoId: int32(o.RepoID), 331 331 LargeFiles: o.LargeFiles, 332 332 Symbols: o.Symbols, ··· 348 348 } 349 349 } 350 350 351 - func (s *sourcegraphClient) getIndexOptions(ctx context.Context, fingerprint *proto.Fingerprint, repos []uint32) ([]indexOptionsItem, *proto.Fingerprint, error) { 351 + func (s *sourcegraphClient) getIndexOptions(ctx context.Context, fingerprint *configv1.Fingerprint, repos []uint32) ([]indexOptionsItem, *configv1.Fingerprint, error) { 352 352 repoIDs := make([]int32, 0, len(repos)) 353 353 for _, id := range repos { 354 354 repoIDs = append(repoIDs, int32(id)) 355 355 } 356 356 357 - req := proto.SearchConfigurationRequest{ 357 + req := configv1.SearchConfigurationRequest{ 358 358 RepoIds: repoIDs, 359 359 Fingerprint: fingerprint, 360 360 } ··· 382 382 } 383 383 384 384 func (s *sourcegraphClient) listRepoIDs(ctx context.Context, indexed []uint32) ([]uint32, error) { 385 - var request proto.ListRequest 385 + var request configv1.ListRequest 386 386 request.Hostname = s.Hostname 387 387 request.IndexedIds = make([]int32, 0, len(indexed)) 388 388 for _, id := range indexed { ··· 412 412 Repositories []indexStatus 413 413 } 414 414 415 - func (u *updateIndexStatusRequest) ToProto() *proto.UpdateIndexStatusRequest { 416 - repositories := make([]*proto.UpdateIndexStatusRequest_Repository, 0, len(u.Repositories)) 415 + func (u *updateIndexStatusRequest) ToProto() *configv1.UpdateIndexStatusRequest { 416 + repositories := make([]*configv1.UpdateIndexStatusRequest_Repository, 0, len(u.Repositories)) 417 417 418 418 for _, repo := range u.Repositories { 419 - branches := make([]*proto.ZoektRepositoryBranch, 0, len(repo.Branches)) 419 + branches := make([]*configv1.ZoektRepositoryBranch, 0, len(repo.Branches)) 420 420 421 421 for _, branch := range repo.Branches { 422 - branches = append(branches, &proto.ZoektRepositoryBranch{ 422 + branches = append(branches, &configv1.ZoektRepositoryBranch{ 423 423 Name: branch.Name, 424 424 Version: branch.Version, 425 425 }) 426 426 } 427 427 428 - repositories = append(repositories, &proto.UpdateIndexStatusRequest_Repository{ 428 + repositories = append(repositories, &configv1.UpdateIndexStatusRequest_Repository{ 429 429 RepoId: repo.RepoID, 430 430 Branches: branches, 431 431 IndexTimeUnix: repo.IndexTimeUnix, 432 432 }) 433 433 } 434 434 435 - return &proto.UpdateIndexStatusRequest{ 435 + return &configv1.UpdateIndexStatusRequest{ 436 436 Repositories: repositories, 437 437 } 438 438 } 439 439 440 - func (u *updateIndexStatusRequest) FromProto(x *proto.UpdateIndexStatusRequest) { 440 + func (u *updateIndexStatusRequest) FromProto(x *configv1.UpdateIndexStatusRequest) { 441 441 protoRepositories := x.GetRepositories() 442 442 repositories := make([]indexStatus, 0, len(protoRepositories)) 443 443
+13 -13
cmd/zoekt-webserver/grpc/server/server.go
··· 4 4 "context" 5 5 "math" 6 6 7 - "github.com/sourcegraph/zoekt/grpc/chunk" 8 - proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 9 7 "google.golang.org/grpc/codes" 10 8 "google.golang.org/grpc/status" 11 9 12 10 "github.com/sourcegraph/zoekt" 11 + "github.com/sourcegraph/zoekt/grpc/chunk" 12 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 13 13 "github.com/sourcegraph/zoekt/query" 14 14 ) 15 15 ··· 20 20 } 21 21 22 22 type Server struct { 23 - proto.UnimplementedWebserverServiceServer 23 + webserverv1.UnimplementedWebserverServiceServer 24 24 streamer zoekt.Streamer 25 25 } 26 26 27 - func (s *Server) Search(ctx context.Context, req *proto.SearchRequest) (*proto.SearchResponse, error) { 27 + func (s *Server) Search(ctx context.Context, req *webserverv1.SearchRequest) (*webserverv1.SearchResponse, error) { 28 28 q, err := query.QFromProto(req.GetQuery()) 29 29 if err != nil { 30 30 return nil, status.Error(codes.InvalidArgument, err.Error()) ··· 38 38 return res.ToProto(), nil 39 39 } 40 40 41 - func (s *Server) StreamSearch(req *proto.StreamSearchRequest, ss proto.WebserverService_StreamSearchServer) error { 41 + func (s *Server) StreamSearch(req *webserverv1.StreamSearchRequest, ss webserverv1.WebserverService_StreamSearchServer) error { 42 42 request := req.GetRequest() 43 43 44 44 q, err := query.QFromProto(request.GetQuery()) ··· 56 56 return err 57 57 } 58 58 59 - func (s *Server) List(ctx context.Context, req *proto.ListRequest) (*proto.ListResponse, error) { 59 + func (s *Server) List(ctx context.Context, req *webserverv1.ListRequest) (*webserverv1.ListResponse, error) { 60 60 q, err := query.QFromProto(req.GetQuery()) 61 61 if err != nil { 62 62 return nil, status.Error(codes.InvalidArgument, err.Error()) ··· 71 71 } 72 72 73 73 // gRPCChunkSender is a zoekt.Sender that sends small chunks of FileMatches to the provided gRPC stream. 74 - func gRPCChunkSender(ss proto.WebserverService_StreamSearchServer) zoekt.Sender { 74 + func gRPCChunkSender(ss webserverv1.WebserverService_StreamSearchServer) zoekt.Sender { 75 75 f := func(r *zoekt.SearchResult) { 76 76 result := r.ToStreamProto().GetResponseChunk() 77 77 78 78 if len(result.GetFiles()) == 0 { // stats-only result, send it immediately 79 - _ = ss.Send(&proto.StreamSearchResponse{ 79 + _ = ss.Send(&webserverv1.StreamSearchResponse{ 80 80 ResponseChunk: result, 81 81 }) 82 82 return ··· 87 87 statsSent := false 88 88 numFilesSent := 0 89 89 90 - sendFunc := func(filesChunk []*proto.FileMatch) error { 90 + sendFunc := func(filesChunk []*webserverv1.FileMatch) error { 91 91 numFilesSent += len(filesChunk) 92 92 93 - var stats *proto.Stats 93 + var stats *webserverv1.Stats 94 94 if !statsSent { // We only send stats back on the first chunk 95 95 statsSent = true 96 96 stats = result.GetStats() ··· 99 99 progress := result.GetProgress() 100 100 101 101 if numFilesSent < len(result.GetFiles()) { // more chunks to come 102 - progress = &proto.Progress{ 102 + progress = &webserverv1.Progress{ 103 103 Priority: result.GetProgress().GetPriority(), 104 104 105 105 // We want the client to consume the entire set of chunks - so we manually ··· 111 111 } 112 112 } 113 113 114 - return ss.Send(&proto.StreamSearchResponse{ 115 - ResponseChunk: &proto.SearchResponse{ 114 + return ss.Send(&webserverv1.StreamSearchResponse{ 115 + ResponseChunk: &webserverv1.SearchResponse{ 116 116 Files: filesChunk, 117 117 118 118 Stats: stats,
+20 -20
cmd/zoekt-webserver/grpc/server/server_test.go
··· 12 12 13 13 "github.com/google/go-cmp/cmp" 14 14 "github.com/google/go-cmp/cmp/cmpopts" 15 - "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 16 15 "go.uber.org/atomic" 17 16 "golang.org/x/net/http2" 18 17 "golang.org/x/net/http2/h2c" ··· 22 21 "google.golang.org/protobuf/testing/protocmp" 23 22 24 23 "github.com/sourcegraph/zoekt" 24 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 25 25 "github.com/sourcegraph/zoekt/internal/mockSearcher" 26 26 "github.com/sourcegraph/zoekt/query" 27 27 ) ··· 52 52 gs := grpc.NewServer() 53 53 defer gs.Stop() 54 54 55 - v1.RegisterWebserverServiceServer(gs, NewServer(adapter{mock})) 55 + webserverv1.RegisterWebserverServiceServer(gs, NewServer(adapter{mock})) 56 56 ts := httptest.NewServer(h2c.NewHandler(gs, &http2.Server{})) 57 57 defer ts.Close() 58 58 ··· 66 66 } 67 67 defer cc.Close() 68 68 69 - client := v1.NewWebserverServiceClient(cc) 69 + client := webserverv1.NewWebserverServiceClient(cc) 70 70 71 - r, err := client.Search(context.Background(), &v1.SearchRequest{Query: query.QToProto(mock.WantSearch)}) 71 + r, err := client.Search(context.Background(), &webserverv1.SearchRequest{Query: query.QToProto(mock.WantSearch)}) 72 72 if err != nil { 73 73 t.Fatal(err) 74 74 } ··· 76 76 t.Fatalf("got %+v, want %+v", r, mock.SearchResult.ToProto()) 77 77 } 78 78 79 - l, err := client.List(context.Background(), &v1.ListRequest{Query: query.QToProto(mock.WantList)}) 79 + l, err := client.List(context.Background(), &webserverv1.ListRequest{Query: query.QToProto(mock.WantList)}) 80 80 if err != nil { 81 81 t.Fatal(err) 82 82 } ··· 85 85 t.Fatalf("got %+v, want %+v", l, mock.RepoList.ToProto()) 86 86 } 87 87 88 - request := v1.StreamSearchRequest{ 89 - Request: &v1.SearchRequest{Query: query.QToProto(mock.WantSearch)}, 88 + request := webserverv1.StreamSearchRequest{ 89 + Request: &webserverv1.SearchRequest{Query: query.QToProto(mock.WantSearch)}, 90 90 } 91 91 92 92 cs, err := client.StreamSearch(context.Background(), &request) ··· 97 97 allResponses := readAllStream(t, cs) 98 98 99 99 // check to make sure that we get the same set of file matches back 100 - var receivedFileMatches []*v1.FileMatch 100 + var receivedFileMatches []*webserverv1.FileMatch 101 101 for _, r := range allResponses { 102 102 receivedFileMatches = append(receivedFileMatches, r.GetFiles()...) 103 103 } ··· 145 145 // Safety, ensure that all other fields are echoed back correctly if the schema ever changes 146 146 opts := []cmp.Option{ 147 147 protocmp.Transform(), 148 - protocmp.IgnoreFields(&v1.SearchResponse{}, 148 + protocmp.IgnoreFields(&webserverv1.SearchResponse{}, 149 149 "progress", // progress is tested above 150 150 "stats", // aggregated stats are tested below 151 151 "files", // files are tested separately ··· 159 159 160 160 receivedStats := &zoekt.Stats{} 161 161 162 - var receivedFileMatches []*v1.FileMatch 162 + var receivedFileMatches []*webserverv1.FileMatch 163 163 for _, r := range allResponses { 164 164 receivedStats.Add(zoekt.StatsFromProto(r.GetStats())) 165 165 receivedFileMatches = append(receivedFileMatches, r.GetFiles()...) ··· 168 168 // Check to make sure that we get one set of stats back 169 169 if diff := cmp.Diff(expectedResult.GetStats(), receivedStats.ToProto(), 170 170 protocmp.Transform(), 171 - protocmp.IgnoreFields(&v1.Stats{}, 171 + protocmp.IgnoreFields(&webserverv1.Stats{}, 172 172 "duration", // for whatever the duration field isn't updated when zoekt.Stats.Add is called 173 173 ), 174 174 ); diff != "" { ··· 195 195 } 196 196 197 197 // newPairedSearchStream returns a pair of client and server search streams that are connected to each other. 198 - func newPairedSearchStream(t *testing.T) (v1.WebserverService_StreamSearchClient, v1.WebserverService_StreamSearchServer) { 198 + func newPairedSearchStream(t *testing.T) (webserverv1.WebserverService_StreamSearchClient, webserverv1.WebserverService_StreamSearchServer) { 199 199 client := &mockSearchStreamClient{t: t} 200 200 server := &mockSearchStreamServer{t: t, pairedClient: client} 201 201 ··· 205 205 type mockSearchStreamClient struct { 206 206 t *testing.T 207 207 208 - storedResponses []*v1.StreamSearchResponse 208 + storedResponses []*webserverv1.StreamSearchResponse 209 209 index int 210 210 211 211 startedReading atomic.Bool ··· 213 213 grpc.ClientStream 214 214 } 215 215 216 - func (m *mockSearchStreamClient) Recv() (*v1.StreamSearchResponse, error) { 216 + func (m *mockSearchStreamClient) Recv() (*webserverv1.StreamSearchResponse, error) { 217 217 m.startedReading.Store(true) 218 218 219 219 if m.index >= len(m.storedResponses) { ··· 225 225 return r, nil 226 226 } 227 227 228 - func (m *mockSearchStreamClient) storeResponse(r *v1.StreamSearchResponse) { 228 + func (m *mockSearchStreamClient) storeResponse(r *webserverv1.StreamSearchResponse) { 229 229 if m.startedReading.Load() { 230 230 m.t.Fatalf("cannot store additional responses after starting to read from stream") 231 231 } ··· 241 241 grpc.ServerStream 242 242 } 243 243 244 - func (m *mockSearchStreamServer) Send(r *v1.StreamSearchResponse) error { 244 + func (m *mockSearchStreamServer) Send(r *webserverv1.StreamSearchResponse) error { 245 245 m.pairedClient.storeResponse(r) 246 246 return nil 247 247 } 248 248 249 249 var ( 250 - _ v1.WebserverService_StreamSearchServer = &mockSearchStreamServer{} 251 - _ v1.WebserverService_StreamSearchClient = &mockSearchStreamClient{} 250 + _ webserverv1.WebserverService_StreamSearchServer = &mockSearchStreamServer{} 251 + _ webserverv1.WebserverService_StreamSearchClient = &mockSearchStreamClient{} 252 252 ) 253 253 254 - func readAllStream(t *testing.T, cs v1.WebserverService_StreamSearchClient) []*v1.SearchResponse { 255 - var got []*v1.SearchResponse 254 + func readAllStream(t *testing.T, cs webserverv1.WebserverService_StreamSearchClient) []*webserverv1.SearchResponse { 255 + var got []*webserverv1.SearchResponse 256 256 for { // collect all responses from the stream 257 257 r, err := cs.Recv() 258 258 if errors.Is(err, io.EOF) {
+16 -85
cmd/zoekt-webserver/main.go
··· 34 34 "path/filepath" 35 35 "strconv" 36 36 "strings" 37 - "sync" 38 37 "time" 39 38 40 - grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" 41 - "github.com/sourcegraph/mountinfo" 42 - "github.com/sourcegraph/zoekt/internal/debugserver" 43 - "github.com/sourcegraph/zoekt/internal/shards" 44 - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" 45 - "golang.org/x/net/http2" 46 - "golang.org/x/net/http2/h2c" 47 - "golang.org/x/sys/unix" 48 - "google.golang.org/grpc" 49 - 50 39 "github.com/opentracing/opentracing-go" 51 40 "github.com/prometheus/client_golang/prometheus" 52 41 "github.com/prometheus/client_golang/prometheus/promauto" 53 42 "github.com/shirou/gopsutil/v3/disk" 54 43 sglog "github.com/sourcegraph/log" 44 + "github.com/sourcegraph/mountinfo" 45 + "github.com/uber/jaeger-client-go" 46 + oteltrace "go.opentelemetry.io/otel/trace" 47 + "go.uber.org/automaxprocs/maxprocs" 48 + "golang.org/x/sys/unix" 49 + "google.golang.org/grpc" 50 + 55 51 "github.com/sourcegraph/zoekt" 56 - zoektgrpc "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/server" 57 - "github.com/sourcegraph/zoekt/grpc/internalerrs" 58 - "github.com/sourcegraph/zoekt/grpc/messagesize" 59 - "github.com/sourcegraph/zoekt/grpc/propagator" 60 - proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 52 + grpcserver "github.com/sourcegraph/zoekt/cmd/zoekt-webserver/grpc/server" 53 + "github.com/sourcegraph/zoekt/grpc/defaults" 54 + "github.com/sourcegraph/zoekt/grpc/grpcutil" 55 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 61 56 "github.com/sourcegraph/zoekt/index" 57 + "github.com/sourcegraph/zoekt/internal/debugserver" 62 58 "github.com/sourcegraph/zoekt/internal/profiler" 63 - "github.com/sourcegraph/zoekt/internal/tenant" 59 + "github.com/sourcegraph/zoekt/internal/shards" 64 60 "github.com/sourcegraph/zoekt/internal/trace" 65 61 "github.com/sourcegraph/zoekt/internal/tracer" 66 62 "github.com/sourcegraph/zoekt/query" 67 63 "github.com/sourcegraph/zoekt/web" 68 - "github.com/uber/jaeger-client-go" 69 - oteltrace "go.opentelemetry.io/otel/trace" 70 - "go.uber.org/automaxprocs/maxprocs" 71 64 ) 72 65 73 66 const logFormat = "2006-01-02T15-04-05.999999999Z07" ··· 297 290 streamer := web.NewTraceAwareSearcher(s.Searcher) 298 291 grpcServer := newGRPCServer(logger, streamer) 299 292 300 - handler = multiplexGRPC(grpcServer, handler) 293 + handler = grpcutil.MultiplexGRPC(grpcServer, handler) 301 294 302 295 srv := &http.Server{ 303 296 Addr: *listen, ··· 333 326 } 334 327 } 335 328 336 - // multiplexGRPC takes a gRPC server and a plain HTTP handler and multiplexes the 337 - // request handling. Any requests that declare themselves as gRPC requests are routed 338 - // to the gRPC server, all others are routed to the httpHandler. 339 - func multiplexGRPC(grpcServer *grpc.Server, httpHandler http.Handler) http.Handler { 340 - newHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 341 - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { 342 - grpcServer.ServeHTTP(w, r) 343 - } else { 344 - httpHandler.ServeHTTP(w, r) 345 - } 346 - }) 347 - 348 - // Until we enable TLS, we need to fall back to the h2c protocol, which is 349 - // basically HTTP2 without TLS. The standard library does not implement the 350 - // h2s protocol, so this hijacks h2s requests and handles them correctly. 351 - return h2c.NewHandler(newHandler, &http2.Server{}) 352 - } 353 - 354 329 // addProxyHandler adds a handler to "mux" that proxies all requests with base 355 330 // /indexserver to "socket". 356 331 func addProxyHandler(mux *http.ServeMux, socket string) { ··· 621 596 } 622 597 623 598 func newGRPCServer(logger sglog.Logger, streamer zoekt.Streamer, additionalOpts ...grpc.ServerOption) *grpc.Server { 624 - metrics := serverMetricsOnce() 625 - 626 - opts := []grpc.ServerOption{ 627 - grpc.ChainStreamInterceptor( 628 - propagator.StreamServerPropagator(tenant.Propagator{}), 629 - tenant.StreamServerInterceptor, 630 - otelgrpc.StreamServerInterceptor(), 631 - metrics.StreamServerInterceptor(), 632 - messagesize.StreamServerInterceptor, 633 - internalerrs.LoggingStreamServerInterceptor(logger), 634 - ), 635 - grpc.ChainUnaryInterceptor( 636 - propagator.UnaryServerPropagator(tenant.Propagator{}), 637 - tenant.UnaryServerInterceptor, 638 - otelgrpc.UnaryServerInterceptor(), 639 - metrics.UnaryServerInterceptor(), 640 - messagesize.UnaryServerInterceptor, 641 - internalerrs.LoggingUnaryServerInterceptor(logger), 642 - ), 643 - } 644 - 645 - opts = append(opts, additionalOpts...) 646 - 647 - // Ensure that the message size options are set last, so they override any other 648 - // server-specific options that tweak the message size. 649 - // 650 - // The message size options are only provided if the environment variable is set. These options serve as an escape hatch, so they 651 - // take precedence over everything else with a uniform size setting that's easy to reason about. 652 - opts = append(opts, messagesize.MustGetServerMessageSizeFromEnv()...) 653 - 654 - s := grpc.NewServer(opts...) 655 - proto.RegisterWebserverServiceServer(s, zoektgrpc.NewServer(streamer)) 599 + s := defaults.NewServer(logger, additionalOpts...) 600 + webserverv1.RegisterWebserverServiceServer(s, grpcserver.NewServer(streamer)) 656 601 657 602 return s 658 603 } ··· 673 618 metricSearchRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{ 674 619 Name: "zoekt_search_requests_total", 675 620 Help: "The total number of search requests that zoekt received", 676 - }) 677 - 678 - // serviceMetricsOnce returns a singleton instance of the server metrics 679 - // that are shared across all gRPC servers that this process creates. 680 - // 681 - // This function panics if the metrics cannot be registered with the default 682 - // Prometheus registry. 683 - serverMetricsOnce = sync.OnceValue(func() *grpcprom.ServerMetrics { 684 - serverMetrics := grpcprom.NewServerMetrics( 685 - grpcprom.WithServerCounterOptions(), 686 - grpcprom.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request) 687 - ) 688 - prometheus.DefaultRegisterer.MustRegister(serverMetrics) 689 - return serverMetrics 690 621 }) 691 622 )
+67
grpc/defaults/server.go
··· 1 + package defaults 2 + 3 + import ( 4 + "sync" 5 + 6 + grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" 7 + "github.com/prometheus/client_golang/prometheus" 8 + sglog "github.com/sourcegraph/log" 9 + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" 10 + "google.golang.org/grpc" 11 + "google.golang.org/grpc/reflection" 12 + 13 + "github.com/sourcegraph/zoekt/grpc/internalerrs" 14 + "github.com/sourcegraph/zoekt/grpc/messagesize" 15 + "github.com/sourcegraph/zoekt/grpc/propagator" 16 + "github.com/sourcegraph/zoekt/internal/tenant" 17 + ) 18 + 19 + func NewServer(logger sglog.Logger, additionalOpts ...grpc.ServerOption) *grpc.Server { 20 + metrics := serverMetricsOnce() 21 + 22 + opts := []grpc.ServerOption{ 23 + grpc.ChainStreamInterceptor( 24 + propagator.StreamServerPropagator(tenant.Propagator{}), 25 + tenant.StreamServerInterceptor, 26 + otelgrpc.StreamServerInterceptor(), 27 + metrics.StreamServerInterceptor(), 28 + messagesize.StreamServerInterceptor, 29 + internalerrs.LoggingStreamServerInterceptor(logger), 30 + ), 31 + grpc.ChainUnaryInterceptor( 32 + propagator.UnaryServerPropagator(tenant.Propagator{}), 33 + tenant.UnaryServerInterceptor, 34 + otelgrpc.UnaryServerInterceptor(), 35 + metrics.UnaryServerInterceptor(), 36 + messagesize.UnaryServerInterceptor, 37 + internalerrs.LoggingUnaryServerInterceptor(logger), 38 + ), 39 + } 40 + 41 + opts = append(opts, additionalOpts...) 42 + 43 + // Ensure that the message size options are set last, so they override any other 44 + // server-specific options that tweak the message size. 45 + // 46 + // The message size options are only provided if the environment variable is set. These options serve as an escape hatch, so they 47 + // take precedence over everything else with a uniform size setting that's easy to reason about. 48 + opts = append(opts, messagesize.MustGetServerMessageSizeFromEnv()...) 49 + 50 + s := grpc.NewServer(opts...) 51 + reflection.Register(s) 52 + return s 53 + } 54 + 55 + // serviceMetricsOnce returns a singleton instance of the server metrics 56 + // that are shared across all gRPC servers that this process creates. 57 + // 58 + // This function panics if the metrics cannot be registered with the default 59 + // Prometheus registry. 60 + var serverMetricsOnce = sync.OnceValue(func() *grpcprom.ServerMetrics { 61 + serverMetrics := grpcprom.NewServerMetrics( 62 + grpcprom.WithServerCounterOptions(), 63 + grpcprom.WithServerHandlingTimeHistogram(), // record the overall response latency for a gRPC request) 64 + ) 65 + prometheus.DefaultRegisterer.MustRegister(serverMetrics) 66 + return serverMetrics 67 + })
+26 -1
grpc/grpcutil/util.go
··· 1 1 package grpcutil 2 2 3 - import "strings" 3 + import ( 4 + "net/http" 5 + "strings" 6 + 7 + "golang.org/x/net/http2" 8 + "golang.org/x/net/http2/h2c" 9 + "google.golang.org/grpc" 10 + ) 4 11 5 12 // SplitMethodName splits a full gRPC method name (e.g. "/package.service/method") in to its individual components (service, method) 6 13 // ··· 12 19 } 13 20 return "unknown", "unknown" 14 21 } 22 + 23 + // MultiplexGRPC takes a gRPC server and a plain HTTP handler and multiplexes the 24 + // request handling. Any requests that declare themselves as gRPC requests are routed 25 + // to the gRPC server, all others are routed to the httpHandler. 26 + func MultiplexGRPC(grpcServer *grpc.Server, httpHandler http.Handler) http.Handler { 27 + newHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 28 + if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { 29 + grpcServer.ServeHTTP(w, r) 30 + } else { 31 + httpHandler.ServeHTTP(w, r) 32 + } 33 + }) 34 + 35 + // Until we enable TLS, we need to fall back to the h2c protocol, which is 36 + // basically HTTP2 without TLS. The standard library does not implement the 37 + // h2s protocol, so this hijacks h2s requests and handles them correctly. 38 + return h2c.NewHandler(newHandler, &http2.Server{}) 39 + }
+15 -17
grpc/internalerrs/common_test.go
··· 8 8 "strings" 9 9 "testing" 10 10 11 - "github.com/google/go-cmp/cmp/cmpopts" 12 - "google.golang.org/protobuf/proto" 13 - "google.golang.org/protobuf/types/known/timestamppb" 14 - 15 - newspb "github.com/sourcegraph/zoekt/grpc/testprotos/news/v1" 16 - 17 11 "github.com/google/go-cmp/cmp" 12 + "github.com/google/go-cmp/cmp/cmpopts" 13 + newsv1 "github.com/sourcegraph/zoekt/grpc/testprotos/news/v1" 18 14 "google.golang.org/grpc" 19 15 "google.golang.org/grpc/codes" 20 16 "google.golang.org/grpc/status" 17 + "google.golang.org/protobuf/proto" 18 + "google.golang.org/protobuf/types/known/timestamppb" 21 19 ) 22 20 23 21 func TestCallBackClientStream(t *testing.T) { ··· 97 95 } 98 96 99 97 // Setup: create a sample proto.Message for the request 100 - request := &newspb.BinaryAttachment{ 98 + request := &newsv1.BinaryAttachment{ 101 99 Name: "sample_request", 102 100 Data: []byte("sample data"), 103 101 } ··· 111 109 } 112 110 113 111 // Check: assert InitialRequest returns the request 114 - if diff := cmp.Diff(request, *stream.InitialRequest(), cmpopts.IgnoreUnexported(newspb.BinaryAttachment{})); diff != "" { 112 + if diff := cmp.Diff(request, *stream.InitialRequest(), cmpopts.IgnoreUnexported(newsv1.BinaryAttachment{})); diff != "" { 115 113 t.Fatalf("InitialRequest() (-want +got):\n%s", diff) 116 114 } 117 115 } ··· 208 206 } 209 207 210 208 // Setup: create a sample proto.Message for the request 211 - request := &newspb.BinaryAttachment{ 209 + request := &newsv1.BinaryAttachment{ 212 210 Name: "sample_request", 213 211 Data: []byte("sample data"), 214 212 } ··· 222 220 } 223 221 224 222 // Check: assert InitialRequest returns the request 225 - if diff := cmp.Diff(request, *stream.InitialRequest(), cmpopts.IgnoreUnexported(newspb.BinaryAttachment{})); diff != "" { 223 + if diff := cmp.Diff(request, *stream.InitialRequest(), cmpopts.IgnoreUnexported(newsv1.BinaryAttachment{})); diff != "" { 226 224 t.Fatalf("InitialRequest() (-want +got):\n%s", diff) 227 225 } 228 226 } ··· 369 367 370 368 func TestFindNonUTF8StringFields(t *testing.T) { 371 369 // Create instances of the BinaryAttachment and KeyValueAttachment messages 372 - invalidBinaryAttachment := &newspb.BinaryAttachment{ 370 + invalidBinaryAttachment := &newsv1.BinaryAttachment{ 373 371 Name: "inval\x80id_binary", 374 372 Data: []byte("sample data"), 375 373 } 376 374 377 - invalidKeyValueAttachment := &newspb.KeyValueAttachment{ 375 + invalidKeyValueAttachment := &newsv1.KeyValueAttachment{ 378 376 Name: "inval\x80id_key_value", 379 377 Data: map[string]string{ 380 378 "key1": "value1", ··· 383 381 } 384 382 385 383 // Create a sample Article message with invalid UTF-8 strings 386 - article := &newspb.Article{ 384 + article := &newsv1.Article{ 387 385 Author: "inval\x80id_author", 388 386 Date: &timestamppb.Timestamp{Seconds: 1234567890}, 389 387 Title: "valid_title", 390 388 Content: "valid_content", 391 - Status: newspb.Article_STATUS_PUBLISHED, 392 - Attachments: []*newspb.Attachment{ 393 - {Contents: &newspb.Attachment_BinaryAttachment{BinaryAttachment: invalidBinaryAttachment}}, 394 - {Contents: &newspb.Attachment_KeyValueAttachment{KeyValueAttachment: invalidKeyValueAttachment}}, 389 + Status: newsv1.Article_STATUS_PUBLISHED, 390 + Attachments: []*newsv1.Attachment{ 391 + {Contents: &newsv1.Attachment_BinaryAttachment{BinaryAttachment: invalidBinaryAttachment}}, 392 + {Contents: &newsv1.Attachment_KeyValueAttachment{KeyValueAttachment: invalidKeyValueAttachment}}, 395 393 }, 396 394 } 397 395
+1
index/index_test.go
··· 26 26 "github.com/google/go-cmp/cmp" 27 27 "github.com/google/go-cmp/cmp/cmpopts" 28 28 "github.com/grafana/regexp" 29 + 29 30 "github.com/sourcegraph/zoekt" 30 31 "github.com/sourcegraph/zoekt/query" 31 32 )
+116 -117
query/query_proto.go
··· 6 6 7 7 "github.com/RoaringBitmap/roaring" 8 8 "github.com/grafana/regexp" 9 - 10 - proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 9 + webserverv1 "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 11 10 ) 12 11 13 - func QToProto(q Q) *proto.Q { 12 + func QToProto(q Q) *webserverv1.Q { 14 13 switch v := q.(type) { 15 14 case RawConfig: 16 - return &proto.Q{Query: &proto.Q_RawConfig{RawConfig: v.ToProto()}} 15 + return &webserverv1.Q{Query: &webserverv1.Q_RawConfig{RawConfig: v.ToProto()}} 17 16 case *Regexp: 18 - return &proto.Q{Query: &proto.Q_Regexp{Regexp: v.ToProto()}} 17 + return &webserverv1.Q{Query: &webserverv1.Q_Regexp{Regexp: v.ToProto()}} 19 18 case *Symbol: 20 - return &proto.Q{Query: &proto.Q_Symbol{Symbol: v.ToProto()}} 19 + return &webserverv1.Q{Query: &webserverv1.Q_Symbol{Symbol: v.ToProto()}} 21 20 case *Language: 22 - return &proto.Q{Query: &proto.Q_Language{Language: v.ToProto()}} 21 + return &webserverv1.Q{Query: &webserverv1.Q_Language{Language: v.ToProto()}} 23 22 case *Const: 24 - return &proto.Q{Query: &proto.Q_Const{Const: v.Value}} 23 + return &webserverv1.Q{Query: &webserverv1.Q_Const{Const: v.Value}} 25 24 case *Repo: 26 - return &proto.Q{Query: &proto.Q_Repo{Repo: v.ToProto()}} 25 + return &webserverv1.Q{Query: &webserverv1.Q_Repo{Repo: v.ToProto()}} 27 26 case *RepoRegexp: 28 - return &proto.Q{Query: &proto.Q_RepoRegexp{RepoRegexp: v.ToProto()}} 27 + return &webserverv1.Q{Query: &webserverv1.Q_RepoRegexp{RepoRegexp: v.ToProto()}} 29 28 case *BranchesRepos: 30 - return &proto.Q{Query: &proto.Q_BranchesRepos{BranchesRepos: v.ToProto()}} 29 + return &webserverv1.Q{Query: &webserverv1.Q_BranchesRepos{BranchesRepos: v.ToProto()}} 31 30 case *RepoIDs: 32 - return &proto.Q{Query: &proto.Q_RepoIds{RepoIds: v.ToProto()}} 31 + return &webserverv1.Q{Query: &webserverv1.Q_RepoIds{RepoIds: v.ToProto()}} 33 32 case *RepoSet: 34 - return &proto.Q{Query: &proto.Q_RepoSet{RepoSet: v.ToProto()}} 33 + return &webserverv1.Q{Query: &webserverv1.Q_RepoSet{RepoSet: v.ToProto()}} 35 34 case *FileNameSet: 36 - return &proto.Q{Query: &proto.Q_FileNameSet{FileNameSet: v.ToProto()}} 35 + return &webserverv1.Q{Query: &webserverv1.Q_FileNameSet{FileNameSet: v.ToProto()}} 37 36 case *Type: 38 - return &proto.Q{Query: &proto.Q_Type{Type: v.ToProto()}} 37 + return &webserverv1.Q{Query: &webserverv1.Q_Type{Type: v.ToProto()}} 39 38 case *Substring: 40 - return &proto.Q{Query: &proto.Q_Substring{Substring: v.ToProto()}} 39 + return &webserverv1.Q{Query: &webserverv1.Q_Substring{Substring: v.ToProto()}} 41 40 case *And: 42 - return &proto.Q{Query: &proto.Q_And{And: v.ToProto()}} 41 + return &webserverv1.Q{Query: &webserverv1.Q_And{And: v.ToProto()}} 43 42 case *Or: 44 - return &proto.Q{Query: &proto.Q_Or{Or: v.ToProto()}} 43 + return &webserverv1.Q{Query: &webserverv1.Q_Or{Or: v.ToProto()}} 45 44 case *Not: 46 - return &proto.Q{Query: &proto.Q_Not{Not: v.ToProto()}} 45 + return &webserverv1.Q{Query: &webserverv1.Q_Not{Not: v.ToProto()}} 47 46 case *Branch: 48 - return &proto.Q{Query: &proto.Q_Branch{Branch: v.ToProto()}} 47 + return &webserverv1.Q{Query: &webserverv1.Q_Branch{Branch: v.ToProto()}} 49 48 case *Boost: 50 - return &proto.Q{Query: &proto.Q_Boost{Boost: v.ToProto()}} 49 + return &webserverv1.Q{Query: &webserverv1.Q_Boost{Boost: v.ToProto()}} 51 50 default: 52 51 // The following nodes do not have a proto representation: 53 52 // - caseQ: only used internally, not by the RPC layer ··· 55 54 } 56 55 } 57 56 58 - func QFromProto(p *proto.Q) (Q, error) { 57 + func QFromProto(p *webserverv1.Q) (Q, error) { 59 58 switch v := p.Query.(type) { 60 - case *proto.Q_RawConfig: 59 + case *webserverv1.Q_RawConfig: 61 60 return RawConfigFromProto(v.RawConfig), nil 62 - case *proto.Q_Regexp: 61 + case *webserverv1.Q_Regexp: 63 62 return RegexpFromProto(v.Regexp) 64 - case *proto.Q_Symbol: 63 + case *webserverv1.Q_Symbol: 65 64 return SymbolFromProto(v.Symbol) 66 - case *proto.Q_Language: 65 + case *webserverv1.Q_Language: 67 66 return LanguageFromProto(v.Language), nil 68 - case *proto.Q_Const: 67 + case *webserverv1.Q_Const: 69 68 return &Const{Value: v.Const}, nil 70 - case *proto.Q_Repo: 69 + case *webserverv1.Q_Repo: 71 70 return RepoFromProto(v.Repo) 72 - case *proto.Q_RepoRegexp: 71 + case *webserverv1.Q_RepoRegexp: 73 72 return RepoRegexpFromProto(v.RepoRegexp) 74 - case *proto.Q_BranchesRepos: 73 + case *webserverv1.Q_BranchesRepos: 75 74 return BranchesReposFromProto(v.BranchesRepos) 76 - case *proto.Q_RepoIds: 75 + case *webserverv1.Q_RepoIds: 77 76 return RepoIDsFromProto(v.RepoIds) 78 - case *proto.Q_RepoSet: 77 + case *webserverv1.Q_RepoSet: 79 78 return RepoSetFromProto(v.RepoSet), nil 80 - case *proto.Q_FileNameSet: 79 + case *webserverv1.Q_FileNameSet: 81 80 return FileNameSetFromProto(v.FileNameSet), nil 82 - case *proto.Q_Type: 81 + case *webserverv1.Q_Type: 83 82 return TypeFromProto(v.Type) 84 - case *proto.Q_Substring: 83 + case *webserverv1.Q_Substring: 85 84 return SubstringFromProto(v.Substring), nil 86 - case *proto.Q_And: 85 + case *webserverv1.Q_And: 87 86 return AndFromProto(v.And) 88 - case *proto.Q_Or: 87 + case *webserverv1.Q_Or: 89 88 return OrFromProto(v.Or) 90 - case *proto.Q_Not: 89 + case *webserverv1.Q_Not: 91 90 return NotFromProto(v.Not) 92 - case *proto.Q_Branch: 91 + case *webserverv1.Q_Branch: 93 92 return BranchFromProto(v.Branch), nil 94 - case *proto.Q_Boost: 93 + case *webserverv1.Q_Boost: 95 94 return BoostFromProto(v.Boost) 96 95 default: 97 96 panic(fmt.Sprintf("unknown query node %T", p.Query)) 98 97 } 99 98 } 100 99 101 - func RegexpFromProto(p *proto.Regexp) (*Regexp, error) { 100 + func RegexpFromProto(p *webserverv1.Regexp) (*Regexp, error) { 102 101 parsed, err := syntax.Parse(p.GetRegexp(), regexpFlags) 103 102 if err != nil { 104 103 return nil, err ··· 111 110 }, nil 112 111 } 113 112 114 - func (r *Regexp) ToProto() *proto.Regexp { 115 - return &proto.Regexp{ 113 + func (r *Regexp) ToProto() *webserverv1.Regexp { 114 + return &webserverv1.Regexp{ 116 115 Regexp: r.Regexp.String(), 117 116 FileName: r.FileName, 118 117 Content: r.Content, ··· 120 119 } 121 120 } 122 121 123 - func SymbolFromProto(p *proto.Symbol) (*Symbol, error) { 122 + func SymbolFromProto(p *webserverv1.Symbol) (*Symbol, error) { 124 123 expr, err := QFromProto(p.GetExpr()) 125 124 if err != nil { 126 125 return nil, err ··· 131 130 }, nil 132 131 } 133 132 134 - func (s *Symbol) ToProto() *proto.Symbol { 135 - return &proto.Symbol{ 133 + func (s *Symbol) ToProto() *webserverv1.Symbol { 134 + return &webserverv1.Symbol{ 136 135 Expr: QToProto(s.Expr), 137 136 } 138 137 } 139 138 140 - func LanguageFromProto(p *proto.Language) *Language { 139 + func LanguageFromProto(p *webserverv1.Language) *Language { 141 140 return &Language{ 142 141 Language: p.GetLanguage(), 143 142 } 144 143 } 145 144 146 - func (l *Language) ToProto() *proto.Language { 147 - return &proto.Language{Language: l.Language} 145 + func (l *Language) ToProto() *webserverv1.Language { 146 + return &webserverv1.Language{Language: l.Language} 148 147 } 149 148 150 - func RepoFromProto(p *proto.Repo) (*Repo, error) { 149 + func RepoFromProto(p *webserverv1.Repo) (*Repo, error) { 151 150 r, err := regexp.Compile(p.GetRegexp()) 152 151 if err != nil { 153 152 return nil, err ··· 157 156 }, nil 158 157 } 159 158 160 - func (q *Repo) ToProto() *proto.Repo { 161 - return &proto.Repo{ 159 + func (q *Repo) ToProto() *webserverv1.Repo { 160 + return &webserverv1.Repo{ 162 161 Regexp: q.Regexp.String(), 163 162 } 164 163 } 165 164 166 - func RepoRegexpFromProto(p *proto.RepoRegexp) (*RepoRegexp, error) { 165 + func RepoRegexpFromProto(p *webserverv1.RepoRegexp) (*RepoRegexp, error) { 167 166 r, err := regexp.Compile(p.GetRegexp()) 168 167 if err != nil { 169 168 return nil, err ··· 173 172 }, nil 174 173 } 175 174 176 - func (q *RepoRegexp) ToProto() *proto.RepoRegexp { 177 - return &proto.RepoRegexp{ 175 + func (q *RepoRegexp) ToProto() *webserverv1.RepoRegexp { 176 + return &webserverv1.RepoRegexp{ 178 177 Regexp: q.Regexp.String(), 179 178 } 180 179 } 181 180 182 - func BranchesReposFromProto(p *proto.BranchesRepos) (*BranchesRepos, error) { 181 + func BranchesReposFromProto(p *webserverv1.BranchesRepos) (*BranchesRepos, error) { 183 182 brs := make([]BranchRepos, len(p.GetList())) 184 183 for i, br := range p.GetList() { 185 184 branchRepos, err := BranchReposFromProto(br) ··· 193 192 }, nil 194 193 } 195 194 196 - func (br *BranchesRepos) ToProto() *proto.BranchesRepos { 197 - list := make([]*proto.BranchRepos, len(br.List)) 195 + func (br *BranchesRepos) ToProto() *webserverv1.BranchesRepos { 196 + list := make([]*webserverv1.BranchRepos, len(br.List)) 198 197 for i, branchRepo := range br.List { 199 198 list[i] = branchRepo.ToProto() 200 199 } 201 200 202 - return &proto.BranchesRepos{ 201 + return &webserverv1.BranchesRepos{ 203 202 List: list, 204 203 } 205 204 } 206 205 207 - func RepoIDsFromProto(p *proto.RepoIds) (*RepoIDs, error) { 206 + func RepoIDsFromProto(p *webserverv1.RepoIds) (*RepoIDs, error) { 208 207 bm := roaring.NewBitmap() 209 208 err := bm.UnmarshalBinary(p.GetRepos()) 210 209 if err != nil { ··· 216 215 }, nil 217 216 } 218 217 219 - func (q *RepoIDs) ToProto() *proto.RepoIds { 218 + func (q *RepoIDs) ToProto() *webserverv1.RepoIds { 220 219 b, err := q.Repos.ToBytes() 221 220 if err != nil { 222 221 panic("unexpected error marshalling bitmap: " + err.Error()) 223 222 } 224 - return &proto.RepoIds{ 223 + return &webserverv1.RepoIds{ 225 224 Repos: b, 226 225 } 227 226 } 228 227 229 - func BranchReposFromProto(p *proto.BranchRepos) (BranchRepos, error) { 228 + func BranchReposFromProto(p *webserverv1.BranchRepos) (BranchRepos, error) { 230 229 bm := roaring.NewBitmap() 231 230 err := bm.UnmarshalBinary(p.GetRepos()) 232 231 if err != nil { ··· 238 237 }, nil 239 238 } 240 239 241 - func (br *BranchRepos) ToProto() *proto.BranchRepos { 240 + func (br *BranchRepos) ToProto() *webserverv1.BranchRepos { 242 241 b, err := br.Repos.ToBytes() 243 242 if err != nil { 244 243 panic("unexpected error marshalling bitmap: " + err.Error()) 245 244 } 246 245 247 - return &proto.BranchRepos{ 246 + return &webserverv1.BranchRepos{ 248 247 Branch: br.Branch, 249 248 Repos: b, 250 249 } 251 250 } 252 251 253 - func RepoSetFromProto(p *proto.RepoSet) *RepoSet { 252 + func RepoSetFromProto(p *webserverv1.RepoSet) *RepoSet { 254 253 return &RepoSet{ 255 254 Set: p.GetSet(), 256 255 } 257 256 } 258 257 259 - func (q *RepoSet) ToProto() *proto.RepoSet { 260 - return &proto.RepoSet{ 258 + func (q *RepoSet) ToProto() *webserverv1.RepoSet { 259 + return &webserverv1.RepoSet{ 261 260 Set: q.Set, 262 261 } 263 262 } 264 263 265 - func FileNameSetFromProto(p *proto.FileNameSet) *FileNameSet { 264 + func FileNameSetFromProto(p *webserverv1.FileNameSet) *FileNameSet { 266 265 m := make(map[string]struct{}, len(p.GetSet())) 267 266 for _, name := range p.GetSet() { 268 267 m[name] = struct{}{} ··· 272 271 } 273 272 } 274 273 275 - func (q *FileNameSet) ToProto() *proto.FileNameSet { 274 + func (q *FileNameSet) ToProto() *webserverv1.FileNameSet { 276 275 s := make([]string, 0, len(q.Set)) 277 276 for name := range q.Set { 278 277 s = append(s, name) 279 278 } 280 - return &proto.FileNameSet{ 279 + return &webserverv1.FileNameSet{ 281 280 Set: s, 282 281 } 283 282 } 284 283 285 - func TypeFromProto(p *proto.Type) (*Type, error) { 284 + func TypeFromProto(p *webserverv1.Type) (*Type, error) { 286 285 child, err := QFromProto(p.GetChild()) 287 286 if err != nil { 288 287 return nil, err ··· 290 289 291 290 var kind uint8 292 291 switch p.GetType() { 293 - case proto.Type_KIND_FILE_MATCH: 292 + case webserverv1.Type_KIND_FILE_MATCH: 294 293 kind = TypeFileMatch 295 - case proto.Type_KIND_FILE_NAME: 294 + case webserverv1.Type_KIND_FILE_NAME: 296 295 kind = TypeFileName 297 - case proto.Type_KIND_REPO: 296 + case webserverv1.Type_KIND_REPO: 298 297 kind = TypeRepo 299 298 } 300 299 ··· 305 304 }, nil 306 305 } 307 306 308 - func (q *Type) ToProto() *proto.Type { 309 - var kind proto.Type_Kind 307 + func (q *Type) ToProto() *webserverv1.Type { 308 + var kind webserverv1.Type_Kind 310 309 switch q.Type { 311 310 case TypeFileMatch: 312 - kind = proto.Type_KIND_FILE_MATCH 311 + kind = webserverv1.Type_KIND_FILE_MATCH 313 312 case TypeFileName: 314 - kind = proto.Type_KIND_FILE_NAME 313 + kind = webserverv1.Type_KIND_FILE_NAME 315 314 case TypeRepo: 316 - kind = proto.Type_KIND_REPO 315 + kind = webserverv1.Type_KIND_REPO 317 316 } 318 317 319 - return &proto.Type{ 318 + return &webserverv1.Type{ 320 319 Child: QToProto(q.Child), 321 320 Type: kind, 322 321 } 323 322 } 324 323 325 - func SubstringFromProto(p *proto.Substring) *Substring { 324 + func SubstringFromProto(p *webserverv1.Substring) *Substring { 326 325 return &Substring{ 327 326 Pattern: p.GetPattern(), 328 327 CaseSensitive: p.GetCaseSensitive(), ··· 331 330 } 332 331 } 333 332 334 - func (q *Substring) ToProto() *proto.Substring { 335 - return &proto.Substring{ 333 + func (q *Substring) ToProto() *webserverv1.Substring { 334 + return &webserverv1.Substring{ 336 335 Pattern: q.Pattern, 337 336 CaseSensitive: q.CaseSensitive, 338 337 FileName: q.FileName, ··· 340 339 } 341 340 } 342 341 343 - func OrFromProto(p *proto.Or) (*Or, error) { 342 + func OrFromProto(p *webserverv1.Or) (*Or, error) { 344 343 children := make([]Q, len(p.GetChildren())) 345 344 for i, child := range p.GetChildren() { 346 345 c, err := QFromProto(child) ··· 354 353 }, nil 355 354 } 356 355 357 - func (q *Or) ToProto() *proto.Or { 358 - children := make([]*proto.Q, len(q.Children)) 356 + func (q *Or) ToProto() *webserverv1.Or { 357 + children := make([]*webserverv1.Q, len(q.Children)) 359 358 for i, child := range q.Children { 360 359 children[i] = QToProto(child) 361 360 } 362 - return &proto.Or{ 361 + return &webserverv1.Or{ 363 362 Children: children, 364 363 } 365 364 } 366 365 367 - func BoostFromProto(p *proto.Boost) (*Boost, error) { 366 + func BoostFromProto(p *webserverv1.Boost) (*Boost, error) { 368 367 child, err := QFromProto(p.GetChild()) 369 368 if err != nil { 370 369 return nil, err ··· 375 374 }, nil 376 375 } 377 376 378 - func (q *Boost) ToProto() *proto.Boost { 379 - return &proto.Boost{ 377 + func (q *Boost) ToProto() *webserverv1.Boost { 378 + return &webserverv1.Boost{ 380 379 Child: QToProto(q.Child), 381 380 Boost: q.Boost, 382 381 } 383 382 } 384 383 385 - func NotFromProto(p *proto.Not) (*Not, error) { 384 + func NotFromProto(p *webserverv1.Not) (*Not, error) { 386 385 child, err := QFromProto(p.GetChild()) 387 386 if err != nil { 388 387 return nil, err ··· 392 391 }, nil 393 392 } 394 393 395 - func (q *Not) ToProto() *proto.Not { 396 - return &proto.Not{ 394 + func (q *Not) ToProto() *webserverv1.Not { 395 + return &webserverv1.Not{ 397 396 Child: QToProto(q.Child), 398 397 } 399 398 } 400 399 401 - func AndFromProto(p *proto.And) (*And, error) { 400 + func AndFromProto(p *webserverv1.And) (*And, error) { 402 401 children := make([]Q, len(p.GetChildren())) 403 402 for i, child := range p.GetChildren() { 404 403 c, err := QFromProto(child) ··· 412 411 }, nil 413 412 } 414 413 415 - func (q *And) ToProto() *proto.And { 416 - children := make([]*proto.Q, len(q.Children)) 414 + func (q *And) ToProto() *webserverv1.And { 415 + children := make([]*webserverv1.Q, len(q.Children)) 417 416 for i, child := range q.Children { 418 417 children[i] = QToProto(child) 419 418 } 420 - return &proto.And{ 419 + return &webserverv1.And{ 421 420 Children: children, 422 421 } 423 422 } 424 423 425 - func BranchFromProto(p *proto.Branch) *Branch { 424 + func BranchFromProto(p *webserverv1.Branch) *Branch { 426 425 return &Branch{ 427 426 Pattern: p.GetPattern(), 428 427 Exact: p.GetExact(), 429 428 } 430 429 } 431 430 432 - func (q *Branch) ToProto() *proto.Branch { 433 - return &proto.Branch{ 431 + func (q *Branch) ToProto() *webserverv1.Branch { 432 + return &webserverv1.Branch{ 434 433 Pattern: q.Pattern, 435 434 Exact: q.Exact, 436 435 } 437 436 } 438 437 439 - func RawConfigFromProto(p *proto.RawConfig) (res RawConfig) { 438 + func RawConfigFromProto(p *webserverv1.RawConfig) (res RawConfig) { 440 439 for _, protoFlag := range p.Flags { 441 440 switch protoFlag { 442 - case proto.RawConfig_FLAG_ONLY_PUBLIC: 441 + case webserverv1.RawConfig_FLAG_ONLY_PUBLIC: 443 442 res |= RcOnlyPublic 444 - case proto.RawConfig_FLAG_ONLY_PRIVATE: 443 + case webserverv1.RawConfig_FLAG_ONLY_PRIVATE: 445 444 res |= RcOnlyPrivate 446 - case proto.RawConfig_FLAG_ONLY_FORKS: 445 + case webserverv1.RawConfig_FLAG_ONLY_FORKS: 447 446 res |= RcOnlyForks 448 - case proto.RawConfig_FLAG_NO_FORKS: 447 + case webserverv1.RawConfig_FLAG_NO_FORKS: 449 448 res |= RcNoForks 450 - case proto.RawConfig_FLAG_ONLY_ARCHIVED: 449 + case webserverv1.RawConfig_FLAG_ONLY_ARCHIVED: 451 450 res |= RcOnlyArchived 452 - case proto.RawConfig_FLAG_NO_ARCHIVED: 451 + case webserverv1.RawConfig_FLAG_NO_ARCHIVED: 453 452 res |= RcNoArchived 454 453 } 455 454 } 456 455 return res 457 456 } 458 457 459 - func (r RawConfig) ToProto() *proto.RawConfig { 460 - var flags []proto.RawConfig_Flag 458 + func (r RawConfig) ToProto() *webserverv1.RawConfig { 459 + var flags []webserverv1.RawConfig_Flag 461 460 for _, flag := range flagNames { 462 461 if r&flag.Mask != 0 { 463 462 switch flag.Mask { 464 463 case RcOnlyPublic: 465 - flags = append(flags, proto.RawConfig_FLAG_ONLY_PUBLIC) 464 + flags = append(flags, webserverv1.RawConfig_FLAG_ONLY_PUBLIC) 466 465 case RcOnlyPrivate: 467 - flags = append(flags, proto.RawConfig_FLAG_ONLY_PRIVATE) 466 + flags = append(flags, webserverv1.RawConfig_FLAG_ONLY_PRIVATE) 468 467 case RcOnlyForks: 469 - flags = append(flags, proto.RawConfig_FLAG_ONLY_FORKS) 468 + flags = append(flags, webserverv1.RawConfig_FLAG_ONLY_FORKS) 470 469 case RcNoForks: 471 - flags = append(flags, proto.RawConfig_FLAG_NO_FORKS) 470 + flags = append(flags, webserverv1.RawConfig_FLAG_NO_FORKS) 472 471 case RcOnlyArchived: 473 - flags = append(flags, proto.RawConfig_FLAG_ONLY_ARCHIVED) 472 + flags = append(flags, webserverv1.RawConfig_FLAG_ONLY_ARCHIVED) 474 473 case RcNoArchived: 475 - flags = append(flags, proto.RawConfig_FLAG_NO_ARCHIVED) 474 + flags = append(flags, webserverv1.RawConfig_FLAG_NO_ARCHIVED) 476 475 } 477 476 } 478 477 } 479 - return &proto.RawConfig{Flags: flags} 478 + return &webserverv1.RawConfig{Flags: flags} 480 479 }