Skip to content

Commit b102586

Browse files
authored
Merge pull request #173 from m-lab/parser-fix
Add unit test and fix bugs
2 parents 282b0f4 + 6143576 commit b102586

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

parser/ndt_meta.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func handleIP(connSpec schema.Web100ValueMap, prefix string, ipString string) {
4848
connSpec.SetString(prefix+"_ip", ipString)
4949
ip := net.ParseIP(ipString)
5050
if ip == nil {
51-
// TODO - log/metric
51+
log.Printf("Failed parsing connSpec IP: %s\n", ipString)
52+
metrics.WarningCount.WithLabelValues(
53+
"ndt", "unknown", "failed parsing connSpec IP").Inc()
5254
} else {
5355
connSpec.SetString(prefix+"_ip", ip.String())
5456
if ip.To4() != nil {
@@ -62,18 +64,33 @@ func handleIP(connSpec schema.Web100ValueMap, prefix string, ipString string) {
6264
func (mfd *MetaFileData) PopulateConnSpec(connSpec schema.Web100ValueMap) {
6365
for k, v := range fieldPairs {
6466
s, ok := mfd.Fields[k]
65-
if ok && s != "" {
66-
connSpec.SetString(v, s)
67+
if ok {
68+
if s != "" {
69+
connSpec.SetString(v, s)
70+
}
71+
} else {
72+
log.Printf("Missing field: %s %v\n", k, v)
6773
}
6874
}
69-
s, ok := mfd.Fields["server_ip"]
75+
s, ok := connSpec["server_ip"]
7076
// TODO - extract function for this stanza
71-
if ok && s != "" {
72-
handleIP(connSpec, "server", s)
77+
if ok {
78+
if s != "" {
79+
handleIP(connSpec, "server", s.(string))
80+
}
81+
} else {
82+
metrics.WarningCount.WithLabelValues(
83+
"table", "unknown", "missing server_ip").Inc()
7384
}
74-
s, ok = mfd.Fields["client_ip"]
75-
if ok && s != "" {
76-
handleIP(connSpec, "client", s)
85+
s, ok = connSpec["client_ip"]
86+
if ok {
87+
if s != "" {
88+
handleIP(connSpec, "client", s.(string))
89+
}
90+
} else {
91+
log.Println("client_ip missing from .meta")
92+
metrics.WarningCount.WithLabelValues(
93+
"table", "unknown", "missing client_ip").Inc()
7794
}
7895
}
7996

parser/ndt_meta_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package parser_test
22

33
import (
44
"io/ioutil"
5+
"syscall"
56
"testing"
67
"time"
78

89
"github.com/m-lab/etl/parser"
10+
"github.com/m-lab/etl/schema"
911
)
1012

1113
// Not complete, but verifies basic functionality.
@@ -34,4 +36,32 @@ func TestMetaParser(t *testing.T) {
3436
if meta.Fields["server hostname"] != "mlab3.vie01.measurement-lab.org" {
3537
t.Error("Incorrect hostname: ", meta.Fields["hostname"])
3638
}
39+
40+
connSpec := schema.EmptyConnectionSpec()
41+
meta.PopulateConnSpec(connSpec)
42+
43+
// This particular file is missing the server_ip address...
44+
if _, ok := connSpec["server_ip"]; ok {
45+
t.Error("expected server_ip to be empty")
46+
}
47+
48+
// But the client_ip address (and client_af) should be fine.
49+
if v, ok := connSpec["client_ip"]; !ok {
50+
t.Logf("missing client ip address")
51+
for k, v := range meta.Fields {
52+
t.Logf("%s : %s\n", k, v)
53+
}
54+
t.Error("missing client ip address")
55+
} else {
56+
t.Logf("found client ip: %v\n", v)
57+
}
58+
59+
if v, ok := connSpec["client_af"]; !ok {
60+
t.Logf("missing client_af annotation")
61+
t.Error("missing client_af")
62+
} else {
63+
if v.(int64) != syscall.AF_INET {
64+
t.Logf("Wrong client_af value: ", v.(int64))
65+
}
66+
}
3767
}

0 commit comments

Comments
 (0)