Skip to content

Commit

Permalink
Build hostname based on CloudRun envs
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Nov 9, 2023
1 parent 8ed667c commit c6541f2
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/webrtc-load-tester/roles/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/url"
"os"
"strings"
"time"

"github.com/chromedp/chromedp"
Expand Down Expand Up @@ -103,14 +104,11 @@ func runSinglePlayerTest(ctx context.Context, args playerArguments, idx uint) er
chromedp.Navigate(url),
}

glog.Infof("Running player with env vars ", os.Environ())

if args.ScreenshotFolderOS == nil {
tasks = append(tasks, chromedp.Sleep(args.TestDuration))
} else {
hostname, _ := os.Hostname()
osFolder := args.ScreenshotFolderOS.
JoinPath(hostname, fmt.Sprintf("player-%d", idx)).
JoinPath(getHostname(), fmt.Sprintf("player-%d", idx)).
String()

driver, err := drivers.ParseOSURL(osFolder, true)
Expand Down Expand Up @@ -183,3 +181,18 @@ func buildPlayerUrl(baseURL, playbackID, playbackURL string) (string, error) {

return url.String(), nil
}

func getHostname() string {
execution := os.Getenv("CLOUD_RUN_EXECUTION")
taskIndex := os.Getenv("CLOUD_RUN_TASK_INDEX")

if execution != "" && taskIndex != "" {
// extract only the final hash on the execution name
parts := strings.Split(execution, "-")
hash := parts[len(parts)-1]
return fmt.Sprintf("exec-%s-task-%s", hash, taskIndex)
}

hostname, _ := os.Hostname()
return hostname
}

0 comments on commit c6541f2

Please sign in to comment.