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

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: Rewrote bundle logic (and associated updates). 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
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..0fab318d2884a24fadc779b1e0e8c9fd796e66db
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/bundler.go
@@ -0,0 +1,78 @@
+// 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
+
+ // NewSizer is the Sizer instance to use to help with Bundler accounting.
+ // If nil, a FastSizer will be used.
+ NewSizer func(*protocol.ButlerLogBundle) Sizer
+}
+
+// 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.
iannucci 2015/09/01 03:03:21 reverses? Can it be called more than once?
dnj 2015/09/02 01:58:14 Nope.
+ 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
+}

Powered by Google App Engine
This is Rietveld 408576698