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

Side by Side Diff: client/internal/logdog/butler/output/output.go

Issue 1211053004: LogDog: Add Butler Output package. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Relocate butlerproto to common, document. Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(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 output
6
7 import (
8 "fmt"
9
10 "github.com/luci/luci-go/common/logdog/protocol"
11 )
12
13 // Output is a sink endpoint for groups of messages.
14 //
15 // An Output's methods must be goroutine-safe.
16 //
17 // Note that there is no guarantee that any of the bundles passed through an
18 // Output are ordered.
19 type Output interface {
20 // SendBundle sends a constructed ButlerLogBundle through the Output.
21 //
22 // If an error is returned, it indicates a failure to send the bundle.
23 // If there is a data error or a message type is not supported by the
24 // Output, it should log the error and return nil.
25 SendBundle(*protocol.ButlerLogBundle) error
26
27 // MaxSize returns the maximum number of bytes that this Output can proc ess
28 // with a single send. A return value <=0 indicates that there si no fix ed
29 // maximum size for this Output.
30 //
31 // Since it is impossible for callers to know the actual size of the mes sage
32 // that is being submitted, and since message batching may cluster acros s
33 // size boundaries, this should be a conservative estimate.
34 MaxSize() int
35
36 // Collect current Output stats.
37 Stats() Stats
38
39 // Close closes the Output, blocking until any buffered actions are flus hed.
40 Close()
41 }
42
43 // Stats is an interface to query Output statistics.
44 //
45 // An Output's ability to keep statistics varies with its implementation
46 // details. Currently, Stats are for debugging/information purposes only.
47 type Stats interface {
48 fmt.Stringer
49
50 // SentBytes returns the number of bytes
51 SentBytes() int
52 // SentMessages returns the number of successfully transmitted messages.
53 SentMessages() int
54 // DiscardedMessages returns the number of discarded messages.
55 DiscardedMessages() int
56 // Errors returns the number of errors encountered during operation.
57 Errors() int
58 }
59
60 // StatsBase is a simple implementation of the Stats interface.
61 type StatsBase struct {
62 F struct {
63 SentBytes int // The number of bytes sent.
64 SentMessages int // The number of messages sent.
65 DiscardedMessages int // The number of messages that have been d iscarded.
66 Errors int // The number of errors encountered.
67 }
68 }
69
70 var _ Stats = (*StatsBase)(nil)
71
72 func (s *StatsBase) String() string {
73 return fmt.Sprintf("%+v", s.F)
74 }
75
76 // SentBytes implements Stas.
77 func (s *StatsBase) SentBytes() int {
78 return s.F.SentBytes
79 }
80
81 // SentMessages implements Stas.
82 func (s *StatsBase) SentMessages() int {
83 return s.F.SentMessages
84 }
85
86 // DiscardedMessages implements Stas.
87 func (s *StatsBase) DiscardedMessages() int {
88 return s.F.DiscardedMessages
89 }
90
91 // Errors implements Stas.
92 func (s *StatsBase) Errors() int {
93 return s.F.Errors
94 }
95
96 // Merge merges the values from one Stats block into another.
97 func (s *StatsBase) Merge(o Stats) {
98 s.F.SentBytes += o.SentBytes()
99 s.F.SentMessages += o.SentMessages()
100 s.F.DiscardedMessages += o.DiscardedMessages()
101 s.F.Errors += o.Errors()
102 }
OLDNEW
« no previous file with comments | « client/internal/logdog/butler/output/log/logOutput.go ('k') | client/internal/logdog/butler/output/pubsub/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698