-
Notifications
You must be signed in to change notification settings - Fork 4
Add promql support for the prequel product. #25
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
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,25 +24,31 @@ type AstSetMatcherT struct { | |||||
|
|
||||||
| func (b *builderT) buildMachineNode(parserNode *parser.NodeT, parentMachineAddress, machineAddress *AstNodeAddressT, children []*AstNodeT) (*AstNodeT, error) { | ||||||
| var ( | ||||||
| seqMatcher *AstSeqMatcherT | ||||||
| setMatcher *AstSetMatcherT | ||||||
| matchNode = newAstNode(parserNode, parserNode.Metadata.Type, schema.ScopeCluster, parentMachineAddress, machineAddress) | ||||||
| err error | ||||||
| matchNode = newAstNode(parserNode, parserNode.Metadata.Type, schema.ScopeCluster, parentMachineAddress, machineAddress) | ||||||
| ) | ||||||
|
|
||||||
| switch parserNode.Metadata.Type { | ||||||
| case schema.NodeTypeSeq, schema.NodeTypeLogSeq: | ||||||
| matchNode.Metadata.Type = schema.NodeTypeSeq | ||||||
| if seqMatcher, err = buildSeqMatcher(parserNode, children); err != nil { | ||||||
| if seqMatcher, err := buildSeqMatcher(parserNode, children); err != nil { | ||||||
| return nil, err | ||||||
| } else { | ||||||
| matchNode.Object = seqMatcher | ||||||
| } | ||||||
| matchNode.Object = seqMatcher | ||||||
| case schema.NodeTypeSet, schema.NodeTypeLogSet: | ||||||
| matchNode.Metadata.Type = schema.NodeTypeSet | ||||||
| if setMatcher, err = buildSetMatcher(parserNode, children); err != nil { | ||||||
| if setMatcher, err := buildSetMatcher(parserNode, children); err != nil { | ||||||
| return nil, err | ||||||
| } else { | ||||||
| matchNode.Object = setMatcher | ||||||
| } | ||||||
| case schema.NodeTypePromQL: | ||||||
| matchNode.Metadata.Type = schema.NodeTypePromQL | ||||||
| if promMatcher, err := b.buildPromQLNode(parserNode, machineAddress, nil); err != nil { | ||||||
| return nil, err | ||||||
| } else { | ||||||
| matchNode.Object = promMatcher | ||||||
|
||||||
| matchNode.Object = promMatcher | |
| matchNode.Object = promMatcher.Object |
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.
Not sure I did this right. @tonymeehan ?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package ast | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/prequel-dev/prequel-compiler/pkg/parser" | ||
| "github.com/prequel-dev/prequel-compiler/pkg/schema" | ||
| "github.com/rs/zerolog/log" | ||
| ) | ||
|
|
||
| type AstPromQL struct { | ||
| Expr string | ||
| For time.Duration | ||
| Interval time.Duration | ||
| Event *AstEventT | ||
| } | ||
|
|
||
| func (b *builderT) buildPromQLNode(parserNode *parser.NodeT, machineAddress *AstNodeAddressT, termIdx *uint32) (*AstNodeT, error) { | ||
|
|
||
| // Expects one child of type ParsePromQL | ||
|
|
||
| if len(parserNode.Children) != 1 { | ||
| log.Error().Int("child_count", len(parserNode.Children)).Msg("PromQL node must have exactly one child") | ||
| return nil, parserNode.WrapError(ErrInvalidNodeType) | ||
| } | ||
|
|
||
| promNode, ok := parserNode.Children[0].(*parser.PromQLT) | ||
|
|
||
| if !ok { | ||
| log.Error().Any("promql", parserNode.Children[0]).Msg("Failed to build PromQL node") | ||
| return nil, parserNode.WrapError(ErrMissingScalar) | ||
| } | ||
|
|
||
| if promNode.Expr == "" { | ||
| log.Error().Msg("PromQL Expr string is empty") | ||
| return nil, parserNode.WrapError(ErrMissingScalar) | ||
| } | ||
|
|
||
| pn := &AstPromQL{ | ||
| Expr: promNode.Expr, | ||
| } | ||
|
|
||
| if parserNode.Metadata.Event != nil { | ||
| if parserNode.Metadata.Event.Origin { | ||
| b.HasOrigin = true | ||
| } | ||
| pn.Event = &AstEventT{ | ||
| Source: parserNode.Metadata.Event.Source, | ||
| Origin: parserNode.Metadata.Event.Origin, | ||
| } | ||
| } | ||
|
|
||
| if promNode.Interval != nil { | ||
| pn.Interval = *promNode.Interval | ||
| } | ||
|
|
||
| if promNode.For != nil { | ||
| pn.For = *promNode.For | ||
| } | ||
|
|
||
| var ( | ||
| address = b.newAstNodeAddress(parserNode.Metadata.RuleHash, parserNode.Metadata.Type.String(), termIdx) | ||
| node = newAstNode(parserNode, parserNode.Metadata.Type, schema.ScopeCluster, machineAddress, address) | ||
| ) | ||
|
|
||
| node.Object = pn | ||
| return node, nil | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import ( | |
| "os" | ||
| "time" | ||
|
|
||
| "gopkg.in/yaml.v2" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // version: 0.0.1 | ||
|
|
||
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.
nice