-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: remove gob and SSE rpc endpoints
We now only consume zoekt via gRPC at Sourcegraph and I doubt anyone uses the old endpoints. This will have one required update in sourcegraph, and that is to use SenderFunc from the main zoekt package rather than from the now deleted stream package. Test Plan: go test
- Loading branch information
1 parent
74e75ef
commit dc59e85
Showing
18 changed files
with
156 additions
and
1,047 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package server | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/sourcegraph/zoekt" | ||
) | ||
|
||
// newSamplingSender is a zoekt.Sender that samples stats events to avoid | ||
// sending many empty stats events over the wire. | ||
func newSamplingSender(next zoekt.Sender) *samplingSender { | ||
return &samplingSender{next: next} | ||
} | ||
|
||
type samplingSender struct { | ||
next zoekt.Sender | ||
agg zoekt.SearchResult | ||
aggCount int | ||
} | ||
|
||
func (s *samplingSender) Send(event *zoekt.SearchResult) { | ||
// We don't want to send events over the wire if they don't contain file | ||
// matches. Hence, in case we didn't find any results, we aggregate the stats | ||
// and send them out in regular intervals. | ||
if len(event.Files) == 0 { | ||
s.aggCount++ | ||
|
||
s.agg.Stats.Add(event.Stats) | ||
s.agg.Progress = event.Progress | ||
|
||
if s.aggCount%100 == 0 && !s.agg.Stats.Zero() { | ||
s.next.Send(&s.agg) | ||
s.agg = zoekt.SearchResult{} | ||
} | ||
|
||
return | ||
} | ||
|
||
// If we have aggregate stats, we merge them with the new event before sending | ||
// it. We drop agg.Progress, because we assume that event.Progress reflects the | ||
// latest status. | ||
if !s.agg.Stats.Zero() { | ||
event.Stats.Add(s.agg.Stats) | ||
s.agg = zoekt.SearchResult{} | ||
} | ||
|
||
s.next.Send(event) | ||
} | ||
|
||
// Flush sends any aggregated stats that we haven't sent yet | ||
func (s *samplingSender) Flush() { | ||
if !s.agg.Stats.Zero() { | ||
s.next.Send(&zoekt.SearchResult{ | ||
Stats: s.agg.Stats, | ||
Progress: zoekt.Progress{ | ||
Priority: math.Inf(-1), | ||
MaxPendingPriority: math.Inf(-1), | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package server | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcegraph/zoekt" | ||
) | ||
|
||
func TestSamplingStream(t *testing.T) { | ||
nonZeroStats := zoekt.Stats{ | ||
ContentBytesLoaded: 10, | ||
} | ||
filesEvent := &zoekt.SearchResult{ | ||
Files: make([]zoekt.FileMatch, 10), | ||
Stats: nonZeroStats, | ||
} | ||
fileEvents := func(n int) []*zoekt.SearchResult { | ||
res := make([]*zoekt.SearchResult, n) | ||
for i := 0; i < n; i++ { | ||
res[i] = filesEvent | ||
} | ||
return res | ||
} | ||
statsEvent := &zoekt.SearchResult{ | ||
Stats: nonZeroStats, | ||
} | ||
statsEvents := func(n int) []*zoekt.SearchResult { | ||
res := make([]*zoekt.SearchResult, n) | ||
for i := 0; i < n; i++ { | ||
res[i] = statsEvent | ||
} | ||
return res | ||
} | ||
cases := []struct { | ||
events []*zoekt.SearchResult | ||
beforeFlushCount int | ||
afterFlushCount int | ||
}{ | ||
// These test cases assume that the sampler only forwards | ||
// every 100 stats-only event. In case the sampling logic | ||
// changes, these tests are not valuable. | ||
{nil, 0, 0}, | ||
{fileEvents(1), 1, 1}, | ||
{fileEvents(2), 2, 2}, | ||
{fileEvents(200), 200, 200}, | ||
{append(fileEvents(1), statsEvents(1)...), 1, 2}, | ||
{append(fileEvents(1), statsEvents(2)...), 1, 2}, | ||
{append(fileEvents(1), statsEvents(99)...), 1, 2}, | ||
{append(fileEvents(1), statsEvents(100)...), 2, 2}, | ||
{statsEvents(500), 5, 5}, | ||
{statsEvents(501), 5, 6}, | ||
} | ||
|
||
for _, tc := range cases { | ||
count := 0 | ||
ss := newSamplingSender(zoekt.SenderFunc(func(*zoekt.SearchResult) { | ||
count += 1 | ||
})) | ||
|
||
for _, event := range tc.events { | ||
ss.Send(event) | ||
} | ||
if count != tc.beforeFlushCount { | ||
t.Fatalf("expected %d events, got %d", tc.beforeFlushCount, count) | ||
} | ||
ss.Flush() | ||
|
||
if count != tc.afterFlushCount { | ||
t.Fatalf("expected %d events, got %d", tc.afterFlushCount, count) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.