diff --git a/go.mod b/go.mod index a7d7d87..267e50d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/go-test/deep v1.0.6 github.com/m-lab/annotation-service v0.0.0-20210504151333-138bdf572368 - github.com/m-lab/go v0.1.47 + github.com/m-lab/go v0.1.57 github.com/m-lab/tcp-info v1.5.3 github.com/oschwald/geoip2-golang v1.7.0 github.com/prometheus/client_golang v1.12.2 diff --git a/go.sum b/go.sum index e5e382c..3164fc0 100644 --- a/go.sum +++ b/go.sum @@ -248,6 +248,8 @@ github.com/m-lab/annotation-service v0.0.0-20210504151333-138bdf572368 h1:cRzgLE github.com/m-lab/annotation-service v0.0.0-20210504151333-138bdf572368/go.mod h1:bW5A2AmUqyh6kGbmu4X8fYK2pRcfTvTjAXW/+4VQZUA= github.com/m-lab/go v0.1.47 h1:yV6RgVpiWm2BnpJcjfy4pbUkB9cz0BvBbVG64UGLiC0= github.com/m-lab/go v0.1.47/go.mod h1:woT26L9Hf07juZGHe7Z4WveV7MM6NS6vQaaWzRQnab4= +github.com/m-lab/go v0.1.57 h1:C6IjtM/DY0FEiA3FB2HS7av4ybtwQOa8Y3vys6XEXaA= +github.com/m-lab/go v0.1.57/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ= github.com/m-lab/tcp-info v1.5.3 h1:4IspTPcNc8D8LNRvuFnID8gDiz+hxPAtYvpKZaiGGe8= github.com/m-lab/tcp-info v1.5.3/go.mod h1:bkvI4qbjB6QVC2tsLSHqf5OnIYcmuLEVjo7+8YA56Kg= github.com/m-lab/uuid-annotator v0.4.1/go.mod h1:f/zvgcc5A3HQ1Y63HWpbBVXNcsJwQ4uRIOqsF/nyto8= diff --git a/main.go b/main.go index 8e7d0fa..68b8e97 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/m-lab/go/content" "github.com/m-lab/go/flagx" + "github.com/m-lab/go/host" "github.com/m-lab/go/memoryless" "github.com/m-lab/go/prometheusx" "github.com/m-lab/go/rtx" @@ -71,6 +72,19 @@ func main() { flag.Parse() rtx.Must(flagx.ArgsFromEnv(flag.CommandLine), "Could not get args from environment variables") + // Parse the node's name into its constituent parts. This ensures that the + // value of the -hostname flag is actually valid. Additionally, virtual + // nodes which are part of a managed instance group may have a random + // suffix, which uuid-annotator cannot use, so we explicitly only include + // the parts of the node name that uuid-annotator actually cares about. The + // resultant variable mlabHostname should match a machine name in siteinfo's + // annotations.json: + // + // https://siteinfo.mlab-oti.measurementlab.net/v2/sites/annotations.json + h, err := host.Parse(*hostname) + rtx.Must(err, "Failed to parse -hostname flag value") + mlabHostname := h.String() + defer mainCancel() // A waitgroup that waits for every component goroutine to complete before main exits. wg := sync.WaitGroup{} @@ -121,7 +135,7 @@ func main() { // Load the siteinfo annotations for "site" specific metadata. js, err := content.FromURL(mainCtx, siteinfo.URL) rtx.Must(err, "Could not load siteinfo URL") - site := siteannotator.New(mainCtx, *hostname, js, localIPs) + site := siteannotator.New(mainCtx, mlabHostname, js, localIPs) // Generate .json files for every UUID discovered. h := handler.New(*datadir, *eventbuffersize, []annotator.Annotator{geo, asn, site})