| 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 bundler | 5 package bundler |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "container/heap" | 8 "container/heap" |
| 9 "fmt" | 9 "fmt" |
| 10 "sync" | 10 "sync" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/luci/luci-go/client/logdog/butlerlib/streamproto" | 13 "github.com/luci/luci-go/client/logdog/butlerlib/streamproto" |
| 14 "github.com/luci/luci-go/common/cancelcond" | 14 "github.com/luci/luci-go/common/cancelcond" |
| 15 "github.com/luci/luci-go/common/clock" | 15 "github.com/luci/luci-go/common/clock" |
| 16 "github.com/luci/luci-go/common/config" | 16 "github.com/luci/luci-go/common/config" |
| 17 "github.com/luci/luci-go/common/logdog/types" | 17 "github.com/luci/luci-go/common/logdog/types" |
| 18 "github.com/luci/luci-go/common/proto/google" | 18 "github.com/luci/luci-go/common/proto/google" |
| 19 "github.com/luci/luci-go/common/proto/logdog/logpb" | 19 "github.com/luci/luci-go/common/proto/logdog/logpb" |
| 20 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| 21 ) | 21 ) |
| 22 | 22 |
| 23 // Config is the Bundler configuration. | 23 // Config is the Bundler configuration. |
| 24 type Config struct { | 24 type Config struct { |
| 25 // Clock is the clock instance that will be used for Bundler and stream | 25 // Clock is the clock instance that will be used for Bundler and stream |
| 26 // timing. | 26 // timing. |
| 27 Clock clock.Clock | 27 Clock clock.Clock |
| 28 | 28 |
| 29 // Source is the bundle source string to use. This can be empty if there
is no | |
| 30 // source information to include. | |
| 31 Source string | |
| 32 | |
| 33 // Project is the project to use. | 29 // Project is the project to use. |
| 34 Project config.ProjectName | 30 Project config.ProjectName |
| 35 // Prefix is the common prefix for this set of streams. | 31 // Prefix is the common prefix for this set of streams. |
| 36 Prefix types.StreamName | 32 Prefix types.StreamName |
| 37 // Secret is the prefix secret for this set of streams. | 33 // Secret is the prefix secret for this set of streams. |
| 38 Secret []byte | 34 Secret []byte |
| 39 | 35 |
| 40 // MaxBufferedBytes is the maximum number of bytes to buffer in memory p
er | 36 // MaxBufferedBytes is the maximum number of bytes to buffer in memory p
er |
| 41 // stream. | 37 // stream. |
| 42 MaxBufferedBytes int64 | 38 MaxBufferedBytes int64 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 defer func() { | 182 defer func() { |
| 187 if bb != nil && bb.hasContent() { | 183 if bb != nil && bb.hasContent() { |
| 188 b.bundleC <- bb.bundle() | 184 b.bundleC <- bb.bundle() |
| 189 } | 185 } |
| 190 }() | 186 }() |
| 191 | 187 |
| 192 for { | 188 for { |
| 193 bb = &builder{ | 189 bb = &builder{ |
| 194 size: b.c.MaxBundleSize, | 190 size: b.c.MaxBundleSize, |
| 195 template: logpb.ButlerLogBundle{ | 191 template: logpb.ButlerLogBundle{ |
| 196 Source: b.c.Source, | |
| 197 Timestamp: google.NewTimestamp(b.getClock().Now(
)), | 192 Timestamp: google.NewTimestamp(b.getClock().Now(
)), |
| 198 Project: string(b.c.Project), | 193 Project: string(b.c.Project), |
| 199 Prefix: string(b.c.Prefix), | 194 Prefix: string(b.c.Prefix), |
| 200 Secret: b.c.Secret, | 195 Secret: b.c.Secret, |
| 201 }, | 196 }, |
| 202 } | 197 } |
| 203 var oldestContentTime time.Time | 198 var oldestContentTime time.Time |
| 204 | 199 |
| 205 for { | 200 for { |
| 206 state := b.getStreamStateLocked() | 201 state := b.getStreamStateLocked() |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 493 |
| 499 func (s *streamState) Push(x interface{}) { | 494 func (s *streamState) Push(x interface{}) { |
| 500 s.streams = append(s.streams, x.(bundlerStream)) | 495 s.streams = append(s.streams, x.(bundlerStream)) |
| 501 } | 496 } |
| 502 | 497 |
| 503 func (s *streamState) Pop() interface{} { | 498 func (s *streamState) Pop() interface{} { |
| 504 last := s.streams[len(s.streams)-1] | 499 last := s.streams[len(s.streams)-1] |
| 505 s.streams = s.streams[:len(s.streams)-1] | 500 s.streams = s.streams[:len(s.streams)-1] |
| 506 return last | 501 return last |
| 507 } | 502 } |
| OLD | NEW |