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

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: 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..6a891217e2caefddaf1a7504f036c0bec4914db7
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/bundler.go
@@ -0,0 +1,62 @@
+// 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 {
+ // Sizer is the Sizer instance to use to help with Bundler accounting.
tandrii(chromium) 2015/08/11 14:06:07 start comment with func name "// NewSizer
dnj (Google) 2015/08/11 16:24:00 Done.
+ // 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() int
tandrii(chromium) 2015/08/11 14:06:07 is int enough? maybe int64?
dnj (Google) 2015/08/11 16:24:00 Int should be enough, since in practice the size c
+
+ // AppendBundleEntry adds a ButlerLogBundle_Entry to the Sizer and returns
+ // its calculated size.
+ AppendBundleEntry(*protocol.ButlerLogBundle_Entry)
tandrii(chromium) 2015/08/11 14:06:07 this doesn't return
dnj (Google) 2015/08/11 16:24:01 It sure doesn't. Done.
+
+ // AppendLogEntry adds a LogEntry to the Sizer and returns its calculated
+ // size.
+ AppendLogEntry(*protocol.ButlerLogBundle_Entry, *protocol.LogEntry)
tandrii(chromium) 2015/08/11 14:06:07 this doesn't return
dnj (Google) 2015/08/11 16:24:01 Acknowledged.
+}
+
+// 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.
+ Append(*protocol.ButlerLogBundle_Entry)
+
+ // Bundle converts the current set of buffered log data into a series of
tandrii(chromium) 2015/08/11 14:06:07 nit: s/Bundle/GetBundles
dnj (Google) 2015/08/11 16:24:00 Done.
+ // ButlerLogBundle instances. Afterwards, the Bundler will no longer contain
+ // any buffered data.
+ //
+ // If the supplied threshold value is greater than zero, the returned bundle
+ // will only contain enough log messages such that its serialized protobuf
+ // byte count is less or equal to the threshold.
+ //
+ // Bundle may return nil if the Bundler has no accumulated data.
+ GetBundles(int) []*protocol.ButlerLogBundle
+
+ // Size returns the Bundler's current size.
+ Size() int
+
+ // Empty returns true if the Bundler has no buffered log data.
+ Empty() bool
+}

Powered by Google App Engine
This is Rietveld 408576698