mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 15:31:55 +00:00
Merge pull request #765 from ylacancellera/pt-galera-log-explainer
pt-galera-log-explainer: improvments from feedbacks
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/types"
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/utils"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -93,11 +94,9 @@ func NoDatesRegex(skipLeadingCircumflex bool) string {
|
||||
return "^(?![0-9]{4})"
|
||||
}
|
||||
|
||||
const k8sprefix = `{"log":"`
|
||||
|
||||
func SearchDateFromLog(logline string) (time.Time, string, bool) {
|
||||
if logline[:len(k8sprefix)] == k8sprefix {
|
||||
logline = logline[len(k8sprefix):]
|
||||
if logline[:len(types.OperatorLogPrefix)] == types.OperatorLogPrefix {
|
||||
logline = logline[len(types.OperatorLogPrefix):]
|
||||
}
|
||||
for _, layout := range DateLayouts {
|
||||
if len(logline) < len(layout) {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package regex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -43,12 +44,13 @@ var PXCOperatorMap = types.RegexMap{
|
||||
},
|
||||
|
||||
// Why is it not in regular "views" regexes:
|
||||
// it could have been useful as an "verbosity=types.Detailed" regexes, very rarely
|
||||
// but in context of operators, it is actually a very important information
|
||||
// it would have been useful very rarely for on-premise setups but in context of operators,
|
||||
// it is actually an important info because gcache recovery can provoke out of memories due to
|
||||
// filecache counting against memory usage
|
||||
"RegexGcacheScan": &types.LogRegex{
|
||||
// those "operators" regexes do not have the log prefix added implicitly. It's not strictly needed, but
|
||||
// it will help to avoid catching random piece of log out of order
|
||||
Regex: regexp.MustCompile(k8sprefix + ".*GCache::RingBuffer initial scan"),
|
||||
Regex: regexp.MustCompile(types.OperatorLogPrefix + ".*GCache::RingBuffer initial scan"),
|
||||
Handler: func(submatches map[string]string, logCtx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
return logCtx, types.SimpleDisplayer("recovering gcache")
|
||||
},
|
||||
@@ -85,4 +87,20 @@ var PXCOperatorMap = types.RegexMap{
|
||||
},
|
||||
Verbosity: types.DebugMySQL,
|
||||
},
|
||||
|
||||
"RegexPodName": &types.LogRegex{
|
||||
Regex: regexp.MustCompile("^wsrep_node_incoming_address="),
|
||||
InternalRegex: regexp.MustCompile("^wsrep_node_incoming_address=(?P<podname>[a-zA-Z0-9-]*)\\.(?P<deployment>[a-zA-Z0-9-]*)\\.(?P<namespace>[a-zA-Z0-9-]*)\\."),
|
||||
Handler: func(submatches map[string]string, logCtx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
|
||||
logCtx.OperatorMetadata = &types.OperatorMetadata{
|
||||
PodName: submatches["podname"],
|
||||
Deployment: submatches["deployment"],
|
||||
Namespace: submatches["namespace"],
|
||||
}
|
||||
|
||||
return logCtx, types.SimpleDisplayer(fmt.Sprintf("podname: %s, dep: %s, namespace: %s", submatches["podname"], submatches["deployment"], submatches["namespace"]))
|
||||
},
|
||||
Verbosity: types.DebugMySQL,
|
||||
},
|
||||
}
|
||||
|
@@ -56,6 +56,21 @@ func TestPXCOperatorRegex(t *testing.T) {
|
||||
expectedOut: "recovering gcache",
|
||||
key: "RegexGcacheScan",
|
||||
},
|
||||
|
||||
{
|
||||
log: "wsrep_node_incoming_address=cluster1-0.cluster1.pxc.svc.cluster.local:3306",
|
||||
expected: regexTestState{
|
||||
LogCtx: types.LogCtx{
|
||||
OperatorMetadata: &types.OperatorMetadata{
|
||||
PodName: "cluster1-0",
|
||||
Deployment: "cluster1",
|
||||
Namespace: "pxc",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedOut: "podname: cluster1-0, dep: cluster1, namespace: pxc",
|
||||
key: "RegexPodName",
|
||||
},
|
||||
}
|
||||
|
||||
iterateRegexTest(t, PXCOperatorMap, tests)
|
||||
|
Reference in New Issue
Block a user