| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package butler | 5 package butler |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "io" | 10 "io" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // Output is the output instance to use for log dispatch. | 45 // Output is the output instance to use for log dispatch. |
| 46 Output output.Output | 46 Output output.Output |
| 47 // OutputWorkers is the number of simultaneous goroutines that will be u
sed | 47 // OutputWorkers is the number of simultaneous goroutines that will be u
sed |
| 48 // to output Butler log data. If zero, DefaultOutputWorkers will be used
. | 48 // to output Butler log data. If zero, DefaultOutputWorkers will be used
. |
| 49 OutputWorkers int | 49 OutputWorkers int |
| 50 | 50 |
| 51 // Project is the project that the log stream will be bound to. | 51 // Project is the project that the log stream will be bound to. |
| 52 Project config.ProjectName | 52 Project config.ProjectName |
| 53 // Prefix is the log stream common prefix value. | 53 // Prefix is the log stream common prefix value. |
| 54 Prefix types.StreamName | 54 Prefix types.StreamName |
| 55 // Secret is the prefix secret that will be used for streams generated b
y this | |
| 56 // Butler. | |
| 57 Secret types.PrefixSecret | |
| 58 | 55 |
| 59 // BufferLogs, if true, instructs the butler to buffer collected log dat
a | 56 // BufferLogs, if true, instructs the butler to buffer collected log dat
a |
| 60 // before sending it to Output. | 57 // before sending it to Output. |
| 61 BufferLogs bool | 58 BufferLogs bool |
| 62 // If buffering logs, this is the maximum amount of time that a log will | 59 // If buffering logs, this is the maximum amount of time that a log will |
| 63 // be buffered before being marked for dispatch. If this is zero, | 60 // be buffered before being marked for dispatch. If this is zero, |
| 64 // DefaultMaxBufferAge will be used. | 61 // DefaultMaxBufferAge will be used. |
| 65 MaxBufferAge time.Duration | 62 MaxBufferAge time.Duration |
| 66 | 63 |
| 67 // TeeStdout, if not nil, is the Writer that will be used for streams | 64 // TeeStdout, if not nil, is the Writer that will be used for streams |
| (...skipping 13 matching lines...) Expand all Loading... |
| 81 // TODO(dnj): Empty project should not validate here once projects are | 78 // TODO(dnj): Empty project should not validate here once projects are |
| 82 // mandatory. | 79 // mandatory. |
| 83 if c.Project != "" { | 80 if c.Project != "" { |
| 84 if err := c.Project.Validate(); err != nil { | 81 if err := c.Project.Validate(); err != nil { |
| 85 return fmt.Errorf("invalid project: %v", err) | 82 return fmt.Errorf("invalid project: %v", err) |
| 86 } | 83 } |
| 87 } | 84 } |
| 88 if err := c.Prefix.Validate(); err != nil { | 85 if err := c.Prefix.Validate(); err != nil { |
| 89 return fmt.Errorf("invalid prefix: %v", err) | 86 return fmt.Errorf("invalid prefix: %v", err) |
| 90 } | 87 } |
| 91 if err := c.Secret.Validate(); err != nil { | |
| 92 return fmt.Errorf("invalid secret: %v", err) | |
| 93 } | |
| 94 return nil | 88 return nil |
| 95 } | 89 } |
| 96 | 90 |
| 97 // Butler is the Butler application structure. The Butler runs until closed. | 91 // Butler is the Butler application structure. The Butler runs until closed. |
| 98 // During operation, it acts as a service manager and data router, routing: | 92 // During operation, it acts as a service manager and data router, routing: |
| 99 // - Messages from Streams to the attached Output. | 93 // - Messages from Streams to the attached Output. |
| 100 // - Streams from a StreamServer to the Stream list (AddStream). | 94 // - Streams from a StreamServer to the Stream list (AddStream). |
| 101 type Butler struct { | 95 type Butler struct { |
| 102 c *Config | 96 c *Config |
| 103 ctx context.Context | 97 ctx context.Context |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 141 } |
| 148 | 142 |
| 149 if config.OutputWorkers <= 0 { | 143 if config.OutputWorkers <= 0 { |
| 150 config.OutputWorkers = DefaultOutputWorkers | 144 config.OutputWorkers = DefaultOutputWorkers |
| 151 } | 145 } |
| 152 | 146 |
| 153 bc := bundler.Config{ | 147 bc := bundler.Config{ |
| 154 Clock: clock.Get(ctx), | 148 Clock: clock.Get(ctx), |
| 155 Project: config.Project, | 149 Project: config.Project, |
| 156 Prefix: config.Prefix, | 150 Prefix: config.Prefix, |
| 157 Secret: config.Secret, | |
| 158 MaxBufferedBytes: streamBufferSize, | 151 MaxBufferedBytes: streamBufferSize, |
| 159 MaxBundleSize: config.Output.MaxSize(), | 152 MaxBundleSize: config.Output.MaxSize(), |
| 160 } | 153 } |
| 161 if config.BufferLogs { | 154 if config.BufferLogs { |
| 162 bc.MaxBufferDelay = config.MaxBufferAge | 155 bc.MaxBufferDelay = config.MaxBufferAge |
| 163 } | 156 } |
| 164 lb := bundler.New(bc) | 157 lb := bundler.New(bc) |
| 165 | 158 |
| 166 b := &Butler{ | 159 b := &Butler{ |
| 167 c: &config, | 160 c: &config, |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // shutdown prematurely, so this should be reasonably quick. | 545 // shutdown prematurely, so this should be reasonably quick. |
| 553 b.Activate() | 546 b.Activate() |
| 554 } | 547 } |
| 555 | 548 |
| 556 // Returns the configured Butler error. | 549 // Returns the configured Butler error. |
| 557 func (b *Butler) getRunErr() error { | 550 func (b *Butler) getRunErr() error { |
| 558 b.shutdownMu.Lock() | 551 b.shutdownMu.Lock() |
| 559 defer b.shutdownMu.Unlock() | 552 defer b.shutdownMu.Unlock() |
| 560 return b.runErr | 553 return b.runErr |
| 561 } | 554 } |
| OLD | NEW |