forked from honeycombio/honeycomb-tcpagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackbox_test.go
98 lines (88 loc) · 2.36 KB
/
blackbox_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main_test
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"sync"
"testing"
"github.com/honeycombio/honeycomb-tcpagent/protocols/mongodb"
"github.com/honeycombio/honeycomb-tcpagent/publish"
"github.com/honeycombio/honeycomb-tcpagent/sniffer"
libhoney "github.com/honeycombio/libhoney-go"
"github.com/stretchr/testify/assert"
)
type testTransport struct {
eventCount int
sync.Mutex
}
func (tr *testTransport) RoundTrip(r *http.Request) (*http.Response, error) {
tr.Lock()
tr.eventCount++
tr.Unlock()
return &http.Response{Body: ioutil.NopCloser(bytes.NewReader(nil)), StatusCode: 200}, nil
}
func BenchmarkIngestion(b *testing.B) {
// Read from a pcap file containing ~100K MongoDB queries
options := sniffer.Options{
SourceType: "offline",
Device: "any",
SnapLen: 65535,
BufSizeMb: 30,
FlushTimeout: 60,
PcapFile: "testdata/tcpd_any.pcap",
}
for i := 0; i < b.N; i++ {
transport := &testTransport{}
libhoneyOptions := libhoney.Config{
APIHost: "http://localhost:9999",
Dataset: "test",
WriteKey: "test",
Transport: transport,
}
tp := publish.NewHoneycombPublisher(libhoneyOptions)
pf := &mongodb.ParserFactory{
Options: mongodb.Options{Port: 27017},
Publisher: tp,
}
s, _ := sniffer.New(options, pf)
s.Run()
transport.Lock()
// TODO actually wait for all publishing to finish
assert.True(b, transport.eventCount > 70000)
fmt.Println("event count", transport.eventCount)
transport.Unlock()
}
}
func TestSampling(t *testing.T) {
// Read from a pcap file containing ~100K MongoDB queries
options := sniffer.Options{
SourceType: "offline",
Device: "any",
SnapLen: 65535,
BufSizeMb: 30,
FlushTimeout: 60,
PcapFile: "testdata/tcpd_any.pcap",
}
transport := &testTransport{}
libhoneyOptions := libhoney.Config{
APIHost: "http://localhost:9999",
Dataset: "test",
WriteKey: "test",
Transport: transport,
SampleRate: 5,
}
tp := publish.NewHoneycombPublisher(libhoneyOptions)
pf := &mongodb.ParserFactory{
Options: mongodb.Options{Port: 27017},
Publisher: tp,
}
s, _ := sniffer.New(options, pf)
s.Run()
transport.Lock()
// TODO actually wait for all publishing to finish
assert.True(t, transport.eventCount > 18000)
assert.True(t, transport.eventCount < 22000)
fmt.Println("event count", transport.eventCount)
transport.Unlock()
}