Skip to content

Commit

Permalink
Add -hostname-file flag (#65)
Browse files Browse the repository at this point in the history
* Update m-lab/go to v0.1.73

* Add -hostname-file flag
  • Loading branch information
robertodauria authored May 16, 2024
1 parent a36f346 commit a844149
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/go-test/deep v1.0.6
github.com/m-lab/go v0.1.66
github.com/m-lab/go v0.1.73
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/m-lab/go v0.1.66 h1:adDJILqKBCkd5YeVhCrrjWkjoNRtDzlDr6uizWu5/pE=
github.com/m-lab/go v0.1.66/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ=
github.com/m-lab/go v0.1.73 h1:vy4MRcEyvYOhfA55V6tT/NZlrfWS0qTNJktIrLaAbmw=
github.com/m-lab/go v0.1.73/go.mod h1:BirARfHWjjXHaCGNyWCm/CKW1OarjuEj8Yn6Z2rc0M4=
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/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
var (
datadir = flag.String("datadir", ".", "The directory to put the data in")
hostname = flag.String("hostname", "", "The server hostname, used to lookup server siteinfo annotations")
hostnameFile = flagx.FileBytes{}
maxmindurl = flagx.URL{}
routeviewv4 = flagx.URL{}
routeviewv6 = flagx.URL{}
Expand All @@ -49,6 +50,7 @@ var (
)

func init() {
flag.Var(&hostnameFile, "hostname-file", "The file containing the server hostname.")
flag.Var(&maxmindurl, "maxmind.url", "The URL for the file containing MaxMind IP metadata. Accepted URL schemes currently are: gs://bucket/file and file:./relativepath/file")
flag.Var(&routeviewv4, "routeview-v4.url", "The URL for the RouteViewIPv4 file containing ASN metadata. gs:// and file:// schemes accepted.")
flag.Var(&routeviewv6, "routeview-v6.url", "The URL for the RouteViewIPv6 file containing ASN metadata. gs:// and file:// schemes accepted.")
Expand All @@ -73,6 +75,12 @@ func main() {
flag.Parse()
rtx.Must(flagx.ArgsFromEnv(flag.CommandLine), "Could not get args from environment variables")

// If the -hostname flag was not set, try reading the hostname from the
// -hostname-file.
if hostnameFile.String() != "" && *hostname == "" {
*hostname = hostnameFile.String()
}

// Create the datatype directory immediately, since pusher will crash
// without it.
rtx.Must(os.MkdirAll(*datadir, 0755), "Could not create datatype dir %s", datadir)
Expand All @@ -87,7 +95,7 @@ func main() {
//
// https://siteinfo.mlab-oti.measurementlab.net/v2/sites/annotations.json
h, err := host.Parse(*hostname)
rtx.Must(err, "Failed to parse -hostname flag value")
rtx.Must(err, "Failed to parse the provided hostname")
mlabHostname := h.String()

defer mainCancel()
Expand Down

0 comments on commit a844149

Please sign in to comment.