Skip to content

Commit

Permalink
tool: fix tool to tolerate T in the log context
Browse files Browse the repository at this point in the history
In recent releases, the log context now contains a tenant ID (`T`)
that comes before the node. This was not accounted for in the logs
regexp.

This commit fixes this and adds some tests.
  • Loading branch information
RaduBerinde committed Nov 2, 2023
1 parent 58cbdb4 commit 844f058
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tool/logs/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ var (
// Captures a common logging prefix that can be used as the context for the
// surrounding information captured by other expressions. Example:
//
// I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n5,pebble,s5] ...
// I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [T1,n5,pebble,s5] ...
//
logContextPattern = regexp.MustCompile(
`^.*` +
/* Timestamp */ `(?P<timestamp>\d{6} \d{2}:\d{2}:\d{2}.\d{6}).*` +
/* Node / Store */ `\[n(?P<node>\d+|\?).*,s(?P<store>\d+|\?).*?\].*`,
/* Node / Store */ `\[(T(\d+|\?),)?n(?P<node>\d+|\?).*,s(?P<store>\d+|\?).*?\].*`,
)
logContextPatternTimestampIdx = logContextPattern.SubexpIndex("timestamp")
logContextPatternNodeIdx = logContextPattern.SubexpIndex("node")
Expand Down
51 changes: 51 additions & 0 deletions tool/logs/compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,57 @@ func TestCompactionLogs_Regex(t *testing.T) {
}
}

func TestParseLogContext(t *testing.T) {
testCases := []struct {
line string
timestamp string
node int
store int
}{
{
line: `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n5,pebble,s6] foo`,
timestamp: "211215 14:26:56.012382",
node: 5,
store: 6,
},
{
line: `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [T?,n5,pebble,s6] foo`,
timestamp: "211215 14:26:56.012382",
node: 5,
store: 6,
},
{
line: `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [T15,n5,pebble,s6] foo`,
timestamp: "211215 14:26:56.012382",
node: 5,
store: 6,
},
{
line: `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [T1,n?,pebble,s6] foo`,
timestamp: "211215 14:26:56.012382",
node: -1,
store: 6,
},
{
line: `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n5,pebble,s?] foo`,
timestamp: "211215 14:26:56.012382",
node: 5,
store: -1,
},
}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
var b logEventCollector
require.NoError(t, parseLogContext(tc.line, &b))
expT, err := time.Parse(timeFmt, tc.timestamp)
require.NoError(t, err)
require.Equal(t, expT, b.ctx.timestamp)
require.Equal(t, tc.node, b.ctx.node)
require.Equal(t, tc.store, b.ctx.store)
})
}
}

func TestCompactionLogs(t *testing.T) {
dir := t.TempDir()
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
Expand Down

0 comments on commit 844f058

Please sign in to comment.