mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 05:58:16 +00:00
pt-galera-log-explainer: fixes: operator identity, keeping oldest
translations, avoiding unspecified names loops for whois command Those bugs were not breaking behavior, but they were causing variations of results. It would not always store the same timestamps, sometimes breaking tests Most of the random come from regex map iteration
This commit is contained in:
@@ -72,7 +72,7 @@ var IdentsMap = types.RegexMap{
|
||||
|
||||
"RegexMemberCount": &types.LogRegex{
|
||||
Regex: regexp.MustCompile("members.[0-9]+.:"),
|
||||
InternalRegex: regexp.MustCompile(regexMembers),
|
||||
InternalRegex: regexp.MustCompile("members." + regexMembers + ".:"),
|
||||
Handler: func(submatches map[string]string, logCtx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
|
||||
members := submatches[groupMembers]
|
||||
|
@@ -194,6 +194,14 @@ func TestIdentsRegex(t *testing.T) {
|
||||
},
|
||||
key: "RegexMemberCount",
|
||||
},
|
||||
{
|
||||
log: "{\"log\":\"2001-01-01T01:01:01.000000Z 10 [Note] [MY-000000] [Galera] ================================================\\nView:\\n id: 9f191762-2542-11ee-89be-13bdb1218f0e:9339113\\n status: primary\\n protocol_version: 4\\n capabilities: MULTI-MASTER, CERTIFICATION, PARALLEL_APPLYING, REPLAY, ISOLATION, PAUSE, CAUSAL_READ, INCREMENTAL_WS, UNORDERED, PREORDERED, STREAMING, NBO\\n final: no\\n own_index: 1\\n members(2):\\n\\t0: 45406e8d-2de0-11ee-95fc-f29a5fdf1ee0, cluster1-0\\n\\t1: 5bf18376-2de0-11ee-8333-6e755a3456ca, cluster1-2\\n=================================================\\n\",\"file\":\"/var/lib/mysql/mysqld-error.log\"}",
|
||||
expectedOut: "view member count: 2",
|
||||
expected: regexTestState{
|
||||
LogCtx: types.LogCtx{MemberCount: 2},
|
||||
},
|
||||
key: "RegexMemberCount",
|
||||
},
|
||||
|
||||
{
|
||||
log: "2001-01-01T01:01:01.000000Z 1 [Note] [MY-000000] [Galera] ####### My UUID: 60205de0-5cf6-11ec-8884-3a01908be11a",
|
||||
|
@@ -61,7 +61,7 @@ var PXCOperatorMap = types.RegexMap{
|
||||
// so this regex is about capturing subgroups to re-handle each them to the appropriate existing IdentsMap regex
|
||||
"RegexOperatorMemberAssociations": &types.LogRegex{
|
||||
Regex: regexp.MustCompile("================================================.*View:"),
|
||||
InternalRegex: regexp.MustCompile("own_index: " + regexIdx + ".*(?P<memberlog>" + IdentsMap["RegexMemberCount"].Regex.String() + ")(?P<compiledAssociations>(....-?[0-9]{1,2}(\\.-?[0-9])?: [a-z0-9]+-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]+, [a-zA-Z0-9-_\\.]+)+)"),
|
||||
InternalRegex: regexp.MustCompile("own_index: " + regexIdx + ".*" + IdentsMap["RegexMemberCount"].Regex.String() + "(?P<compiledAssociations>(....-?[0-9]{1,2}(\\.-?[0-9])?: [a-z0-9]+-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]+, [a-zA-Z0-9-_\\.]+)+)"),
|
||||
Handler: func(submatches map[string]string, logCtx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
|
||||
logCtx.MyIdx = submatches[groupIdx]
|
||||
@@ -71,12 +71,10 @@ var PXCOperatorMap = types.RegexMap{
|
||||
msg string
|
||||
)
|
||||
|
||||
logCtx, displayer = IdentsMap["RegexMemberCount"].Handle(logCtx, submatches["memberlog"], date)
|
||||
msg += displayer(logCtx) + "; "
|
||||
|
||||
subAssociations := strings.Split(submatches["compiledAssociations"], "\\n\\t")
|
||||
// if it only has a single element, the regular non-operator logRegex will trigger normally already
|
||||
if len(subAssociations) < 2 {
|
||||
return logCtx, types.SimpleDisplayer(msg)
|
||||
return logCtx, types.SimpleDisplayer("")
|
||||
}
|
||||
for _, subAssociation := range subAssociations[1:] {
|
||||
// better to reuse the idents regex
|
||||
|
@@ -21,15 +21,14 @@ func TestPXCOperatorRegex(t *testing.T) {
|
||||
},
|
||||
expected: regexTestState{
|
||||
LogCtx: types.LogCtx{
|
||||
MyIdx: "0",
|
||||
MemberCount: 3,
|
||||
OwnHashes: []string{"45406e8d-95fc"},
|
||||
OwnNames: []string{"cluster1-0"},
|
||||
MyIdx: "0",
|
||||
OwnHashes: []string{"45406e8d-95fc"},
|
||||
OwnNames: []string{"cluster1-0"},
|
||||
},
|
||||
HashToNodeNames: map[string]string{"45406e8d-95fc": "cluster1-0", "5bf18376-8333": "cluster1-2", "66e2b7bf-8000": "cluster1-1"},
|
||||
State: "PRIMARY",
|
||||
},
|
||||
expectedOut: "view member count: 3; 45406e8d-95fc is cluster1-0; 5bf18376-8333 is cluster1-2; 66e2b7bf-8000 is cluster1-1; ",
|
||||
expectedOut: "45406e8d-95fc is cluster1-0; 5bf18376-8333 is cluster1-2; 66e2b7bf-8000 is cluster1-1; ",
|
||||
key: "RegexOperatorMemberAssociations",
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user