forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli,log: allow use of debug merge-logs on older logs
Fixes cockroachdb#68278. Log parsers require the flag --format when parsing older logs (because they do not contain format specification). With this patch, this is no longer a requirement as the log format is now inferred based on the structure of the log if no log format specification exists. Release justification: bug fix Release note (bug fix): The debug merge-logs command no longer returns an error when the log decoder attempts to parse older logs.
- Loading branch information
1 parent
146e021
commit 6d1becd
Showing
5 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package log | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cockroachdb/datadriven" | ||
) | ||
|
||
func TestReadLogFormat(t *testing.T) { | ||
datadriven.RunTest(t, "testdata/read_header", | ||
func(t *testing.T, td *datadriven.TestData) string { | ||
switch td.Cmd { | ||
case "log": | ||
_, format, err := ReadFormatFromLogFile(strings.NewReader(td.Input)) | ||
if err != nil { | ||
td.Fatalf(t, "error while reading format from the log file: %v", err) | ||
} | ||
return format | ||
default: | ||
t.Fatalf("unknown directive: %q", td.Cmd) | ||
} | ||
// unreachable | ||
return "" | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
subtest detect_v1_format | ||
|
||
log | ||
I210621 19:01:01.426193 1 util/log/sync_buffer.go:195 ⋮ [config] file created at: 2021/06/21 19:01:01 | ||
I210621 19:01:01.426200 1 util/log/sync_buffer.go:195 ⋮ [config] running on machine: | ||
I210621 19:01:01.426205 1 util/log/sync_buffer.go:195 ⋮ [config] binary: CockroachDB CCL v20.2.7 (x86_64-apple-darwin14, built 2021/03/29 17:56:44, go1.13.14) | ||
I210621 19:01:01.426208 1 util/log/sync_buffer.go:195 ⋮ [config] arguments: ‹[cockroach start-single-node --insecure --listen-addr=localhost:26257 --http-addr=localhost:8080]› | ||
I210609 21:45:59.308670 1 util/log/sync_buffer.go:195 ⋮ [config] log format (utf8=✓): crdb-v1 | ||
I210621 19:01:01.426216 1 util/log/sync_buffer.go:195 ⋮ [config] line format: [IWEF]yymmdd hh:mm:ss.uuuuuu goid file:line msg utf8=✓ | ||
---- | ||
crdb-v1 | ||
|
||
subtest end | ||
|
||
subtest detect_v2_format | ||
|
||
log | ||
I210816 21:25:47.681121 1 util/log/file_sync_buffer.go:238 ⋮ [config] file created at: 2021/08/16 21:25:47 | ||
I210816 21:25:47.681129 1 util/log/file_sync_buffer.go:238 ⋮ [config] running on machine: | ||
I210816 21:25:47.681135 1 util/log/file_sync_buffer.go:238 ⋮ [config] binary: CockroachDB CCL v21.2.0-alpha.00000000-3306-g39d59f1fc9-dirty (x86_64-apple-darwin20.6.0, built , go1.16.6) | ||
I210816 21:25:47.681140 1 util/log/file_sync_buffer.go:238 ⋮ [config] arguments: [‹./cockroach› ‹start-single-node› ‹--insecure› ‹--listen-addr=localhost:26258› ‹--http-addr=localhost:8081›] | ||
I210609 21:45:59.308670 1 util/log/file_sync_buffer.go:238 ⋮ [config] log format (utf8=✓): crdb-v2 | ||
I210816 21:25:47.681152 1 util/log/file_sync_buffer.go:238 ⋮ [config] line format: [IWEF]yymmdd hh:mm:ss.uuuuuu goid [chan@]file:line redactionmark \[tags\] [counter] msg | ||
---- | ||
crdb-v2 | ||
|
||
subtest end | ||
|
||
subtest default_to_v1_format | ||
|
||
log | ||
I210621 19:01:01.426193 1 util/log/sync_buffer.go:195 ⋮ [config] file created at: 2021/06/21 19:01:01 | ||
I210621 19:01:01.426200 1 util/log/sync_buffer.go:195 ⋮ [config] running on machine: | ||
I210621 19:01:01.426205 1 util/log/sync_buffer.go:195 ⋮ [config] binary: CockroachDB CCL v20.2.7 (x86_64-apple-darwin14, built 2021/03/29 17:56:44, go1.13.14) | ||
I210621 19:01:01.426208 1 util/log/sync_buffer.go:195 ⋮ [config] arguments: ‹[cockroach start-single-node --insecure --listen-addr=localhost:26257 --http-addr=localhost:8080]› | ||
I210621 19:01:01.426216 1 util/log/sync_buffer.go:195 ⋮ [config] line format: [IWEF]yymmdd hh:mm:ss.uuuuuu goid file:line msg utf8=✓ | ||
---- | ||
crdb-v1 | ||
|
||
subtest end | ||
|
||
subtest default_to_v2_format | ||
|
||
log | ||
I210816 21:25:47.681121 1 util/log/file_sync_buffer.go:238 ⋮ [config] file created at: 2021/08/16 21:25:47 | ||
I210816 21:25:47.681129 1 util/log/file_sync_buffer.go:238 ⋮ [config] running on machine: | ||
I210816 21:25:47.681135 1 util/log/file_sync_buffer.go:238 ⋮ [config] binary: CockroachDB CCL v21.2.0-alpha.00000000-3306-g39d59f1fc9-dirty (x86_64-apple-darwin20.6.0, built , go1.16.6) | ||
I210816 21:25:47.681140 1 util/log/file_sync_buffer.go:238 ⋮ [config] arguments: [‹./cockroach› ‹start-single-node› ‹--insecure› ‹--listen-addr=localhost:26258› ‹--http-addr=localhost:8081›] | ||
I210816 21:25:47.681152 1 util/log/file_sync_buffer.go:238 ⋮ [config] line format: [IWEF]yymmdd hh:mm:ss.uuuuuu goid [chan@]file:line redactionmark \[tags\] [counter] msg | ||
---- | ||
crdb-v2 | ||
|
||
subtest end |