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

Querier/Ingester: Fixing json expression parser bug #3928

Merged
Merged
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
3 changes: 2 additions & 1 deletion pkg/distributor/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/kit/log/level"
"github.com/grafana/loki/pkg/loghttp/push"
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user"

"github.com/grafana/loki/pkg/loghttp/push"
)

// PushHandler reads a snappy-compressed proto from the HTTP body.
Expand Down
6 changes: 6 additions & 0 deletions pkg/logql/log/jsonexpr/jsonexpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func TestJSONExpressionParser(t *testing.T) {
nil,
fmt.Errorf("syntax error: unexpected DOT, expecting FIELD"),
},
{
"syntax error on key access",
`["key`,
nil,
fmt.Errorf("syntax error: unexpected $end, expecting RSB"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
11 changes: 10 additions & 1 deletion pkg/logql/log/jsonexpr/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (sc *Scanner) scanField() string {
break
}

if r == '.' || r == scanner.EOF || r == rune(0) {
if r == '.' || isEndOfInput(r) {
sc.unread()
break
}
Expand All @@ -118,6 +118,10 @@ func (sc *Scanner) scanStr() string {

for {
r := sc.read()
if isEndOfInput(r) {
break
}

if r == '"' || r == ']' {
break
}
Expand Down Expand Up @@ -150,6 +154,11 @@ func (sc *Scanner) scanInt() (int, error) {
return strconv.Atoi(string(number))
}

// input is either terminated by EOF or null byte
func isEndOfInput(r rune) bool {
return r == scanner.EOF || r == rune(0)
}

func (sc *Scanner) read() rune {
ch, _, _ := sc.buf.ReadRune()
return ch
Expand Down