Skip to content

Commit f3974a7

Browse files
authored
Updates annotator to use v2 of the siteinfo annotations format (#46)
* Convers siteannotator to use v2 annotations format The v2 version of the siteinfo annotations format allows for proper annotation of virtual sites, which have different IP addresses for every machine at the virtual site. This commit modifies the siteannotator to be able to utilize the v2 format. * Updates unit tests for changes to the siteannotator The siteannotator now supports the v2 siteinfo annotations format. This commit updates unit tests to support these changes. * Updates Go modules, and moves to Go v1.17 Also updates Travis build environment to Go v1.17 * Fixes install of goveralls for Travis build * Updates Docker build env to Go 1.17, too * Uses mlab-sandbox in all unit tests
1 parent 8823a28 commit f3974a7

File tree

8 files changed

+510
-109
lines changed

8 files changed

+510
-109
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
language: go
22

33
go:
4-
- 1.15
4+
- 1.17
55

66
install:
77
- go get -v -t ./...
88

99
before_script:
10-
- go get github.com/mattn/goveralls
10+
- go install github.com/mattn/goveralls@latest
1111

1212
script:
1313
- go vet ./...

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build uuid-annotator
2-
FROM golang:1.15-alpine as build
2+
FROM golang:1.17-alpine as build
33
RUN apk --no-cache add git
44
COPY . /go/src/github.com/m-lab/uuid-annotator
55
WORKDIR /go/src/github.com/m-lab/uuid-annotator

go.mod

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
module github.com/m-lab/uuid-annotator
22

3-
go 1.16
3+
go 1.17
44

55
require (
66
github.com/go-test/deep v1.0.6
7-
github.com/gocarina/gocsv v0.0.0-20210408192840-02d7211d929d // indirect
87
github.com/m-lab/annotation-service v0.0.0-20210504151333-138bdf572368
9-
github.com/m-lab/go v0.1.44
8+
github.com/m-lab/go v0.1.47
109
github.com/m-lab/tcp-info v1.5.3
11-
github.com/oschwald/geoip2-golang v1.5.0
12-
github.com/prometheus/client_golang v1.7.1
13-
github.com/spf13/afero v1.6.0
10+
github.com/oschwald/geoip2-golang v1.7.0
11+
github.com/prometheus/client_golang v1.12.2
12+
github.com/spf13/afero v1.8.2
13+
)
14+
15+
require (
16+
cloud.google.com/go v0.102.0 // indirect
17+
cloud.google.com/go/compute v1.6.1 // indirect
18+
cloud.google.com/go/iam v0.3.0 // indirect
19+
cloud.google.com/go/storage v1.22.1 // indirect
20+
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
21+
github.com/beorn7/perks v1.0.1 // indirect
22+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
23+
github.com/gocarina/gocsv v0.0.0-20210408192840-02d7211d929d // indirect
24+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
25+
github.com/golang/protobuf v1.5.2 // indirect
26+
github.com/google/go-cmp v0.5.8 // indirect
27+
github.com/google/uuid v1.3.0 // indirect
28+
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
29+
github.com/googleapis/go-type-adapters v1.0.0 // indirect
30+
github.com/googleapis/google-cloud-go-testing v0.0.0-20210719221736-1c9a4c676720 // indirect
31+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
32+
github.com/oschwald/maxminddb-golang v1.9.0 // indirect
33+
github.com/prometheus/client_model v0.2.0 // indirect
34+
github.com/prometheus/common v0.34.0 // indirect
35+
github.com/prometheus/procfs v0.7.3 // indirect
36+
go.opencensus.io v0.23.0 // indirect
37+
golang.org/x/net v0.0.0-20220524220425-1d687d428aca // indirect
38+
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 // indirect
39+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
40+
golang.org/x/text v0.3.7 // indirect
41+
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
42+
google.golang.org/api v0.81.0 // indirect
43+
google.golang.org/appengine v1.6.7 // indirect
44+
google.golang.org/genproto v0.0.0-20220525015930-6ca3db687a9d // indirect
45+
google.golang.org/grpc v1.46.2 // indirect
46+
google.golang.org/protobuf v1.28.0 // indirect
1447
)

go.sum

Lines changed: 419 additions & 46 deletions
Large diffs are not rendered by default.

main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestMainSmokeTest(t *testing.T) {
3939
rtx.Must(routeviewv6.Set("file:./testdata/RouteViewIPv6.tiny.gz"), "Failed to set routeview v6 url for testing")
4040
rtx.Must(asnameurl.Set("file:./data/asnames.ipinfo.csv"), "Failed to set ipinfo ASName url for testing")
4141
rtx.Must(siteinfo.Set("file:./testdata/annotations.json"), "Failed to set siteinfo annotations url for testing")
42-
*hostname = "mlab1.lga03.measurement-lab.org"
42+
*hostname = "mlab1-lga03.mlab-sandbox.measurement-lab.org"
4343

4444
// Now start up a fake eventsocket.
4545
srv := eventsocket.New(*eventsocket.Filename)

siteannotator/server.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"sync"
99

1010
"github.com/m-lab/go/content"
11-
"github.com/m-lab/go/host"
1211
"github.com/m-lab/go/rtx"
1312

1413
"github.com/m-lab/tcp-info/inetdiag"
@@ -28,7 +27,7 @@ type siteAnnotator struct {
2827

2928
// ErrHostnameNotFound is generated when the given hostname cannot be found in the
3029
// downloaded siteinfo annotations.
31-
var ErrHostnameNotFound = errors.New("Hostname Not Found")
30+
var ErrHostnameNotFound = errors.New("hostname not found")
3231

3332
// New makes a new server Annotator using metadata from siteinfo JSON.
3433
func New(ctx context.Context, hostname string, js content.Provider, localIPs []net.IP) annotator.Annotator {
@@ -82,12 +81,12 @@ func (g *siteAnnotator) annotate(src string, server *annotator.ServerAnnotations
8281
}
8382

8483
type siteinfoAnnotation struct {
85-
Name string
86-
Network struct {
84+
Annotation annotator.ServerAnnotations
85+
Network struct {
8786
IPv4 string
8887
IPv6 string
8988
}
90-
Annotation annotator.ServerAnnotations
89+
Type string
9190
}
9291

9392
func parseCIDR(v4, v6 string) (net.IPNet, net.IPNet, error) {
@@ -115,26 +114,17 @@ func (g *siteAnnotator) load(ctx context.Context) (*annotator.ServerAnnotations,
115114
if err != nil {
116115
return nil, err
117116
}
118-
var s []siteinfoAnnotation
119-
var result annotator.ServerAnnotations
117+
var s map[string]siteinfoAnnotation
120118
err = json.Unmarshal(js, &s)
121119
if err != nil {
122120
return nil, err
123121
}
124-
h, err := host.Parse(g.hostname)
125-
if err != nil {
126-
return nil, err
127-
}
128-
for i := range s {
129-
if s[i].Name == h.Site {
130-
result = s[i].Annotation // Copy out of array.
131-
result.Machine = h.Machine
132-
g.v4, g.v6, err = parseCIDR(s[i].Network.IPv4, s[i].Network.IPv6)
133-
if err != nil {
134-
return nil, err
135-
}
136-
return &result, nil
122+
if v, ok := s[g.hostname]; ok {
123+
g.v4, g.v6, err = parseCIDR(v.Network.IPv4, v.Network.IPv6)
124+
if err != nil {
125+
return nil, err
137126
}
127+
return &v.Annotation, nil
138128
}
139129
return nil, ErrHostnameNotFound
140130
}

siteannotator/server_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestNew(t *testing.T) {
8888
name: "success-src",
8989
localIPs: []net.IP{net.ParseIP("64.86.148.137")},
9090
provider: &localRawfile,
91-
hostname: "mlab1.lga03.measurement-lab.org",
91+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
9292
ID: &inetdiag.SockID{
9393
SPort: 1,
9494
SrcIP: "1.0.0.1",
@@ -103,7 +103,7 @@ func TestNew(t *testing.T) {
103103
name: "success-dest",
104104
localIPs: []net.IP{net.ParseIP("64.86.148.137")},
105105
provider: &localRawfile,
106-
hostname: "mlab1.lga03.measurement-lab.org",
106+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
107107
ID: &inetdiag.SockID{
108108
SPort: 1,
109109
SrcIP: "64.86.148.137",
@@ -118,7 +118,7 @@ func TestNew(t *testing.T) {
118118
name: "success-no-ipv4-config-with-ipv6-connection",
119119
localIPs: []net.IP{net.ParseIP("2001:5a0:4300::2")},
120120
provider: &localRawfile,
121-
hostname: "mlab1.six02.measurement-lab.org",
121+
hostname: "mlab1-six02.mlab-sandbox.measurement-lab.org",
122122
ID: &inetdiag.SockID{
123123
SPort: 1,
124124
SrcIP: "2001:5a0:4300::2",
@@ -133,7 +133,7 @@ func TestNew(t *testing.T) {
133133
name: "success-no-ipv4-config-with-ipv4-connection",
134134
localIPs: []net.IP{net.ParseIP("64.86.148.137")},
135135
provider: &localRawfile,
136-
hostname: "mlab1.six02.measurement-lab.org",
136+
hostname: "mlab1-six02.mlab-sandbox.measurement-lab.org",
137137
ID: &inetdiag.SockID{
138138
SPort: 1,
139139
SrcIP: "64.86.148.137",
@@ -146,7 +146,7 @@ func TestNew(t *testing.T) {
146146
name: "success-no-ipv6-config-with-ipv4-connection",
147147
localIPs: []net.IP{net.ParseIP("64.86.148.130")},
148148
provider: &localRawfile,
149-
hostname: "mlab1.six01.measurement-lab.org",
149+
hostname: "mlab1-six01.mlab-sandbox.measurement-lab.org",
150150
ID: &inetdiag.SockID{
151151
SPort: 1,
152152
SrcIP: "64.86.148.130",
@@ -161,7 +161,7 @@ func TestNew(t *testing.T) {
161161
name: "success-no-ipv6-config-with-ipv6-connection",
162162
localIPs: []net.IP{net.ParseIP("2001:5a0:4300::2")},
163163
provider: &localRawfile,
164-
hostname: "mlab1.six01.measurement-lab.org",
164+
hostname: "mlab1-six01.mlab-sandbox.measurement-lab.org",
165165
ID: &inetdiag.SockID{
166166
SPort: 1,
167167
SrcIP: "2001:5a0:4300::2",
@@ -174,7 +174,7 @@ func TestNew(t *testing.T) {
174174
name: "error-neither-ips-are-server",
175175
localIPs: []net.IP{net.ParseIP("64.86.148.137")},
176176
provider: &localRawfile,
177-
hostname: "mlab1.lga03.measurement-lab.org",
177+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
178178
ID: &inetdiag.SockID{
179179
SPort: 1,
180180
SrcIP: "2.0.0.2",
@@ -212,7 +212,7 @@ func Test_srvannotator_load(t *testing.T) {
212212
{
213213
name: "success",
214214
provider: &localRawfile,
215-
hostname: "mlab1.lga03.measurement-lab.org",
215+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
216216
want: &annotator.ServerAnnotations{
217217
Site: "lga03",
218218
Machine: "mlab1",
@@ -235,7 +235,7 @@ func Test_srvannotator_load(t *testing.T) {
235235
{
236236
name: "success-project-flat-name",
237237
provider: &localRawfile,
238-
hostname: "mlab1-lga03.mlab-oti.measurement-lab.org",
238+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
239239
want: &annotator.ServerAnnotations{
240240
Site: "lga03",
241241
Machine: "mlab1",
@@ -258,7 +258,7 @@ func Test_srvannotator_load(t *testing.T) {
258258
{
259259
name: "success-no-six",
260260
provider: &localRawfile,
261-
hostname: "mlab1.six01.measurement-lab.org",
261+
hostname: "mlab1-six01.mlab-sandbox.measurement-lab.org",
262262
want: &annotator.ServerAnnotations{
263263
Site: "six01",
264264
Machine: "mlab1",
@@ -273,25 +273,25 @@ func Test_srvannotator_load(t *testing.T) {
273273
{
274274
name: "error-bad-ipv4",
275275
provider: &localRawfile,
276-
hostname: "mlab1.bad04.measurement-lab.org",
276+
hostname: "mlab1-bad04.mlab-sandbox.measurement-lab.org",
277277
wantErr: true,
278278
},
279279
{
280280
name: "error-bad-ipv6",
281281
provider: &localRawfile,
282-
hostname: "mlab1.bad06.measurement-lab.org",
282+
hostname: "mlab1-bad06.mlab-sandbox.measurement-lab.org",
283283
wantErr: true,
284284
},
285285
{
286286
name: "error-loading-provider",
287287
provider: &bad,
288-
hostname: "mlab1.lga03.measurement-lab.org",
288+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
289289
wantErr: true,
290290
},
291291
{
292292
name: "error-corrupt-json",
293293
provider: &corruptFile,
294-
hostname: "mlab1.lga03.measurement-lab.org",
294+
hostname: "mlab1-lga03.mlab-sandbox.measurement-lab.org",
295295
wantErr: true,
296296
},
297297
{
@@ -303,13 +303,13 @@ func Test_srvannotator_load(t *testing.T) {
303303
{
304304
name: "error-bad-name-separator",
305305
provider: &localRawfile,
306-
hostname: "mlab1=lga03.mlab-oti.measurement-lab.org",
306+
hostname: "mlab1=lga03.mlab-sandbox.measurement-lab.org",
307307
wantErr: true,
308308
},
309309
{
310310
name: "error-hostname-not-in-annotations",
311311
provider: &localRawfile,
312-
hostname: "mlab1.abc01.measurement-lab.org",
312+
hostname: "mlab1-abc01.mlab-sandbox.measurement-lab.org",
313313
wantErr: true,
314314
},
315315
}

testdata/annotations.json

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[
2-
{
1+
{
2+
"mlab1-lga03.mlab-sandbox.measurement-lab.org": {
33
"Annotation": {
44
"Geo": {
55
"City": "New York",
@@ -9,6 +9,7 @@
99
"Longitude": -73.8667,
1010
"State": "NY"
1111
},
12+
"Machine": "mlab1",
1213
"Network": {
1314
"ASName": "TATA COMMUNICATIONS (AMERICA) INC",
1415
"ASNumber": 6453,
@@ -22,74 +23,78 @@
2223
},
2324
"Site": "lga03"
2425
},
25-
"Name": "lga03",
2626
"Network": {
2727
"IPv4": "64.86.148.128/26",
2828
"IPv6": "2001:5a0:4300::/64"
29-
}
29+
},
30+
"Type": "physical"
3031
},
31-
{
32+
"mlab1-six02.mlab-sandbox.measurement-lab.org": {
3233
"Annotation": {
3334
"Geo": {
3435
"City": "New York"
3536
},
37+
"Machine": "mlab1",
3638
"Network": {
3739
"ASName": "TATA COMMUNICATIONS (AMERICA) INC"
3840
},
3941
"Site": "six02"
4042
},
41-
"Name": "six02",
4243
"Network": {
4344
"IPv4": "",
4445
"IPv6": "2001:5a0:4300::/64"
45-
}
46+
},
47+
"Type": "virtual"
4648
},
47-
{
49+
"mlab1-six01.mlab-sandbox.measurement-lab.org": {
4850
"Annotation": {
4951
"Geo": {
5052
"City": "New York"
5153
},
54+
"Machine": "mlab1",
5255
"Network": {
5356
"ASName": "TATA COMMUNICATIONS (AMERICA) INC"
5457
},
5558
"Site": "six01"
5659
},
57-
"Name": "six01",
5860
"Network": {
5961
"IPv4": "64.86.148.128/26",
6062
"IPv6": ""
61-
}
63+
},
64+
"Type": "physical"
6265
},
63-
{
66+
"mlab1-bad04.mlab-sandbox.measurement-lab.org": {
6467
"Annotation": {
6568
"Geo": {
6669
"City": "New York"
6770
},
71+
"Machine": "mlab1",
6872
"Network": {
6973
"ASName": "TATA COMMUNICATIONS (AMERICA) INC"
7074
},
7175
"Site": "bad04"
7276
},
73-
"Name": "bad04",
7477
"Network": {
7578
"IPv4": "this-is-not-a-subnet/26",
7679
"IPv6": "2001:5a0:4300::/64"
77-
}
80+
},
81+
"Type": "physical"
7882
},
79-
{
83+
"mlab1-bad06.mlab-sandbox.measurement-lab.org": {
8084
"Annotation": {
8185
"Geo": {
8286
"City": "New York"
8387
},
88+
"Machine": "mlab1",
8489
"Network": {
8590
"ASName": "TATA COMMUNICATIONS (AMERICA) INC"
8691
},
8792
"Site": "bad06"
8893
},
89-
"Name": "bad06",
9094
"Network": {
9195
"IPv4": "64.86.148.128/26",
9296
"IPv6": "this-is-not-a-subnet/64"
93-
}
97+
},
98+
"Type": "physical"
9499
}
95-
]
100+
}

0 commit comments

Comments
 (0)