Skip to content

Commit 84187df

Browse files
Add hopannotation1 to paris traceroute (#1047)
* Add hopannotation1 to paris traceroute * Update comment * Fix idiom * Fix comment * Use filepath hostname * Undo test change * Use etl.ValidateTestPath() * Reuse existing Datapath * Formatting * Refactor code
1 parent 84a2778 commit 84187df

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

parser/pt.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ func NewPTParser(ins etl.Inserter, ann ...v2as.Annotator) *PTParser {
374374
}
375375

376376
// ProcessAllNodes take the array of the Nodes, and generate one ScamperHop entry from each node.
377-
func ProcessAllNodes(allNodes []Node, server_IP, protocol string, tableName string) []schema.ScamperHop {
377+
func ProcessAllNodes(allNodes []Node, server_IP, protocol string, tableName string,
378+
logTime time.Time, machine string) []schema.ScamperHop {
378379
var results []schema.ScamperHop
379380
if len(allNodes) == 0 {
380381
return nil
@@ -399,6 +400,7 @@ func ProcessAllNodes(allNodes []Node, server_IP, protocol string, tableName stri
399400
source := schema.HopIP{
400401
IP: server_IP,
401402
}
403+
source.HopAnnotation1 = getParisHopAnnotation(logTime, machine, source.IP)
402404
oneHop := schema.ScamperHop{
403405
Source: source,
404406
Links: links,
@@ -410,6 +412,7 @@ func ProcessAllNodes(allNodes []Node, server_IP, protocol string, tableName stri
410412
IP: allNodes[i].parent_ip,
411413
Hostname: allNodes[i].parent_hostname,
412414
}
415+
source.HopAnnotation1 = getParisHopAnnotation(logTime, machine, source.IP)
413416
oneHop := schema.ScamperHop{
414417
Source: source,
415418
Links: links,
@@ -420,6 +423,16 @@ func ProcessAllNodes(allNodes []Node, server_IP, protocol string, tableName stri
420423
return results
421424
}
422425

426+
// getParisHopAnnotation() returns returns a new `*hopannotation.HopAnnotation1` to use
427+
// as a synthetic annotation for paris-traceroute hops.
428+
func getParisHopAnnotation(logTime time.Time, machine string, IP string) *hopannotation.HopAnnotation1 {
429+
hopID := GetHopID(float64(logTime.UTC().Unix()), machine, IP)
430+
return &hopannotation.HopAnnotation1{
431+
ID: hopID,
432+
Timestamp: logTime,
433+
}
434+
}
435+
423436
// This function was designed for hops with multiple flows. When the source IP are duplicate flows, but the destination IP is
424437
// single flow IP, those hops will result in just one node in the list.
425438
func Unique(oneNode Node, list []Node) bool {
@@ -587,12 +600,12 @@ func (pt *PTParser) ParseAndInsert(meta map[string]bigquery.Value, testName stri
587600
return nil
588601
}
589602

603+
// ArchiveURL must already be valid, so error is safe to ignore.
604+
dp, _ := etl.ValidateTestPath(pt.taskFileName)
590605
// Process the jsonl output of Scamper binary.
591606
if strings.HasSuffix(testName, ".jsonl") {
592607
ptTest, err := ParseJSONL(testName, rawContent, pt.TableName(), pt.taskFileName)
593608
if err == nil {
594-
// ArchiveURL must already be valid, so error is safe to ignore.
595-
dp, _ := etl.ValidateTestPath(pt.taskFileName)
596609
ptTest.ServerX.Site = dp.Site
597610
ptTest.ServerX.Machine = dp.Host
598611

@@ -611,7 +624,7 @@ func (pt *PTParser) ParseAndInsert(meta map[string]bigquery.Value, testName stri
611624
}
612625

613626
// Process the legacy Paris Traceroute txt output
614-
cachedTest, err := Parse(meta, testName, testId, rawContent, pt.TableName())
627+
cachedTest, err := Parse(meta, testName, testId, rawContent, pt.TableName(), dp)
615628
if err != nil {
616629
// These are happening at a high rate, so demote them to warnings until we can fix them.
617630
metrics.WarningCount.WithLabelValues(
@@ -786,7 +799,8 @@ func ProcessOneTuple(parts []string, protocol string, currentLeaves []Node, allN
786799

787800
// Parse the raw test file into hops ParisTracerouteHop.
788801
// TODO(dev): dedup the hops that are identical.
789-
func Parse(meta map[string]bigquery.Value, testName string, testId string, rawContent []byte, tableName string) (cachedPTData, error) {
802+
func Parse(meta map[string]bigquery.Value, testName string, testId string, rawContent []byte,
803+
tableName string, dp etl.DataPath) (cachedPTData, error) {
790804
//log.Printf("%s", testName)
791805
metrics.WorkerState.WithLabelValues(tableName, "pt-parse").Inc()
792806
defer metrics.WorkerState.WithLabelValues(tableName, "pt-parse").Dec()
@@ -911,8 +925,9 @@ func Parse(meta map[string]bigquery.Value, testName string, testId string, rawCo
911925
metrics.PTBitsAwayFromDestV6.WithLabelValues(iataCode).Observe(float64(bitsDiff))
912926
}
913927

928+
machine := fmt.Sprintf("%s-%s", dp.Host, dp.Site)
914929
// Generate Hops from allNodes
915-
PTHops := ProcessAllNodes(allNodes, serverIP, protocol, tableName)
930+
PTHops := ProcessAllNodes(allNodes, serverIP, protocol, tableName, logTime, machine)
916931

917932
source := schema.ServerInfo{
918933
IP: serverIP,

parser/pt_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/go-test/deep"
1313
"github.com/m-lab/annotation-service/api"
1414
v2 "github.com/m-lab/annotation-service/api/v2"
15+
"github.com/m-lab/etl/etl"
1516
"github.com/m-lab/etl/parser"
1617
"github.com/m-lab/etl/schema"
1718
"github.com/m-lab/traceroute-caller/hopannotation"
@@ -242,7 +243,7 @@ func TestParseLegacyFormatData(t *testing.T) {
242243
fmt.Println("cannot load test data")
243244
return
244245
}
245-
cachedTest, err := parser.Parse(nil, "testdata/PT/20160112T00:45:44Z_ALL27409.paris", "", rawData, "pt-daily")
246+
cachedTest, err := parser.Parse(nil, "testdata/PT/20160112T00:45:44Z_ALL27409.paris", "", rawData, "pt-daily", etl.DataPath{})
246247
if err != nil {
247248
t.Fatalf(err.Error())
248249
}
@@ -340,7 +341,9 @@ func TestParseJSONL(t *testing.T) {
340341

341342
func TestParse(t *testing.T) {
342343
rawData, err := ioutil.ReadFile("testdata/PT/20170320T23:53:10Z-172.17.94.34-33456-74.125.224.100-33457.paris")
343-
cachedTest, err := parser.Parse(nil, "testdata/PT/20170320T23:53:10Z-172.17.94.34-33456-74.125.224.100-33457.paris", "", rawData, "pt-daily")
344+
dp, _ := etl.ValidateTestPath("gs://archive-measurement-lab/paris-traceroute/2017/03/20/20170320T000000Z-mlab1-lax05-paris-traceroute-0000.tgz")
345+
cachedTest, err := parser.Parse(nil, "testdata/PT/20170320T23:53:10Z-172.17.94.34-33456-74.125.224.100-33457.paris", "", rawData,
346+
"pt-daily", dp)
344347
if err != nil {
345348
t.Fatalf(err.Error())
346349
}
@@ -363,6 +366,10 @@ func TestParse(t *testing.T) {
363366
City: "",
364367
CountryCode: "",
365368
Hostname: "sr05-te1-8.nuq04.net.google.com",
369+
HopAnnotation1: &hopannotation.HopAnnotation1{
370+
ID: "20170320_mlab1-lax05_64.233.174.109",
371+
Timestamp: cachedTest.LogTime,
372+
},
366373
},
367374
Linkc: 0,
368375
Links: []schema.HopLink{
@@ -623,7 +630,8 @@ func TestParseEmpty(t *testing.T) {
623630
fmt.Println("cannot load test data")
624631
return
625632
}
626-
_, parseErr := parser.Parse(nil, "testdata/20180201T07:57:37Z-125.212.217.215-56622-208.177.76.115-9100.paris", "", rawData, "pt-daily")
633+
_, parseErr := parser.Parse(nil, "testdata/20180201T07:57:37Z-125.212.217.215-56622-208.177.76.115-9100.paris", "", rawData, "pt-daily",
634+
etl.DataPath{})
627635
if parseErr == nil {
628636
t.Fatal(parseErr)
629637
}

0 commit comments

Comments
 (0)