promql: Swap order of parseBrokenJSON. (#7718)

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2020-08-02 16:48:57 +08:00 committed by GitHub
parent 5578c96307
commit 1c1b394e5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -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
}

View file

@ -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