Skip to content
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

Fix offset finder #681

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/proxystorage/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,16 @@ func (p *ProxyStorage) NodeReplacer(ctx context.Context, s *parser.EvalStmt, nod

// If the tree below us is not all the same offset, then we can't do anything below -- we'll need
// to wait until further in execution where they all match
var offset time.Duration
var offset time.Duration = 0

// If we couldn't find an offset, then something is wrong-- lets skip
// Also if there was an error, skip
if !offsetFinder.Found || offsetFinder.Error != nil {
// If we couldn't find an offset, the offset should be 0.
// If there was an error, let's skip.
if offsetFinder.Error != nil {
return nil, nil
}
offset = offsetFinder.Offset
if offsetFinder.Found {
offset = offsetFinder.Offset
}

// Function to recursivelt remove offset. This is needed as we're using
// the node API to String() the query to downstreams. Promql's iterators require
Expand Down
28 changes: 16 additions & 12 deletions pkg/proxystorage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,25 @@ func (o *OffsetFinder) Visit(node parser.Node, _ []parser.Node) (parser.Visitor,
defer o.l.Unlock()
switch n := node.(type) {
case *parser.SubqueryExpr:
if !o.Found {
o.Offset = n.OriginalOffset
o.Found = true
} else {
if n.OriginalOffset != o.Offset {
o.Error = fmt.Errorf("mismatched offsets %v %v", n.OriginalOffset, o.Offset)
if n.OriginalOffset > 0 {
if !o.Found {
o.Offset = n.OriginalOffset
o.Found = true
} else {
if n.OriginalOffset != o.Offset {
o.Error = fmt.Errorf("mismatched offsets %v %v", n.OriginalOffset, o.Offset)
}
}
}
case *parser.VectorSelector:
if !o.Found {
o.Offset = n.OriginalOffset
o.Found = true
} else {
if n.OriginalOffset != o.Offset {
o.Error = fmt.Errorf("mismatched offsets %v %v", n.OriginalOffset, o.Offset)
if n.OriginalOffset > 0 {
if !o.Found {
o.Offset = n.OriginalOffset
o.Found = true
} else {
if n.OriginalOffset != o.Offset {
o.Error = fmt.Errorf("mismatched offsets %v %v", n.OriginalOffset, o.Offset)
}
}
}
}
Expand Down
Loading