| 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 annotee | 5 package annotee |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bufio" | 8 "bufio" |
| 9 "bytes" | 9 "bytes" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // DefaultBufferSize is the Stream BufferSize value that will be used if
no | 30 // DefaultBufferSize is the Stream BufferSize value that will be used if
no |
| 31 // buffer size is provided. | 31 // buffer size is provided. |
| 32 DefaultBufferSize = 8192 | 32 DefaultBufferSize = 8192 |
| 33 ) | 33 ) |
| 34 | 34 |
| 35 const ( | 35 const ( |
| 36 // STDOUT is the system STDOUT stream name. | 36 // STDOUT is the system STDOUT stream name. |
| 37 STDOUT = types.StreamName("stdout") | 37 STDOUT = types.StreamName("stdout") |
| 38 // STDERR is the system STDERR stream. | 38 // STDERR is the system STDERR stream. |
| 39 STDERR = types.StreamName("stderr") | 39 STDERR = types.StreamName("stderr") |
| 40 |
| 41 // DefaultAnnotationSubpath is the default annotation subpath. It will b
e used |
| 42 // if an explicit subpath is not provided. |
| 43 DefaultAnnotationSubpath = types.StreamName("annotations") |
| 40 ) | 44 ) |
| 41 | 45 |
| 42 // Stream describes a single process stream. | 46 // Stream describes a single process stream. |
| 43 type Stream struct { | 47 type Stream struct { |
| 44 // Reader is the stream data reader. It will be processed until it retur
ns | 48 // Reader is the stream data reader. It will be processed until it retur
ns |
| 45 // an error or io.EOF. | 49 // an error or io.EOF. |
| 46 Reader io.Reader | 50 Reader io.Reader |
| 47 // Name is the logdog stream name. | 51 // Name is the logdog stream name. |
| 48 Name types.StreamName | 52 Name types.StreamName |
| 49 // Tee, if not nil, is a writer where all consumed stream data should be | 53 // Tee, if not nil, is a writer where all consumed stream data should be |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 // | 81 // |
| 78 // If no link could be generated, GetLink may return an empty string. | 82 // If no link could be generated, GetLink may return an empty string. |
| 79 GetLink(name ...types.StreamName) string | 83 GetLink(name ...types.StreamName) string |
| 80 } | 84 } |
| 81 | 85 |
| 82 // Options are the configuration options for a Processor. | 86 // Options are the configuration options for a Processor. |
| 83 type Options struct { | 87 type Options struct { |
| 84 // Base is the base log stream name. This is prepended to every log name
, as | 88 // Base is the base log stream name. This is prepended to every log name
, as |
| 85 // well as any generate log names. | 89 // well as any generate log names. |
| 86 Base types.StreamName | 90 Base types.StreamName |
| 91 // AnnotationSubpath is the path underneath of Base where the annotation |
| 92 // stream will be written. |
| 93 // |
| 94 // If empty, DefaultAnnotationSubpath will be used. |
| 95 AnnotationSubpath types.StreamName |
| 87 | 96 |
| 88 // LinkGenerator generates links to alias for a given log stream. | 97 // LinkGenerator generates links to alias for a given log stream. |
| 89 // | 98 // |
| 90 // If nil, no link annotations will be injected. | 99 // If nil, no link annotations will be injected. |
| 91 LinkGenerator LinkGenerator | 100 LinkGenerator LinkGenerator |
| 92 | 101 |
| 93 // Client is the LogDog Butler Client to use for stream creation. | 102 // Client is the LogDog Butler Client to use for stream creation. |
| 94 Client streamclient.Client | 103 Client streamclient.Client |
| 95 | 104 |
| 96 // Execution describes the current applicaton's execution parameters. Th
is | 105 // Execution describes the current applicaton's execution parameters. Th
is |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 173 } |
| 165 | 174 |
| 166 // initialize initializes p's annotation stream handling system. If it is called | 175 // initialize initializes p's annotation stream handling system. If it is called |
| 167 // more than once, it is a no-op. | 176 // more than once, it is a no-op. |
| 168 func (p *Processor) initialize() (err error) { | 177 func (p *Processor) initialize() (err error) { |
| 169 // If we're already initialized, do nothing. | 178 // If we're already initialized, do nothing. |
| 170 if p.annotationStream != nil { | 179 if p.annotationStream != nil { |
| 171 return nil | 180 return nil |
| 172 } | 181 } |
| 173 | 182 |
| 183 annotationPath := p.o.AnnotationSubpath |
| 184 if annotationPath == "" { |
| 185 annotationPath = DefaultAnnotationSubpath |
| 186 } |
| 187 annotationPath = p.astate.RootStep().BaseStream(annotationPath) |
| 188 |
| 174 // Create our annotation stream. | 189 // Create our annotation stream. |
| 175 » if p.annotationStream, err = p.createStream(p.astate.AnnotationStream(),
&metadataStreamArchetype); err != nil { | 190 » if p.annotationStream, err = p.createStream(annotationPath, &metadataStr
eamArchetype); err != nil { |
| 176 log.WithError(err).Errorf(p.ctx, "Failed to create annotation st
ream.") | 191 log.WithError(err).Errorf(p.ctx, "Failed to create annotation st
ream.") |
| 177 return | 192 return |
| 178 } | 193 } |
| 179 | 194 |
| 180 // Complete initialization and start our annotation meter. | 195 // Complete initialization and start our annotation meter. |
| 181 p.annotationC = make(chan annotationSignal) | 196 p.annotationC = make(chan annotationSignal) |
| 182 p.annotationFinishedC = make(chan struct{}) | 197 p.annotationFinishedC = make(chan struct{}) |
| 183 p.allEmittedStreams = map[*Stream]struct{}{} | 198 p.allEmittedStreams = map[*Stream]struct{}{} |
| 184 | 199 |
| 185 // Run our annotation meter in a separate goroutine. | 200 // Run our annotation meter in a separate goroutine. |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 return "@@@" + strings.Join(append(v, params...), "@") + "@@@" | 782 return "@@@" + strings.Join(append(v, params...), "@") + "@@@" |
| 768 } | 783 } |
| 769 | 784 |
| 770 func isContentAnnotation(a string) bool { | 785 func isContentAnnotation(a string) bool { |
| 771 // Strip out any annotation arguments. | 786 // Strip out any annotation arguments. |
| 772 if idx := strings.IndexRune(a, '@'); idx > 0 { | 787 if idx := strings.IndexRune(a, '@'); idx > 0 { |
| 773 a = a[:idx] | 788 a = a[:idx] |
| 774 } | 789 } |
| 775 return a == "STEP_LOG_LINE" | 790 return a == "STEP_LOG_LINE" |
| 776 } | 791 } |
| OLD | NEW |