Next milestone: production memory under 5 GiB, ready for upaas #6

Open
clawbot wants to merge 19 commits from next into main
2 changed files with 89 additions and 18 deletions
Showing only changes of commit cb2374f033 - Show all commits
+6 -2
View File
@@ -74,13 +74,17 @@ type RISMessage struct {
MrtTime float64 `json:"mrt_time,omitempty"` MrtTime float64 `json:"mrt_time,omitempty"`
SocketTime float64 `json:"socket_time,omitempty"` SocketTime float64 `json:"socket_time,omitempty"`
Path ASPath `json:"path,omitempty"` Path ASPath `json:"path,omitempty"`
Community [][]int `json:"community,omitempty"` // Community and Raw are present in the feed but read by no handler.
// They are the largest fields on a message that lives in up to four
// handler queues, so json:"-" keeps them out of the decoded message
// to save queue memory. Do not decode them without a consumer.
Community [][]int `json:"-"`
Origin string `json:"origin,omitempty"` Origin string `json:"origin,omitempty"`
MED *int `json:"med,omitempty"` MED *int `json:"med,omitempty"`
LocalPref *int `json:"local_pref,omitempty"` LocalPref *int `json:"local_pref,omitempty"`
Announcements []RISAnnouncement `json:"announcements,omitempty"` Announcements []RISAnnouncement `json:"announcements,omitempty"`
Withdrawals []string `json:"withdrawals,omitempty"` Withdrawals []string `json:"withdrawals,omitempty"`
Raw string `json:"raw,omitempty"` Raw string `json:"-"`
} }
// RISAnnouncement represents a BGP route announcement within a RIS message. // RISAnnouncement represents a BGP route announcement within a RIS message.
+67
View File
@@ -0,0 +1,67 @@
package ristypes
import (
"bufio"
"encoding/json"
"os"
"testing"
)
// messageExamplesPath is the captured RIS Live feed used as decode fixtures,
// one JSON message per line.
const messageExamplesPath = "../../docs/message-examples.json"
// TestDecodeDropsCommunityAndRaw decodes every captured message the way the
// streamer does and checks that the fields no handler reads (Community, Raw)
// stay empty while the fields handlers use (Path, Announcements) still decode.
func TestDecodeDropsCommunityAndRaw(t *testing.T) {
f, err := os.Open(messageExamplesPath)
if err != nil {
t.Fatalf("open fixtures: %v", err)
}
defer f.Close()
var messages, withPath, withAnnouncements int
scanner := bufio.NewScanner(f)
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
for scanner.Scan() {
line := scanner.Bytes()
if len(line) == 0 {
continue
}
var wrapper RISLiveMessage
if err := json.Unmarshal(line, &wrapper); err != nil {
t.Fatalf("unmarshal message %d: %v", messages+1, err)
}
messages++
msg := wrapper.Data
if msg.Community != nil {
t.Errorf("message %d: Community decoded, want empty: %v", messages, msg.Community)
}
if msg.Raw != "" {
t.Errorf("message %d: Raw decoded, want empty", messages)
}
if len(msg.Path) > 0 {
withPath++
}
if len(msg.Announcements) > 0 {
withAnnouncements++
}
}
if err := scanner.Err(); err != nil {
t.Fatalf("scan fixtures: %v", err)
}
if messages == 0 {
t.Fatal("no messages decoded from fixtures")
}
// The fixtures include announcement messages; a used field must still decode,
// otherwise an empty Community/Raw would prove nothing.
if withPath == 0 || withAnnouncements == 0 {
t.Fatalf("used fields did not decode: withPath=%d withAnnouncements=%d", withPath, withAnnouncements)
}
}