diff --git a/tutorial/whatsup/Makefile b/tutorial/whatsup/Makefile index 8b3ab22b1..ffb8d36ae 100644 --- a/tutorial/whatsup/Makefile +++ b/tutorial/whatsup/Makefile @@ -1,3 +1,4 @@ +HOSTADDR ?= localhost .PHONY: help help: ## Displays help. @@ -10,7 +11,8 @@ init: ## init .PHONY: stop stop: ## stop init - @curl -s http://localhost:19920 || true + @echo "Stopping on $(HOSTADDR)" + @curl -s http://$(HOSTADDR):19920 || true .PHONY: run run: ## run whatsup diff --git a/tutorial/whatsup/internal/acceptance_test.go b/tutorial/whatsup/internal/acceptance_test.go index 12be318f5..38533c495 100644 --- a/tutorial/whatsup/internal/acceptance_test.go +++ b/tutorial/whatsup/internal/acceptance_test.go @@ -27,7 +27,7 @@ import ( ) func TestAcceptance(t *testing.T) { - resp, err := http.Get(fmt.Sprintf("http://localhost:%v/metrics", WhatsupPort)) + resp, err := http.Get(whatsupAddr(fmt.Sprintf("http://localhost:%v", WhatsupPort)) + "/metrics") testutil.Ok(t, err) defer resp.Body.Close() diff --git a/tutorial/whatsup/internal/common.go b/tutorial/whatsup/internal/common.go index 555236982..0667b79cb 100644 --- a/tutorial/whatsup/internal/common.go +++ b/tutorial/whatsup/internal/common.go @@ -37,6 +37,13 @@ type Config struct { TraceSamplingRatio float64 `yaml:"TraceSamplingRatio,omitempty"` } +func whatsupAddr(defAddress string) string { + if a := os.Getenv("HOSTADDR"); a != "" { + return a + ":" + WhatsupPort + } + return defAddress +} + func ParseOptions(args []string) (Config, error) { c := Config{} diff --git a/tutorial/whatsup/internal/playground_test.go b/tutorial/whatsup/internal/playground_test.go index a33d65970..abecb4f91 100644 --- a/tutorial/whatsup/internal/playground_test.go +++ b/tutorial/whatsup/internal/playground_test.go @@ -19,6 +19,7 @@ package internal import ( "fmt" "os" + "strings" "testing" "time" @@ -71,18 +72,27 @@ func TestPlayground(t *testing.T) { testutil.Ok(t, prom.SetConfig(prometheusConfig(map[string]string{ "prometheus": prom.InternalEndpoint("http"), "jaeger": jaeger.InternalEndpoint("http.metrics"), - "whatsup": fmt.Sprintf("host.docker.internal:%v", WhatsupPort), + "whatsup": whatsupAddr(fmt.Sprintf("host.docker.internal:%v", WhatsupPort)), }))) // Due to VM based docker setups (e.g. MacOS), file sharing can be slower - do more sighups just in case (noops if all good) prom.Exec(e2e.NewCommand("kill", "-SIGHUP", "1")) prom.Exec(e2e.NewCommand("kill", "-SIGHUP", "1")) // Best effort. - fmt.Println(e2einteractive.OpenInBrowser("http://" + jaeger.Endpoint("http.front"))) - fmt.Println(e2einteractive.OpenInBrowser("http://" + prom.Endpoint("http"))) + fmt.Println(e2einteractive.OpenInBrowser(convertToExternal("http://" + jaeger.Endpoint("http.front")))) + fmt.Println(e2einteractive.OpenInBrowser(convertToExternal("http://" + prom.Endpoint("http")))) testutil.Ok(t, e2einteractive.RunUntilEndpointHitWithPort(19920)) } +func convertToExternal(endpoint string) string { + a := os.Getenv("HOSTADDR") + if a == "" { + return endpoint + } + // YOLO, fix and test. + return fmt.Sprintf("%v:%v", a, strings.Split(endpoint, ":")[2]) +} + func prometheusConfig(jobToScrapeTargetAddress map[string]string) promconfig.Config { h, _ := os.Hostname() cfg := promconfig.Config{