Skip to content

Commit

Permalink
Added helper function to reader to perform a wildcard query with the …
Browse files Browse the repository at this point in the history
…max time interval.
  • Loading branch information
davidlion committed May 9, 2024
1 parent 0dd51a2 commit 49d61fb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
38 changes: 19 additions & 19 deletions ir/deserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const (
// failure to do so will result in a memory leak.
type Deserializer interface {
DeserializeLogEvent(irBuf []byte) (*ffi.LogEventView, int, error)
DeserializeWildcardMatch(
DeserializeWildcardMatchWithTimeInterval(
irBuf []byte,
timeInterval search.TimestampInterval,
mergedQuery search.MergedWildcardQuery,
timeInterval search.TimestampInterval,
) (*ffi.LogEventView, int, int, error)
TimestampInfo() TimestampInfo
Close() error
Expand Down Expand Up @@ -161,22 +161,22 @@ func (self *eightByteDeserializer) DeserializeLogEvent(
return deserializeLogEvent(self, irBuf)
}

// DeserializeWildcardMatch attempts to read the next log event from the IR
// stream in irBuf that matches mergedQuery within timeInterval. It returns the
// deserialized [ffi.LogEventView], the position read to in irBuf (the end of
// the log event in irBuf), the index of the matched query in mergedQuery,
// and an error. On error returns:
// DeserializeWildcardMatchWithTimeInterval attempts to read the next log event
// from the IR stream in irBuf that matches mergedQuery within timeInterval. It
// returns the deserialized [ffi.LogEventView], the position read to in irBuf
// (the end of the log event in irBuf), the index of the matched query in
// mergedQuery, and an error. On error returns:
// - nil *ffi.LogEventView
// - 0 position
// - -1 index
// - [IrError] error: CLP failed to successfully deserialize
// - [EndOfIr] error: CLP found the IR stream EOF tag
func (self *eightByteDeserializer) DeserializeWildcardMatch(
func (self *eightByteDeserializer) DeserializeWildcardMatchWithTimeInterval(
irBuf []byte,
timeInterval search.TimestampInterval,
mergedQuery search.MergedWildcardQuery,
timeInterval search.TimestampInterval,
) (*ffi.LogEventView, int, int, error) {
return deserializeWildcardMatch(self, irBuf, timeInterval, mergedQuery)
return deserializeWildcardMatch(self, irBuf, mergedQuery, timeInterval)
}

// fourByteDeserializer contains both a common CLP IR deserializer and stores
Expand All @@ -201,22 +201,22 @@ func (self *fourByteDeserializer) DeserializeLogEvent(
return deserializeLogEvent(self, irBuf)
}

// DeserializeWildcardMatch attempts to read the next log event from the IR
// stream in irBuf that matches mergedQuery within timeInterval. It returns the
// deserialized [ffi.LogEventView], the position read to in irBuf (the end of
// the log event in irBuf), the index of the matched query in mergedQuery,
// and an error. On error returns:
// DeserializeWildcardMatchWithTimeInterval attempts to read the next log event
// from the IR stream in irBuf that matches mergedQuery within timeInterval. It
// returns the deserialized [ffi.LogEventView], the position read to in irBuf
// (the end of the log event in irBuf), the index of the matched query in
// mergedQuery, and an error. On error returns:
// - nil *ffi.LogEventView
// - 0 position
// - -1 index
// - [IrError] error: CLP failed to successfully deserialize
// - [EndOfIr] error: CLP found the IR stream EOF tag
func (self *fourByteDeserializer) DeserializeWildcardMatch(
func (self *fourByteDeserializer) DeserializeWildcardMatchWithTimeInterval(
irBuf []byte,
timeInterval search.TimestampInterval,
mergedQuery search.MergedWildcardQuery,
timeInterval search.TimestampInterval,
) (*ffi.LogEventView, int, int, error) {
return deserializeWildcardMatch(self, irBuf, timeInterval, mergedQuery)
return deserializeWildcardMatch(self, irBuf, mergedQuery, timeInterval)
}

func deserializeLogEvent(
Expand Down Expand Up @@ -264,8 +264,8 @@ func deserializeLogEvent(
func deserializeWildcardMatch(
deserializer Deserializer,
irBuf []byte,
time search.TimestampInterval,
mergedQuery search.MergedWildcardQuery,
time search.TimestampInterval,
) (*ffi.LogEventView, int, int, error) {
if 0 >= len(irBuf) {
return nil, 0, -1, IncompleteIr
Expand Down
27 changes: 24 additions & 3 deletions ir/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ir

import (
"io"
"math"
"strings"

"github.com/y-scope/clp-ffi-go/ffi"
Expand Down Expand Up @@ -86,20 +87,40 @@ func (self *Reader) Read() (*ffi.LogEventView, error) {
return event, nil
}

// ReadToWildcardMatch wraps ReadToWildcardMatchWithTimeInterval, attempting to
// read the next log event that matches any query in queries, within the entire
// IR. It forwards the result of ReadToWildcardMatchWithTimeInterval.
func (self *Reader) ReadToWildcardMatch(
timeInterval search.TimestampInterval,
queries []search.WildcardQuery,
) (*ffi.LogEventView, int, error) {
return self.ReadToWildcardMatchWithTimeInterval(
queries,
search.TimestampInterval{0, math.MaxInt64},
)
}

// ReadToWildcardMatchWithTimeInterval attempts to read the next log event that
// matches any query in queries, within timeInterval. It returns the
// deserialized [ffi.LogEventView], the index of the matched query in queries,
// and an error. On error returns:
// - nil *ffi.LogEventView
// - -1 index
// - [IrError] error: CLP failed to successfully deserialize
// - [EndOfIr] error: CLP found the IR stream EOF tag
func (self *Reader) ReadToWildcardMatchWithTimeInterval(
queries []search.WildcardQuery,
timeInterval search.TimestampInterval,
) (*ffi.LogEventView, int, error) {
var event *ffi.LogEventView
var pos int
var matchingQuery int
var err error
mergedQuery := search.MergeWildcardQueries(queries)
for {
event, pos, matchingQuery, err = self.DeserializeWildcardMatch(
event, pos, matchingQuery, err = self.DeserializeWildcardMatchWithTimeInterval(
self.buf[self.start:self.end],
timeInterval,
mergedQuery,
timeInterval,
)
if IncompleteIr != err {
break
Expand Down
4 changes: 2 additions & 2 deletions ir/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestIrReader(t *testing.T) {
// log, err = irr.Read()
// log, err = irr.ReadToContains("ERROR")
// var _ search.WildcardQuery
log, _, err = irr.ReadToWildcardMatch(
interval,
log, _, err = irr.ReadToWildcardMatchWithTimeInterval(
queries,
interval,
)
if nil != err {
break
Expand Down

0 comments on commit 49d61fb

Please sign in to comment.