Merge "Add reasonable defaults to RBE configuration parameters."
This commit is contained in:
commit
5d942d05b1
|
@ -15,6 +15,7 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -261,7 +262,7 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
|
||||
|
||||
if ret.UseRBE() {
|
||||
for k, v := range getRBEVars(ctx, tmpDir) {
|
||||
for k, v := range getRBEVars(ctx, Config{ret}) {
|
||||
ret.environ.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
@ -825,13 +826,73 @@ func (c *configImpl) StartRBE() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *configImpl) RBEStatsOutputDir() string {
|
||||
func (c *configImpl) logDir() string {
|
||||
if c.Dist() {
|
||||
return filepath.Join(c.DistDir(), "logs")
|
||||
}
|
||||
return c.OutDir()
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeStatsOutputDir() string {
|
||||
for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} {
|
||||
if v, ok := c.environ.Get(f); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return c.logDir()
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeLogPath() string {
|
||||
for _, f := range []string{"RBE_log_path", "FLAG_log_path"} {
|
||||
if v, ok := c.environ.Get(f); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("text://%v/reproxy_log.txt", c.logDir())
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeExecRoot() string {
|
||||
for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} {
|
||||
if v, ok := c.environ.Get(f); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return wd
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeDir() string {
|
||||
if v, ok := c.environ.Get("RBE_DIR"); ok {
|
||||
return v
|
||||
}
|
||||
return "prebuilts/remoteexecution-client/live/"
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeReproxy() string {
|
||||
for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} {
|
||||
if v, ok := c.environ.Get(f); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return filepath.Join(c.rbeDir(), "reproxy")
|
||||
}
|
||||
|
||||
func (c *configImpl) rbeAuth() (string, string) {
|
||||
credFlags := []string{"use_application_default_credentials", "use_gce_credentials", "credential_file"}
|
||||
for _, cf := range credFlags {
|
||||
for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} {
|
||||
if v, ok := c.environ.Get(f); ok {
|
||||
v = strings.TrimSpace(v)
|
||||
if v != "" && v != "false" && v != "0" {
|
||||
return "RBE_" + cf, v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "RBE_use_application_default_credentials", "true"
|
||||
}
|
||||
|
||||
func (c *configImpl) UseRemoteBuild() bool {
|
||||
|
|
|
@ -37,10 +37,8 @@ const (
|
|||
|
||||
func rbeCommand(ctx Context, config Config, rbeCmd string) string {
|
||||
var cmdPath string
|
||||
if rbeDir, ok := config.Environment().Get("RBE_DIR"); ok {
|
||||
if rbeDir := config.rbeDir(); rbeDir != "" {
|
||||
cmdPath = filepath.Join(rbeDir, rbeCmd)
|
||||
} else if home, ok := config.Environment().Get("HOME"); ok {
|
||||
cmdPath = filepath.Join(home, "rbe", rbeCmd)
|
||||
} else {
|
||||
ctx.Fatalf("rbe command path not found")
|
||||
}
|
||||
|
@ -52,9 +50,18 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string {
|
|||
return cmdPath
|
||||
}
|
||||
|
||||
func getRBEVars(ctx Context, tmpDir string) map[string]string {
|
||||
func getRBEVars(ctx Context, config Config) map[string]string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return map[string]string{"RBE_server_address": fmt.Sprintf("unix://%v/reproxy_%v.sock", tmpDir, rand.Intn(1000))}
|
||||
vars := map[string]string{
|
||||
"RBE_server_address": fmt.Sprintf("unix://%v/reproxy_%v.sock", absPath(ctx, config.TempDir()), rand.Intn(1000)),
|
||||
"RBE_log_path": config.rbeLogPath(),
|
||||
"RBE_re_proxy": config.rbeReproxy(),
|
||||
"RBE_exec_root": config.rbeExecRoot(),
|
||||
"RBE_output_dir": config.rbeStatsOutputDir(),
|
||||
}
|
||||
k, v := config.rbeAuth()
|
||||
vars[k] = v
|
||||
return vars
|
||||
}
|
||||
|
||||
func startRBE(ctx Context, config Config) {
|
||||
|
@ -102,7 +109,7 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) {
|
|||
return
|
||||
}
|
||||
|
||||
outputDir := config.RBEStatsOutputDir()
|
||||
outputDir := config.rbeStatsOutputDir()
|
||||
if outputDir == "" {
|
||||
ctx.Fatal("RBE output dir variable not defined. Aborting metrics dumping.")
|
||||
}
|
||||
|
@ -111,6 +118,9 @@ func DumpRBEMetrics(ctx Context, config Config, filename string) {
|
|||
// Stop the proxy first in order to generate the RBE metrics protobuf file.
|
||||
stopRBE(ctx, config)
|
||||
|
||||
if metricsFile == filename {
|
||||
return
|
||||
}
|
||||
if _, err := copyFile(metricsFile, filename); err != nil {
|
||||
ctx.Fatalf("failed to copy %q to %q: %v\n", metricsFile, filename, err)
|
||||
}
|
||||
|
|
|
@ -83,24 +83,13 @@ func TestDumpRBEMetrics(t *testing.T) {
|
|||
func TestDumpRBEMetricsErrors(t *testing.T) {
|
||||
ctx := testContext()
|
||||
tests := []struct {
|
||||
description string
|
||||
rbeOutputDirDefined bool
|
||||
bootstrapProgram string
|
||||
expectedErr string
|
||||
description string
|
||||
bootstrapProgram string
|
||||
expectedErr string
|
||||
}{{
|
||||
description: "output_dir not defined",
|
||||
bootstrapProgram: rbeBootstrapProgram,
|
||||
expectedErr: "RBE output dir variable not defined",
|
||||
}, {
|
||||
description: "stopRBE failed",
|
||||
rbeOutputDirDefined: true,
|
||||
bootstrapProgram: "#!/bin/bash\nexit 1\n",
|
||||
expectedErr: "shutdown failed",
|
||||
}, {
|
||||
description: "failed to copy metrics file",
|
||||
rbeOutputDirDefined: true,
|
||||
bootstrapProgram: "#!/bin/bash\n",
|
||||
expectedErr: "failed to copy",
|
||||
description: "stopRBE failed",
|
||||
bootstrapProgram: "#!/bin/bash\nexit 1\n",
|
||||
expectedErr: "shutdown failed",
|
||||
}}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
@ -124,10 +113,6 @@ func TestDumpRBEMetricsErrors(t *testing.T) {
|
|||
env.Set("OUT_DIR", tmpDir)
|
||||
env.Set("RBE_DIR", tmpDir)
|
||||
|
||||
if tt.rbeOutputDirDefined {
|
||||
env.Set("RBE_output_dir", t.TempDir())
|
||||
}
|
||||
|
||||
config := Config{&configImpl{
|
||||
environ: env,
|
||||
}}
|
||||
|
|
Loading…
Reference in New Issue