| Index: go/src/infra/tools/kitchen/cook_logdog.go
|
| diff --git a/go/src/infra/tools/kitchen/cook_logdog.go b/go/src/infra/tools/kitchen/cook_logdog.go
|
| index 48ea4ea9c274db4a94b4d3dfd18c030842625945..7c20db9d83fcde72d8dc1f5cdae56a176144b01b 100644
|
| --- a/go/src/infra/tools/kitchen/cook_logdog.go
|
| +++ b/go/src/infra/tools/kitchen/cook_logdog.go
|
| @@ -23,12 +23,32 @@ import (
|
| "github.com/luci/luci-go/common/ctxcmd"
|
| "github.com/luci/luci-go/common/environ"
|
| "github.com/luci/luci-go/common/errors"
|
| + "github.com/luci/luci-go/common/logdog/types"
|
| log "github.com/luci/luci-go/common/logging"
|
|
|
| "github.com/golang/protobuf/proto"
|
| "golang.org/x/net/context"
|
| )
|
|
|
| +// buildLogdogPrefix constructs a LogDog Prefix string from Swarming task
|
| +// parameters.
|
| +func buildLogdogPrefix(host, taskID string) (types.StreamName, error) {
|
| + return types.MakeStreamName("", "swarm", host, taskID)
|
| +}
|
| +
|
| +func getLogdogPrefix(env environ.Env) (types.StreamName, error) {
|
| + // Construct our LogDog prefix from the Swarming task parameters.
|
| + host, taskID, err := getSwarmingTaskParameters(env)
|
| + if err != nil {
|
| + return "", errors.Annotate(err).Reason("failed to get swarming task parameters").Err()
|
| + }
|
| + prefix, err := buildLogdogPrefix(host, taskID)
|
| + if err != nil {
|
| + return "", errors.Annotate(err).Reason("failed to build LogDog prefix.").Err()
|
| + }
|
| + return prefix, nil
|
| +}
|
| +
|
| // runWithLogdogButler rus the supplied command through the a LogDog Butler
|
| // engine instance. This involves:
|
| // - Determine a LogDog Prefix.
|
| @@ -39,7 +59,25 @@ import (
|
| // - Otherwise, wait for the process to finish.
|
| // - Shut down the Butler instance.
|
| func (c *cookRun) runWithLogdogButler(ctx context.Context, cmd *exec.Cmd) (rc int, err error) {
|
| - _ = auth.Authenticator{}
|
| + // Get our task's environment.
|
| + var env environ.Env
|
| + if cmd.Env != nil {
|
| + env = environ.New(cmd.Env)
|
| + } else {
|
| + env = environ.System()
|
| + }
|
| +
|
| + prefix := c.logdog.prefix
|
| + if prefix == "" {
|
| + var err error
|
| + prefix, err = getLogdogPrefix(env)
|
| + if err != nil {
|
| + return 0, errors.Annotate(err).Err()
|
| + }
|
| + log.Fields{
|
| + "prefix": prefix,
|
| + }.Infof(ctx, "Generated LogDog prefix [%q] from Swarming parameters.", prefix)
|
| + }
|
|
|
| authenticator := auth.NewAuthenticator(ctx, auth.SilentLogin, auth.Options{
|
| Scopes: out.Scopes(),
|
| @@ -52,7 +90,7 @@ func (c *cookRun) runWithLogdogButler(ctx context.Context, cmd *exec.Cmd) (rc in
|
| Auth: authenticator,
|
| Host: c.logdog.host,
|
| Project: config.ProjectName(c.logdog.project),
|
| - Prefix: c.logdog.prefix,
|
| + Prefix: prefix,
|
| SourceInfo: []string{
|
| "Kitchen",
|
| },
|
| @@ -101,13 +139,6 @@ func (c *cookRun) runWithLogdogButler(ctx context.Context, cmd *exec.Cmd) (rc in
|
| Cmd: cmd,
|
| }
|
|
|
| - var env environ.Env
|
| - if proc.Env != nil {
|
| - env = environ.New(proc.Env)
|
| - } else {
|
| - env = environ.System()
|
| - }
|
| -
|
| // Augment our environment with Butler parameters.
|
| bsEnv := bootstrap.Environment{
|
| Project: config.ProjectName(c.logdog.project),
|
|
|