Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: client/internal/logdog/butler/bundler/bundler.go

Issue 1276923003: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Updated from review. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/internal/logdog/butler/bundler/bundler_impl.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/logdog/butler/bundler/bundler.go
diff --git a/client/internal/logdog/butler/bundler/bundler.go b/client/internal/logdog/butler/bundler/bundler.go
new file mode 100644
index 0000000000000000000000000000000000000000..01e0d53f11823abc489084a7c9170598520c06e1
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/bundler.go
@@ -0,0 +1,85 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package bundler
+
+import (
+ "github.com/luci/luci-go/common/logdog/protocol"
+)
+
+// Config contains configuration information for a Bundler instance.
+type Config struct {
+ // TemplateBundle is the base template ButlerLogBundle. Generated bundles
+ // will be derived from a copy of this bundle.
+ //
+ // The TemplateBundle may not have any log entries. If it does, they will
+ // not be retained.
+ TemplateBundle protocol.ButlerLogBundle
+
+ // Threshold is the size of the LogBundle
+ Threshold int64
+
+ // Deterministic, if true, ensures that logs are bundled deterministically.
+ Deterministic bool
+
+ // NewSizer is the Sizer instance to use to help with Bundler accounting.
+ // If nil, a FastSizer will be used.
+ NewSizer func(*protocol.ButlerLogBundle) Sizer
+
+ // DropCallback, if not nil, is invoked if log entries had to be dropped. This
+ // will only occur when the entries individually violate the threshold.
+ DropCallback func(*protocol.ButlerLogBundle_Entry)
+}
+
+// Sizer is a stateful instance that tracks the size of LogDog ButlerLogBundle
+// protobufs as they are constructed.
+//
+// A Sizer may overestimate the size, but it should strive to never
+// underestimate the size.
+type Sizer interface {
+ // Size returns the current size.
+ Size() int64
+
+ // AppendBundleEntry adds a ButlerLogBundle_Entry and an optional LogEntry
+ // to the Sizer.
+ Append(*protocol.ButlerLogBundle_Entry, *protocol.LogEntry)
+
+ // Undo reversed the most recent Append.
+ Undo()
+}
+
+// Bundler aggregates multiple Butler log bundle entries together into a single
+// log bundle. A Bundler is not goroutine-safe.
+//
+// A Bundler can vet incoming data, rejecting it if its serialized protobuf
+// exceeds a size threshold. For efficiency, the Bundler performs a conservative
+// estimate of the sizes.
+type Bundler interface {
+ // Append adds a single stream's bundle entry to the Bundler.
+ //
+ // The Bundler formally takes ownership of this entry and its fields
+ // (including its logs). The caller must not modify it after Append().
+ Append(*protocol.ButlerLogBundle_Entry)
+
+ // GetBundle converts the current set of buffered log data into a series of
+ // ButlerLogBundle instances.
+ //
+ // If the supplied threshold value is greater than zero, each returned bundle
+ // will only contain enough log messages such that its serialized protobuf
+ // byte count is less or equal to the threshold.
+ //
+ // Note: It may seem useful to have a single-bundle return function. However,
+ // in practice, the Bundler is used by the Butler to extract all bundles at
+ // once. Implementing the single-bundle use case would result in a lot of
+ // unnecessary intermediate size computations.
+ //
+ // Bundle may return nil if the Bundler has no accumulated data.
+ GetBundles() []*protocol.ButlerLogBundle
+
+ // Size returns the Bundler's current size.
+ Size() int64
+
+ // Empty returns true if the Bundler has no buffered log data.
+ Empty() bool
+}
« no previous file with comments | « no previous file | client/internal/logdog/butler/bundler/bundler_impl.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698