From 671a2f0568cb89c0fc8ef21c826b228dacbe8516 Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Fri, 21 Apr 2023 15:23:45 +0200 Subject: [PATCH] Fixed tutorial. (#1256) Signed-off-by: bwplotka --- tutorial/whatsup/Makefile | 1 - tutorial/whatsup/internal/acceptance_test.go | 2 +- tutorial/whatsup/internal/common.go | 7 +++++++ tutorial/whatsup/internal/playground_test.go | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tutorial/whatsup/Makefile b/tutorial/whatsup/Makefile index 8b3ab22..f204021 100644 --- a/tutorial/whatsup/Makefile +++ b/tutorial/whatsup/Makefile @@ -1,4 +1,3 @@ - .PHONY: help help: ## Displays help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-z0-9A-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) diff --git a/tutorial/whatsup/internal/acceptance_test.go b/tutorial/whatsup/internal/acceptance_test.go index 12be318..38533c4 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 5552369..0667b79 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 a33d659..abecb4f 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{