-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement stream stats Closes: #190 Signed-off-by: Gabriele Santomaggio <[email protected]> Signed-off-by: Gabriele Santomaggio <[email protected]>
- Loading branch information
1 parent
ec6e973
commit 5cadb98
Showing
7 changed files
with
211 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stream | ||
|
||
import "fmt" | ||
|
||
type StreamStats struct { | ||
stats map[string]int64 | ||
streamName string | ||
} | ||
|
||
func newStreamStats(stats map[string]int64, streamName string) *StreamStats { | ||
return &StreamStats{stats: stats, streamName: streamName} | ||
|
||
} | ||
|
||
// FirstOffset - The first offset in the stream. | ||
// return first offset in the stream / | ||
// Error if there is no first offset yet | ||
func (s *StreamStats) FirstOffset() (int64, error) { | ||
if s.stats["first_chunk_id"] == -1 { | ||
return -1, fmt.Errorf("FirstOffset not found for %s", s.streamName) | ||
} | ||
return s.stats["first_chunk_id"], nil | ||
} | ||
|
||
// LastOffset - The last offset in the stream. | ||
// return last offset in the stream | ||
// error if there is no first offset yet | ||
func (s *StreamStats) LastOffset() (int64, error) { | ||
if s.stats["last_chunk_id"] == -1 { | ||
return -1, fmt.Errorf("LastOffset not found for %s", s.streamName) | ||
} | ||
return s.stats["last_chunk_id"], nil | ||
} | ||
|
||
// CommittedChunkId - The ID (offset) of the committed chunk (block of messages) in the stream. | ||
// | ||
// It is the offset of the first message in the last chunk confirmed by a quorum of the stream | ||
// cluster members (leader and replicas). | ||
// | ||
// The committed chunk ID is a good indication of what the last offset of a stream can be at a | ||
// given time. The value can be stale as soon as the application reads it though, as the committed | ||
// chunk ID for a stream that is published to changes all the time. | ||
// | ||
// return committed offset in this stream | ||
// Error if there is no committed chunk yet | ||
func (s *StreamStats) CommittedChunkId() (int64, error) { | ||
if s.stats["committed_chunk_id"] == -1 { | ||
return -1, fmt.Errorf("CommittedChunkId not found for %s", s.streamName) | ||
} | ||
return s.stats["committed_chunk_id"], nil | ||
} |