github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/k6runner/env.go (about)

     1  package k6runner
     2  
     3  import (
     4  	"slices"
     5  	"strings"
     6  )
     7  
     8  // k6Env returns the environment variables that are passed to the k6 process that runs checks.
     9  // Ideally, this should be a clean slate env, but we know people are relying on the fact that k6 inherits the agent's
    10  // environment.
    11  // TODO: Make this a clean slate on the next major release, as a breaking change.
    12  func k6Env(localEnv []string) []string {
    13  	// envDefaults maps environment variables to their value. They will be set only if the environment variable is not
    14  	// already present on localEnv.
    15  	envDefaults := map[string]string{
    16  		"K6_BROWSER_LOG":               "info",
    17  		"K6_AUTO_EXTENSION_RESOLUTION": "false",
    18  	}
    19  
    20  	for env, val := range envDefaults {
    21  		if !slices.ContainsFunc(localEnv, func(e string) bool { return strings.HasPrefix(e, env+"=") }) {
    22  			localEnv = append(localEnv, env+"="+val)
    23  		}
    24  	}
    25  
    26  	return localEnv
    27  }