Unverified Commit 1c1b394e authored by johncming's avatar johncming Committed by GitHub
Browse files

promql: Swap order of parseBrokenJSON. (#7718)



Signed-off-by: default avatarjohncming <johncming@yahoo.com>
parent 5578c963
......@@ -43,7 +43,7 @@ const (
entrySize int = 1000
)
func parseBrokenJSON(brokenJSON []byte) (bool, string) {
func parseBrokenJSON(brokenJSON []byte) (string, bool) {
queries := strings.ReplaceAll(string(brokenJSON), "\x00", "")
if len(queries) > 0 {
queries = queries[:len(queries)-1] + "]"
......@@ -51,10 +51,10 @@ func parseBrokenJSON(brokenJSON []byte) (bool, string) {
// Conditional because of implementation detail: len() = 1 implies file consisted of a single char: '['.
if len(queries) <= 1 {
return false, "[]"
return "[]", false
}
return true, queries
return queries, true
}
func logUnfinishedQueries(filename string, filesize int, logger log.Logger) {
......@@ -72,7 +72,7 @@ func logUnfinishedQueries(filename string, filesize int, logger log.Logger) {
return
}
queriesExist, queries := parseBrokenJSON(brokenJSON)
queries, queriesExist := parseBrokenJSON(brokenJSON)
if !queriesExist {
return
}
......
......@@ -162,7 +162,7 @@ func TestParseBrokenJSON(t *testing.T) {
},
} {
t.Run("", func(t *testing.T) {
ok, out := parseBrokenJSON(tc.b)
out, ok := parseBrokenJSON(tc.b)
if tc.ok != ok {
t.Fatalf("expected %t, got %t", tc.ok, ok)
return
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment