Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package bundler | |
|
tandrii(chromium)
2015/08/11 17:32:22
I guess this CL introduces this package. If so, it
dnj
2015/08/11 18:14:28
Done.
| |
| 6 | |
| 7 import ( | |
| 8 "github.com/luci/luci-go/common/logdog/protocol" | |
| 9 ) | |
| 10 | |
| 11 // Config contains configuration information for a Bundler instance. | |
| 12 type Config struct { | |
| 13 // TemplateBundle is the base template ButlerLogBundle. Generated bundle s | |
| 14 // will be derived from a copy of this bundle. | |
| 15 // | |
| 16 // The TemplateBundle may not have any log entries. If it does, they wil l | |
| 17 // not be retained. | |
| 18 TemplateBundle protocol.ButlerLogBundle | |
| 19 | |
| 20 // NewSizer is the Sizer instance to use to help with Bundler accounting . | |
| 21 // If nil, a FastSizer will be used. | |
| 22 NewSizer func(*protocol.ButlerLogBundle) Sizer | |
| 23 } | |
| 24 | |
| 25 // Sizer is a stateful instance that tracks the size of LogDog ButlerLogBundle | |
| 26 // protobufs as they are constructed. | |
| 27 // | |
| 28 // A Sizer may overestimate the size, but it should strive to never | |
| 29 // underestimate the size. | |
| 30 type Sizer interface { | |
| 31 // Size returns the current size. | |
| 32 Size() int64 | |
| 33 | |
| 34 // AppendBundleEntry adds a ButlerLogBundle_Entry to the Sizer. | |
| 35 AppendBundleEntry(*protocol.ButlerLogBundle_Entry) | |
| 36 | |
| 37 // AppendLogEntry adds a LogEntry to the Sizer. | |
| 38 AppendLogEntry(*protocol.ButlerLogBundle_Entry, *protocol.LogEntry) | |
| 39 } | |
| 40 | |
| 41 // Bundler aggregates multiple Butler log bundle entries together into a single | |
| 42 // log bundle. A Bundler is not goroutine-safe. | |
| 43 // | |
| 44 // A Bundler can vet incoming data, rejecting it if its serialized protobuf | |
| 45 // exceeds a size threshold. For efficiency, the Bundler performs a conservative | |
| 46 // estimate of the sizes. | |
| 47 type Bundler interface { | |
| 48 // Append adds a single stream's bundle entry to the Bundler. | |
| 49 // | |
| 50 // The Bundler formally takes ownership of this entry and its fields | |
| 51 // (including its logs). The caller must not modify it after Append(). | |
| 52 Append(*protocol.ButlerLogBundle_Entry) | |
| 53 | |
| 54 // GetBundle converts the current set of buffered log data into a series of | |
| 55 // ButlerLogBundle instances. | |
| 56 // | |
| 57 // If the supplied threshold value is greater than zero, each returned b undle | |
| 58 // will only contain enough log messages such that its serialized protob uf | |
| 59 // byte count is less or equal to the threshold. | |
| 60 // | |
| 61 // Note: It may seem useful to have a single-bundle return function. How ever, | |
| 62 // in practice, the Bundler is used by the Butler to extract all bundles . | |
| 63 // Implementing the single-bundle use case would result in a lot of | |
| 64 // unnecessary intermediate size computations. | |
|
tandrii(chromium)
2015/08/11 17:32:22
agree
| |
| 65 // | |
| 66 // Bundle may return nil if the Bundler has no accumulated data. | |
| 67 GetBundles(int64) []*protocol.ButlerLogBundle | |
| 68 | |
| 69 // Size returns the Bundler's current size. | |
| 70 Size() int64 | |
| 71 | |
| 72 // Empty returns true if the Bundler has no buffered log data. | |
| 73 Empty() bool | |
| 74 } | |
| OLD | NEW |