Skip to content

Commit a45d40c

Browse files
authored
keep only 1/10 of snapshots (#832)
* keep only 1/10 of snapshots
1 parent 7e739cf commit a45d40c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

parser/tcpinfo.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ func (p *TCPInfoParser) IsParsable(testName string, data []byte) (string, bool)
6969
return "", false
7070
}
7171

72+
func thinSnaps(orig []*snapshot.Snapshot) []*snapshot.Snapshot {
73+
n := len(orig)
74+
out := make([]*snapshot.Snapshot, 0, 1+n/10)
75+
for i := 0; i < n; i += 10 {
76+
out = append(out, orig[i])
77+
}
78+
if n%10 != 0 {
79+
out = append(out, orig[n-1])
80+
}
81+
return out
82+
}
83+
7284
// ParseAndInsert extracts all ArchivalRecords from the rawContent and inserts into a single row.
7385
// Approximately 15 usec/snapshot.
7486
func (p *TCPInfoParser) ParseAndInsert(fileMetadata map[string]bigquery.Value, testName string, rawContent []byte) error {
@@ -125,7 +137,8 @@ func (p *TCPInfoParser) ParseAndInsert(fileMetadata map[string]bigquery.Value, t
125137
}
126138

127139
row := schema.TCPRow{}
128-
row.Snapshots = snaps
140+
// TODO - restore full snapshots, or implement smarter filtering.
141+
row.Snapshots = thinSnaps(snaps)
129142
row.FinalSnapshot = snaps[len(snaps)-1]
130143
if row.FinalSnapshot.InetDiagMsg != nil {
131144
row.SockID = row.FinalSnapshot.InetDiagMsg.ID.GetSockID()

parser/tcpinfo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func TestTCPParser(t *testing.T) {
164164
if duration > 20*time.Second {
165165
t.Error("Incorrect duration calculation", duration)
166166
}
167+
168+
if totalSnaps != 1588 {
169+
t.Error("expected 1588 (thinned) snapshots, got", totalSnaps)
170+
}
167171
}
168172

169173
// This is a subset of TestTCPParser, but simpler, so might be useful.

0 commit comments

Comments
 (0)