Skip to content

Commit

Permalink
Fixed tutorial.
Browse files Browse the repository at this point in the history
Signed-off-by: bwplotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Apr 21, 2023
1 parent 90eb83b commit 6ecf1df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tutorial/whatsup/Makefile
@@ -1,3 +1,4 @@
HOSTADDR ?= localhost

.PHONY: help
help: ## Displays help.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tutorial/whatsup/internal/acceptance_test.go
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions tutorial/whatsup/internal/common.go
Expand Up @@ -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{}

Expand Down
16 changes: 13 additions & 3 deletions tutorial/whatsup/internal/playground_test.go
Expand Up @@ -19,6 +19,7 @@ package internal
import (
"fmt"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 6ecf1df

Please sign in to comment.