Skip to content

Commit c4918c9

Browse files
authored
Use updated version of m-lab/go/host, which supports service names (#117)
* Uses m-lab/go/host package to determine hostname Virtual machines that are part of a managed instance group will have hostnames/machinenames that have a random suffix, and many of mlab's tools expect hostnames without this suffix. This commit uses the hostname as parsed by the `host` package rather than the raw node Name passed in through the environment. This should result in a valid hostname that does not include any random suffixes. * Uses m-lab/go/host v0.1.58 to preserve service name In the case of virtual nodes that are part of a managed instane group, the node name and hostname will have a random 4 char suffix. This suffix isn't wanted by heartbeat or Locate. This commit updates the included version of m-lab/go to bring in changes to the host package, which adds new functions for returning the hostname with or without service names and suffixes. * Fixes unit test for location.go which uses package
1 parent f5db798 commit c4918c9

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

cmd/heartbeat/heartbeatmsg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func LoadRegistration(ctx context.Context, hostname string, url *url.URL) (*v2.R
3939
}
4040

4141
if v, ok := registrations[h.String()]; ok {
42-
v.Hostname = hostname
42+
v.Hostname = h.StringWithService()
4343
return &v, nil
4444
}
4545

cmd/heartbeat/heartbeatmsg_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ func Test_LoadRegistration(t *testing.T) {
4444
wantErr: false,
4545
wantMsg: validMsg,
4646
},
47+
{
48+
name: "valid-hostname-with-suffix",
49+
hostname: validHostname + "-t95j",
50+
url: validURL,
51+
wantErr: false,
52+
wantMsg: validMsg,
53+
},
4754
{
4855
name: "invalid-hostname",
4956
hostname: "foo",

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ require (
1414
github.com/hashicorp/go-multierror v1.1.1
1515
github.com/justinas/alice v1.2.0
1616
github.com/m-lab/access v0.0.10
17-
github.com/m-lab/go v0.1.54
17+
github.com/m-lab/go v0.1.58
1818
github.com/m-lab/uuid-annotator v0.4.5
1919
github.com/oschwald/geoip2-golang v1.5.0
2020
github.com/prometheus/client_golang v1.13.0
21+
github.com/prometheus/client_model v0.2.0
2122
github.com/prometheus/common v0.37.0
2223
github.com/rafaeljusto/redigomock v2.4.0+incompatible
2324
github.com/sirupsen/logrus v1.8.1
@@ -65,7 +66,6 @@ require (
6566
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
6667
github.com/oschwald/maxminddb-golang v1.8.0 // indirect
6768
github.com/pkg/errors v0.9.1 // indirect
68-
github.com/prometheus/client_model v0.2.0 // indirect
6969
github.com/prometheus/procfs v0.8.0 // indirect
7070
go.opencensus.io v0.23.0 // indirect
7171
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ github.com/m-lab/access v0.0.10 h1:t/lMUJ+nGyDvW9fhT3yDFB+1hQgmuKEX7QMBOqkJBrA=
306306
github.com/m-lab/access v0.0.10/go.mod h1:gZ7YN3SeMTZYeRv5EFaLdG+XVI/F/X4njM1G1BfwuE4=
307307
github.com/m-lab/annotation-service v0.0.0-20210504151333-138bdf572368/go.mod h1:bW5A2AmUqyh6kGbmu4X8fYK2pRcfTvTjAXW/+4VQZUA=
308308
github.com/m-lab/go v0.1.44/go.mod h1:+C0ZBlRKsF7wIbqHRtiL8bqD6cOwlZXDTK/KQ7Iv434=
309-
github.com/m-lab/go v0.1.54 h1:z5FxSrcMT0RJF/EDNjeo77pmvzvhGHJMiyPl4N9Mbzo=
310-
github.com/m-lab/go v0.1.54/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ=
309+
github.com/m-lab/go v0.1.58 h1:Byow2/BmhoKy6+0hHMx5WxZiD7lF7fQcnEMtaHNxkC0=
310+
github.com/m-lab/go v0.1.58/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ=
311311
github.com/m-lab/tcp-info v1.5.3/go.mod h1:bkvI4qbjB6QVC2tsLSHqf5OnIYcmuLEVjo7+8YA56Kg=
312312
github.com/m-lab/uuid-annotator v0.4.1/go.mod h1:f/zvgcc5A3HQ1Y63HWpbBVXNcsJwQ4uRIOqsF/nyto8=
313313
github.com/m-lab/uuid-annotator v0.4.5 h1:YSgAwaYqgJ85Al+40DEc3NGBaL1t4TiZatdzXgFNTTI=

heartbeat/location_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,12 @@ func TestIsValidInstance(t *testing.T) {
526526
score: validScore,
527527
expected: true,
528528
expectedHost: host.Name{
529+
Service: "ndt",
529530
Machine: "mlab1",
530531
Site: "lga00",
531532
Project: "mlab-sandbox",
532533
Domain: "measurement-lab.org",
534+
Suffix: "",
533535
Version: "v2",
534536
},
535537
expectedDist: 296.043665,
@@ -545,10 +547,12 @@ func TestIsValidInstance(t *testing.T) {
545547
score: validScore,
546548
expected: true,
547549
expectedHost: host.Name{
550+
Service: "ndt",
548551
Machine: "mlab1",
549552
Site: "lga00",
550553
Project: "mlab-sandbox",
551554
Domain: "measurement-lab.org",
555+
Suffix: "",
552556
Version: "v2",
553557
},
554558
expectedDist: 296.043665,
@@ -586,7 +590,7 @@ func TestIsValidInstance(t *testing.T) {
586590
}
587591

588592
if gotHost != tt.expectedHost {
589-
t.Errorf("isValidInstance() host got: %+v, want: %+v", gotHost, tt.expectedHost)
593+
t.Errorf("isValidInstance() host got: %#v, want: %#v", gotHost, tt.expectedHost)
590594
}
591595

592596
if math.Abs(gotDist-tt.expectedDist) > 0.01 {

0 commit comments

Comments
 (0)