| 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 "bytes" | 8 "bytes" |
| 9 "flag" | 9 "flag" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 "github.com/luci/luci-go/common/config" | 25 "github.com/luci/luci-go/common/config" |
| 26 "github.com/luci/luci-go/common/errors" | 26 "github.com/luci/luci-go/common/errors" |
| 27 "github.com/luci/luci-go/common/flag/multiflag" | 27 "github.com/luci/luci-go/common/flag/multiflag" |
| 28 log "github.com/luci/luci-go/common/logging" | 28 log "github.com/luci/luci-go/common/logging" |
| 29 "github.com/luci/luci-go/common/logging/gologger" | 29 "github.com/luci/luci-go/common/logging/gologger" |
| 30 "github.com/luci/luci-go/common/runtime/paniccatcher" | 30 "github.com/luci/luci-go/common/runtime/paniccatcher" |
| 31 "github.com/luci/luci-go/common/runtime/profiling" | 31 "github.com/luci/luci-go/common/runtime/profiling" |
| 32 grpcLogging "github.com/luci/luci-go/grpc/logging" | 32 grpcLogging "github.com/luci/luci-go/grpc/logging" |
| 33 "github.com/luci/luci-go/logdog/client/butler" | 33 "github.com/luci/luci-go/logdog/client/butler" |
| 34 "github.com/luci/luci-go/logdog/client/butler/output" | 34 "github.com/luci/luci-go/logdog/client/butler/output" |
| 35 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" |
| 35 "github.com/luci/luci-go/logdog/common/types" | 36 "github.com/luci/luci-go/logdog/common/types" |
| 36 ) | 37 ) |
| 37 | 38 |
| 38 const ( | 39 const ( |
| 39 // flagErrorReturnCode is returned when there is an error with the Butle
r's | 40 // flagErrorReturnCode is returned when there is an error with the Butle
r's |
| 40 // command-line configuration. | 41 // command-line configuration. |
| 41 configErrorReturnCode = 2 | 42 configErrorReturnCode = 2 |
| 42 | 43 |
| 43 // runtimeErrorReturnCode is returned when the execution fails due to a
Butler | 44 // runtimeErrorReturnCode is returned when the execution fails due to a
Butler |
| 44 // error. This is intended to help differentiate Butler errors from | 45 // error. This is intended to help differentiate Butler errors from |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 | 59 |
| 59 project config.ProjectName | 60 project config.ProjectName |
| 60 prefix types.StreamName | 61 prefix types.StreamName |
| 61 coordinatorHost string | 62 coordinatorHost string |
| 62 outputWorkers int | 63 outputWorkers int |
| 63 outputConfig outputConfigFlag | 64 outputConfig outputConfigFlag |
| 64 ioKeepAliveInterval clockflag.Duration | 65 ioKeepAliveInterval clockflag.Duration |
| 65 | 66 |
| 66 authFlags authcli.Flags | 67 authFlags authcli.Flags |
| 67 | 68 |
| 69 globalTags streamproto.TagMap |
| 68 maxBufferAge clockflag.Duration | 70 maxBufferAge clockflag.Duration |
| 69 noBufferLogs bool | 71 noBufferLogs bool |
| 70 | 72 |
| 71 prof profiling.Profiler | 73 prof profiling.Profiler |
| 72 | 74 |
| 73 client *http.Client | 75 client *http.Client |
| 74 | 76 |
| 75 // ncCtx is a context that will not be cancelled when cancelFunc is call
ed. | 77 // ncCtx is a context that will not be cancelled when cancelFunc is call
ed. |
| 76 ncCtx context.Context | 78 ncCtx context.Context |
| 77 cancelFunc func() | 79 cancelFunc func() |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 fs.Var(&a.project, "project", | 96 fs.Var(&a.project, "project", |
| 95 "The log prefix's project name (required).") | 97 "The log prefix's project name (required).") |
| 96 fs.Var(&a.prefix, "prefix", | 98 fs.Var(&a.prefix, "prefix", |
| 97 "Prefix to apply to all stream names.") | 99 "Prefix to apply to all stream names.") |
| 98 fs.StringVar(&a.coordinatorHost, "coordinator-host", "", | 100 fs.StringVar(&a.coordinatorHost, "coordinator-host", "", |
| 99 "The Coordinator host to pass on to subprocesses.") | 101 "The Coordinator host to pass on to subprocesses.") |
| 100 fs.Var(&a.outputConfig, "output", | 102 fs.Var(&a.outputConfig, "output", |
| 101 "The output name and configuration. Specify 'help' for more info
rmation.") | 103 "The output name and configuration. Specify 'help' for more info
rmation.") |
| 102 fs.IntVar(&a.outputWorkers, "output-workers", butler.DefaultOutputWorker
s, | 104 fs.IntVar(&a.outputWorkers, "output-workers", butler.DefaultOutputWorker
s, |
| 103 "The maximum number of parallel output dispatches.") | 105 "The maximum number of parallel output dispatches.") |
| 106 fs.Var(&a.globalTags, "tag", |
| 107 "Specify key[=value] tags to be applied to all log streams. Indi
vidual treams may override. Can "+ |
| 108 "be specified multiple times.") |
| 104 fs.Var(&a.maxBufferAge, "output-max-buffer-age", | 109 fs.Var(&a.maxBufferAge, "output-max-buffer-age", |
| 105 "Send buffered messages if they've been held for longer than thi
s period.") | 110 "Send buffered messages if they've been held for longer than thi
s period.") |
| 106 fs.BoolVar(&a.noBufferLogs, "output-no-buffer", false, | 111 fs.BoolVar(&a.noBufferLogs, "output-no-buffer", false, |
| 107 "If true, dispatch logs immediately. Setting this flag simplifie
s output at the expense "+ | 112 "If true, dispatch logs immediately. Setting this flag simplifie
s output at the expense "+ |
| 108 "of wire-format efficiency.") | 113 "of wire-format efficiency.") |
| 109 fs.Var(&a.ioKeepAliveInterval, "io-keepalive-stderr", | 114 fs.Var(&a.ioKeepAliveInterval, "io-keepalive-stderr", |
| 110 "If supplied, periodically write messages to STDERR if data is r
eceived on any Butler stream.") | 115 "If supplied, periodically write messages to STDERR if data is r
eceived on any Butler stream.") |
| 111 } | 116 } |
| 112 | 117 |
| 113 func (a *application) authenticator(ctx context.Context) (*auth.Authenticator, e
rror) { | 118 func (a *application) authenticator(ctx context.Context) (*auth.Authenticator, e
rror) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 135 a.prof.Logger = log.Get(a) | 140 a.prof.Logger = log.Get(a) |
| 136 if err := a.prof.Start(); err != nil { | 141 if err := a.prof.Start(); err != nil { |
| 137 return fmt.Errorf("failed to start Profiler: %v", err) | 142 return fmt.Errorf("failed to start Profiler: %v", err) |
| 138 } | 143 } |
| 139 defer a.prof.Stop() | 144 defer a.prof.Stop() |
| 140 | 145 |
| 141 // Instantiate our Butler. | 146 // Instantiate our Butler. |
| 142 butlerOpts := butler.Config{ | 147 butlerOpts := butler.Config{ |
| 143 Project: a.project, | 148 Project: a.project, |
| 144 Prefix: a.prefix, | 149 Prefix: a.prefix, |
| 150 GlobalTags: a.globalTags, |
| 145 MaxBufferAge: time.Duration(a.maxBufferAge), | 151 MaxBufferAge: time.Duration(a.maxBufferAge), |
| 146 BufferLogs: !a.noBufferLogs, | 152 BufferLogs: !a.noBufferLogs, |
| 147 Output: out, | 153 Output: out, |
| 148 OutputWorkers: a.outputWorkers, | 154 OutputWorkers: a.outputWorkers, |
| 149 TeeStdout: os.Stdout, | 155 TeeStdout: os.Stdout, |
| 150 TeeStderr: os.Stderr, | 156 TeeStderr: os.Stderr, |
| 151 IOKeepAliveInterval: time.Duration(a.ioKeepAliveInterval), | 157 IOKeepAliveInterval: time.Duration(a.ioKeepAliveInterval), |
| 152 IOKeepAliveWriter: os.Stderr, | 158 IOKeepAliveWriter: os.Stderr, |
| 153 } | 159 } |
| 154 b, err := butler.New(a, butlerOpts) | 160 b, err := butler.New(a, butlerOpts) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 349 |
| 344 paniccatcher.Do(func() { | 350 paniccatcher.Do(func() { |
| 345 rc = mainImpl(ctx, os.Args[1:]) | 351 rc = mainImpl(ctx, os.Args[1:]) |
| 346 }, func(p *paniccatcher.Panic) { | 352 }, func(p *paniccatcher.Panic) { |
| 347 log.Fields{ | 353 log.Fields{ |
| 348 "panic.error": p.Reason, | 354 "panic.error": p.Reason, |
| 349 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) | 355 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) |
| 350 rc = runtimeErrorReturnCode | 356 rc = runtimeErrorReturnCode |
| 351 }) | 357 }) |
| 352 } | 358 } |
| OLD | NEW |