-
Notifications
You must be signed in to change notification settings - Fork 3.7k
chore(dataobj): predicate pushdown metadata label filters #16846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fd42110
7a4a514
1233899
2de08a9
c29d168
9782d5a
8ff80af
6a07b7d
9b89c4b
31ea30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package dataobj | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type ( | ||
// Predicate is an expression used to filter entries in a data object. | ||
Predicate interface { | ||
isPredicate() | ||
String() string | ||
} | ||
|
||
// StreamsPredicate is a [Predicate] that can be used to filter streams in a | ||
|
@@ -62,13 +65,15 @@ type ( | |
// predicates. | ||
LabelFilterPredicate struct { | ||
Name string | ||
Desc string // Description of the filter for debugging. | ||
Keep func(name, value string) bool | ||
} | ||
|
||
// A LogMessageFilterPredicate is a [LogsPredicate] that requires the log message | ||
// of the entry to pass a Keep function. | ||
LogMessageFilterPredicate struct { | ||
Keep func(line []byte) bool | ||
Desc string // Description of the filter for debugging. | ||
Comment on lines
75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for consistency with the other function predicates, should Desc be before Keep here? |
||
} | ||
|
||
// A MetadataMatcherPredicate is a [LogsPredicate] that requires a metadata | ||
|
@@ -86,6 +91,7 @@ type ( | |
// predicates. | ||
MetadataFilterPredicate struct { | ||
Key string | ||
Desc string // Description of the filter for debugging. | ||
Keep func(key, value string) bool | ||
} | ||
) | ||
|
@@ -109,3 +115,107 @@ func (LabelFilterPredicate) predicateKind(StreamsPredicate) {} | |
func (MetadataMatcherPredicate) predicateKind(LogsPredicate) {} | ||
func (MetadataFilterPredicate) predicateKind(LogsPredicate) {} | ||
func (LogMessageFilterPredicate) predicateKind(LogsPredicate) {} | ||
|
||
func (p AndPredicate[P]) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("(") | ||
sb.WriteString(p.Left.String()) | ||
sb.WriteString(" AND ") | ||
sb.WriteString(p.Right.String()) | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p OrPredicate[P]) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("(") | ||
sb.WriteString(p.Left.String()) | ||
sb.WriteString(" OR ") | ||
sb.WriteString(p.Right.String()) | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p NotPredicate[P]) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("NOT(") | ||
sb.WriteString(p.Inner.String()) | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p TimeRangePredicate[P]) String() string { | ||
var sb strings.Builder | ||
|
||
// Use standard mathematical interval notation | ||
sb.WriteString("TimeRange") | ||
if p.IncludeStart { | ||
sb.WriteString("[") | ||
} else { | ||
sb.WriteString("(") | ||
} | ||
|
||
sb.WriteString(p.StartTime.Format(time.RFC3339)) | ||
sb.WriteString(", ") | ||
sb.WriteString(p.EndTime.Format(time.RFC3339)) | ||
|
||
if p.IncludeEnd { | ||
sb.WriteString("]") | ||
} else { | ||
sb.WriteString(")") | ||
} | ||
|
||
return sb.String() | ||
} | ||
|
||
func (p LabelMatcherPredicate) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("Label(") | ||
sb.WriteString(p.Name) | ||
sb.WriteString("=") | ||
sb.WriteString(p.Value) | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p LabelFilterPredicate) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("LabelFilter(") | ||
sb.WriteString(p.Name) | ||
if p.Desc != "" { | ||
sb.WriteString(fmt.Sprintf(", description=%q", p.Desc)) | ||
} | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p LogMessageFilterPredicate) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("LogMessageFilter(") | ||
if p.Desc != "" { | ||
sb.WriteString(fmt.Sprintf("description=%q", p.Desc)) | ||
} | ||
sb.WriteString(")") | ||
return sb.String() | ||
} | ||
|
||
func (p MetadataMatcherPredicate) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("Metadata(") | ||
sb.WriteString(p.Key) | ||
sb.WriteString("=") | ||
sb.WriteString(p.Value) | ||
sb.WriteString(")") | ||
return sb.String() | ||
Comment on lines
+203
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would return fmt.Sprintf("Metadata(%s=%s)", p.Key, p.Value) here be simpler? (Similar comment for other String methods that don't have if branches) |
||
} | ||
|
||
func (p MetadataFilterPredicate) String() string { | ||
var sb strings.Builder | ||
sb.WriteString("MetadataFilter(") | ||
sb.WriteString(p.Key) | ||
if p.Desc != "" { | ||
sb.WriteString(fmt.Sprintf(", description=%q", p.Desc)) | ||
} | ||
sb.WriteString(")") | ||
return sb.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general question: do we want to make
String() string
a required method on every Predicate? Or may some of them just happen to implement String?