Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: go/src/infra/tools/kitchen/cook.go

Issue 2146403002: Kitchen: Generate LogDog prefix from Swarming. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix error strings in tests. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « DEPS ('k') | go/src/infra/tools/kitchen/cook_logdog.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "io/ioutil" 10 "io/ioutil"
11 "net/url" 11 "net/url"
12 "os" 12 "os"
13 "path" 13 "path"
14 "path/filepath" 14 "path/filepath"
15 "strconv" 15 "strconv"
16 "strings" 16 "strings"
17 17
18 "github.com/maruel/subcommands" 18 "github.com/maruel/subcommands"
19 "golang.org/x/net/context" 19 "golang.org/x/net/context"
20 20
21 "github.com/luci/luci-go/common/cli" 21 "github.com/luci/luci-go/common/cli"
22 "github.com/luci/luci-go/common/clock" 22 "github.com/luci/luci-go/common/clock"
23 "github.com/luci/luci-go/common/ctxcmd" 23 "github.com/luci/luci-go/common/ctxcmd"
24 "github.com/luci/luci-go/common/environ" 24 "github.com/luci/luci-go/common/environ"
25 "github.com/luci/luci-go/common/flag/stringlistflag" 25 "github.com/luci/luci-go/common/flag/stringlistflag"
26 ldTypes "github.com/luci/luci-go/common/logdog/types"
27 ) 26 )
28 27
29 // BootstrapStepName is the name of kitchen's step where it makes preparations 28 // BootstrapStepName is the name of kitchen's step where it makes preparations
30 // for running a recipe, e.g. fetches a repository. 29 // for running a recipe, e.g. fetches a repository.
31 const BootstrapStepName = "recipe bootstrap" 30 const BootstrapStepName = "recipe bootstrap"
32 31
33 // cmdCook checks out a repository at a revision and runs a recipe. 32 // cmdCook checks out a repository at a revision and runs a recipe.
34 var cmdCook = &subcommands.Command{ 33 var cmdCook = &subcommands.Command{
35 UsageLine: "cook -repository <repository URL> -revision <revision> -reci pe <recipe>", 34 UsageLine: "cook -repository <repository URL> -revision <revision> -reci pe <recipe>",
36 ShortDesc: "Checks out a repository and runs a recipe.", 35 ShortDesc: "Checks out a repository and runs a recipe.",
(...skipping 28 matching lines...) Expand all
65 &c.OutputResultJSONFile, 64 &c.OutputResultJSONFile,
66 "output-result-json", 65 "output-result-json",
67 "", 66 "",
68 "The file to write the JSON serialized returned value of the recipe to") 67 "The file to write the JSON serialized returned value of the recipe to")
69 fs.BoolVar( 68 fs.BoolVar(
70 &c.Timestamps, 69 &c.Timestamps,
71 "timestamps", 70 "timestamps",
72 false, 71 false,
73 "If true, print CURRENT_TIMESTAMP annotations.") 72 "If true, print CURRENT_TIMESTAMP annotations.")
74 73
75 » » fs.StringVar( 74 » » c.logdog.addFlags(fs)
76 » » » &c.logdog.host, 75
77 » » » "logdog-host",
78 » » » "",
79 » » » "The name of the LogDog host.")
80 » » fs.StringVar(
81 » » » &c.logdog.project,
82 » » » "logdog-project",
83 » » » "",
84 » » » "The name of the LogDog project to log into. Projects ha ve different ACL sets, "+
85 » » » » "so choose this appropriately.")
86 » » fs.Var(
87 » » » &c.logdog.prefix,
88 » » » "logdog-prefix",
89 » » » "The LogDog stream Prefix to use.")
90 » » fs.BoolVar(
91 » » » &c.logdog.annotee,
92 » » » "logdog-enable-annotee",
93 » » » true,
94 » » » "Process bootstrap STDOUT/STDERR annotations through Ann otee.")
95 » » fs.StringVar(
96 » » » &c.logdog.filePath,
97 » » » "logdog-debug-out-file",
98 » » » "",
99 » » » "If specified, write all generated logs to this path ins tead of sending them.")
100 return &c 76 return &c
101 }, 77 },
102 } 78 }
103 79
104 type cookRun struct { 80 type cookRun struct {
105 subcommands.CommandRunBase 81 subcommands.CommandRunBase
106 82
107 RepositoryURL string 83 RepositoryURL string
108 Revision string 84 Revision string
109 Recipe string 85 Recipe string
110 CheckoutDir string 86 CheckoutDir string
111 Workdir string 87 Workdir string
112 Properties string 88 Properties string
113 PropertiesFile string 89 PropertiesFile string
114 OutputResultJSONFile string 90 OutputResultJSONFile string
115 Timestamps bool 91 Timestamps bool
116 PythonPaths stringlistflag.Flag 92 PythonPaths stringlistflag.Flag
117 93
118 logdog cookLogDogParams 94 logdog cookLogDogParams
119 } 95 }
120 96
121 type cookLogDogParams struct {
122 host string
123 project string
124 prefix ldTypes.StreamName
125 annotee bool
126 filePath string
127 }
128
129 func (p *cookLogDogParams) active() bool {
130 return p.host != "" || p.project != "" || p.prefix != ""
131 }
132
133 func (c *cookRun) validateFlags() error { 97 func (c *cookRun) validateFlags() error {
134 // Validate Repository. 98 // Validate Repository.
135 if c.RepositoryURL == "" { 99 if c.RepositoryURL == "" {
136 return fmt.Errorf("-repository is required") 100 return fmt.Errorf("-repository is required")
137 } 101 }
138 repoURL, err := url.Parse(c.RepositoryURL) 102 repoURL, err := url.Parse(c.RepositoryURL)
139 if err != nil { 103 if err != nil {
140 return fmt.Errorf("invalid repository %q: %s", repoURL, err) 104 return fmt.Errorf("invalid repository %q: %s", repoURL, err)
141 } 105 }
142 repoName := path.Base(repoURL.Path) 106 repoName := path.Base(repoURL.Path)
143 if repoName == "" { 107 if repoName == "" {
144 return fmt.Errorf("invalid repository %q: no path", repoURL) 108 return fmt.Errorf("invalid repository %q: no path", repoURL)
145 } 109 }
146 110
147 // Validate Recipe. 111 // Validate Recipe.
148 if c.Recipe == "" { 112 if c.Recipe == "" {
149 return fmt.Errorf("-recipe is required") 113 return fmt.Errorf("-recipe is required")
150 } 114 }
151 115
152 if c.Properties != "" && c.PropertiesFile != "" { 116 if c.Properties != "" && c.PropertiesFile != "" {
153 return fmt.Errorf("only one of -properties or -properties-file i s allowed") 117 return fmt.Errorf("only one of -properties or -properties-file i s allowed")
154 } 118 }
155 119
156 // If LogDog is enabled, all required LogDog flags must be supplied. 120 // If LogDog is enabled, all required LogDog flags must be supplied.
157 if c.logdog.active() { 121 if c.logdog.active() {
158 » » if c.logdog.project == "" { 122 » » if err := c.logdog.validate(); err != nil {
159 » » » return fmt.Errorf("a LogDog project must be supplied (-l ogdog-project)") 123 » » » return err
160 } 124 }
161 } 125 }
162 126
163 // Fix CheckoutDir. 127 // Fix CheckoutDir.
164 if c.CheckoutDir == "" { 128 if c.CheckoutDir == "" {
165 c.CheckoutDir = repoName 129 c.CheckoutDir = repoName
166 } 130 }
167 return nil 131 return nil
168 } 132 }
169 133
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 286 }
323 287
324 func annotateTime(ctx context.Context) { 288 func annotateTime(ctx context.Context) {
325 timestamp := clock.Get(ctx).Now().Unix() 289 timestamp := clock.Get(ctx).Now().Unix()
326 annotate("CURRENT_TIMESTAMP", strconv.FormatInt(timestamp, 10)) 290 annotate("CURRENT_TIMESTAMP", strconv.FormatInt(timestamp, 10))
327 } 291 }
328 292
329 func annotate(args ...string) { 293 func annotate(args ...string) {
330 fmt.Printf("@@@%s@@@\n", strings.Join(args, "@")) 294 fmt.Printf("@@@%s@@@\n", strings.Join(args, "@"))
331 } 295 }
OLDNEW
« no previous file with comments | « DEPS ('k') | go/src/infra/tools/kitchen/cook_logdog.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698