| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 "errors" | 9 "errors" |
| 10 "flag" | 10 "flag" |
| 11 "fmt" | 11 "fmt" |
| 12 "os" | 12 "os" |
| 13 "time" | 13 "time" |
| 14 | 14 |
| 15 "github.com/golang/protobuf/proto" | 15 "github.com/golang/protobuf/proto" |
| 16 "github.com/luci/luci-go/common/clock/clockflag" | 16 "github.com/luci/luci-go/common/clock/clockflag" |
| 17 "github.com/luci/luci-go/common/config" | 17 "github.com/luci/luci-go/common/config" |
| 18 log "github.com/luci/luci-go/common/logging" | 18 log "github.com/luci/luci-go/common/logging" |
| 19 "github.com/luci/luci-go/common/logging/gologger" | 19 "github.com/luci/luci-go/common/logging/gologger" |
| 20 "github.com/luci/luci-go/common/proto/milo" | 20 "github.com/luci/luci-go/common/proto/milo" |
| 21 "github.com/luci/luci-go/common/runtime/profiling" |
| 21 "github.com/luci/luci-go/logdog/client/annotee" | 22 "github.com/luci/luci-go/logdog/client/annotee" |
| 22 "github.com/luci/luci-go/logdog/client/annotee/executor" | 23 "github.com/luci/luci-go/logdog/client/annotee/executor" |
| 23 "github.com/luci/luci-go/logdog/client/bootstrapResult" | 24 "github.com/luci/luci-go/logdog/client/bootstrapResult" |
| 24 "github.com/luci/luci-go/logdog/client/butlerlib/bootstrap" | 25 "github.com/luci/luci-go/logdog/client/butlerlib/bootstrap" |
| 25 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" | 26 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" |
| 26 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" | 27 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" |
| 27 "github.com/luci/luci-go/logdog/common/types" | 28 "github.com/luci/luci-go/logdog/common/types" |
| 28 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
| 29 ) | 30 ) |
| 30 | 31 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 59 butlerStreamServer string | 60 butlerStreamServer string |
| 60 tee bool | 61 tee bool |
| 61 printSummary bool | 62 printSummary bool |
| 62 testingDir string | 63 testingDir string |
| 63 annotationInterval clockflag.Duration | 64 annotationInterval clockflag.Duration |
| 64 project config.ProjectName | 65 project config.ProjectName |
| 65 nameBase streamproto.StreamNameFlag | 66 nameBase streamproto.StreamNameFlag |
| 66 prefix streamproto.StreamNameFlag | 67 prefix streamproto.StreamNameFlag |
| 67 logdogHost string | 68 logdogHost string |
| 68 | 69 |
| 70 prof profiling.Profiler |
| 71 |
| 69 bootstrap *bootstrap.Bootstrap | 72 bootstrap *bootstrap.Bootstrap |
| 70 } | 73 } |
| 71 | 74 |
| 72 func (a *application) addToFlagSet(fs *flag.FlagSet) { | 75 func (a *application) addToFlagSet(fs *flag.FlagSet) { |
| 73 fs.Var(&a.annotate, "annotate", | 76 fs.Var(&a.annotate, "annotate", |
| 74 "Annotation handling mode. Options are: "+annotationFlagEnum.Cho
ices()) | 77 "Annotation handling mode. Options are: "+annotationFlagEnum.Cho
ices()) |
| 75 fs.StringVar(&a.resultPath, "result-path", "", | 78 fs.StringVar(&a.resultPath, "result-path", "", |
| 76 "If supplied, a JSON file describing the bootstrap result will b
e written here if the bootstrapped process "+ | 79 "If supplied, a JSON file describing the bootstrap result will b
e written here if the bootstrapped process "+ |
| 77 "is successfully executed.") | 80 "is successfully executed.") |
| 78 fs.StringVar(&a.jsonArgsPath, "json-args-path", "", | 81 fs.StringVar(&a.jsonArgsPath, "json-args-path", "", |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 156 |
| 154 // Determine bootstrapped process arguments. | 157 // Determine bootstrapped process arguments. |
| 155 var err error | 158 var err error |
| 156 a.bootstrap, err = bootstrap.Get() | 159 a.bootstrap, err = bootstrap.Get() |
| 157 if err != nil { | 160 if err != nil { |
| 158 log.WithError(err).Warningf(a, "Could not get LogDog Butler boot
strap information.") | 161 log.WithError(err).Warningf(a, "Could not get LogDog Butler boot
strap information.") |
| 159 } | 162 } |
| 160 | 163 |
| 161 fs := &flag.FlagSet{} | 164 fs := &flag.FlagSet{} |
| 162 logFlags.AddFlags(fs) | 165 logFlags.AddFlags(fs) |
| 166 a.prof.AddFlags(fs) |
| 163 a.addToFlagSet(fs) | 167 a.addToFlagSet(fs) |
| 164 if err := fs.Parse(args); err != nil { | 168 if err := fs.Parse(args); err != nil { |
| 165 log.WithError(err).Errorf(a, "Failed to parse flags.") | 169 log.WithError(err).Errorf(a, "Failed to parse flags.") |
| 166 return configErrorReturnCode | 170 return configErrorReturnCode |
| 167 } | 171 } |
| 168 a.Context = logFlags.Set(a.Context) | 172 a.Context = logFlags.Set(a.Context) |
| 169 | 173 |
| 170 client, err := a.getStreamClient() | 174 client, err := a.getStreamClient() |
| 171 if err != nil { | 175 if err != nil { |
| 172 log.WithError(err).Errorf(a, "Failed to get stream client instan
ce.") | 176 log.WithError(err).Errorf(a, "Failed to get stream client instan
ce.") |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 log.Errorf(a, "No command-line arguments were supplied.") | 214 log.Errorf(a, "No command-line arguments were supplied.") |
| 211 return configErrorReturnCode | 215 return configErrorReturnCode |
| 212 } | 216 } |
| 213 | 217 |
| 214 // Translate "<=0" flag option to Processor's "0", indicating that every | 218 // Translate "<=0" flag option to Processor's "0", indicating that every |
| 215 // update should be sent. | 219 // update should be sent. |
| 216 if a.annotationInterval < 0 { | 220 if a.annotationInterval < 0 { |
| 217 a.annotationInterval = 0 | 221 a.annotationInterval = 0 |
| 218 } | 222 } |
| 219 | 223 |
| 224 // Start our profiling service. This will be a no-op if the profiler is
not |
| 225 // configured. |
| 226 a.prof.Logger = log.Get(a) |
| 227 if err := a.prof.Start(); err != nil { |
| 228 log.WithError(err).Errorf(a, "Failed to start profiler.") |
| 229 return runtimeErrorReturnCode |
| 230 } |
| 231 |
| 220 // Initialize our link generator, if we can. | 232 // Initialize our link generator, if we can. |
| 221 e := executor.Executor{ | 233 e := executor.Executor{ |
| 222 Options: annotee.Options{ | 234 Options: annotee.Options{ |
| 223 Base: types.StreamName(a.nameBase), | 235 Base: types.StreamName(a.nameBase), |
| 224 Client: client, | 236 Client: client, |
| 225 MetadataUpdateInterval: time.Duration(a.annotationInterv
al), | 237 MetadataUpdateInterval: time.Duration(a.annotationInterv
al), |
| 226 CloseSteps: true, | 238 CloseSteps: true, |
| 227 }, | 239 }, |
| 228 | 240 |
| 229 Annotate: executor.AnnotationMode(a.annotate), | 241 Annotate: executor.AnnotationMode(a.annotate), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 284 } |
| 273 if err := a.maybeWriteResult(&br); err != nil { | 285 if err := a.maybeWriteResult(&br); err != nil { |
| 274 log.WithError(err).Warningf(a, "Failed to write bootstrap result
.") | 286 log.WithError(err).Warningf(a, "Failed to write bootstrap result
.") |
| 275 } | 287 } |
| 276 return e.ReturnCode() | 288 return e.ReturnCode() |
| 277 } | 289 } |
| 278 | 290 |
| 279 func main() { | 291 func main() { |
| 280 os.Exit(mainImpl(os.Args[1:])) | 292 os.Exit(mainImpl(os.Args[1:])) |
| 281 } | 293 } |
| OLD | NEW |