mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-19 18:34:59 +00:00
pt-galera-log-explainer: Add pxc operator auto detection
This commit is contained in:
23
src/go/pt-galera-log-explainer/detect_operator.go
Normal file
23
src/go/pt-galera-log-explainer/detect_operator.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/types"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// areOperatorFiles will assume every files are from k8s if one is found
|
||||
func areOperatorFiles(paths []string) bool {
|
||||
|
||||
for _, path := range paths {
|
||||
|
||||
cmd := exec.Command(CLI.GrepCmd, "-q", "-a", "-m", "1", "^"+types.OperatorLogPrefix, path)
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
log.Debug().Err(err).Str("path", path).Msg("operator detection result")
|
||||
}
|
||||
return false
|
||||
}
|
@@ -95,7 +95,7 @@ func prepareGrepArgument(regexes types.RegexMap) string {
|
||||
// I'm not adding pxcoperator map the same way others are used, because they do not have the same formats and same place
|
||||
// it needs to be put on the front so that it's not 'merged' with the '{"log":"' json prefix
|
||||
// this is to keep things as close as '^' as possible to keep doing prefix searches
|
||||
grepRegex += "((" + strings.Join(regex.PXCOperatorMap.Compile(), "|") + ")|^{\"log\":\""
|
||||
grepRegex += "((" + strings.Join(regex.PXCOperatorMap.Compile(), "|") + ")|^" + types.OperatorLogPrefix
|
||||
regexes.Merge(regex.PXCOperatorMap)
|
||||
}
|
||||
if CLI.Since != nil {
|
||||
|
@@ -60,13 +60,29 @@ func main() {
|
||||
)
|
||||
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: CLI.NoColor, FormatTimestamp: func(_ interface{}) string { return "" }})
|
||||
if CLI.Verbosity == types.Debug {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
utils.SkipColor = CLI.NoColor
|
||||
|
||||
var paths []string
|
||||
switch kongcli.Command() {
|
||||
case "list <paths>":
|
||||
paths = CLI.List.Paths
|
||||
case "ctx <paths>":
|
||||
paths = CLI.Ctx.Paths
|
||||
case "conflicts <paths>":
|
||||
paths = CLI.Conflicts.Paths
|
||||
}
|
||||
|
||||
if !CLI.PxcOperator && areOperatorFiles(paths) {
|
||||
CLI.PxcOperator = true
|
||||
log.Info().Msg("Detected logs coming from Percona XtraDB Cluster Operator, enabling --pxc-operator")
|
||||
}
|
||||
|
||||
translate.AssumeIPStable = !CLI.PxcOperator
|
||||
|
||||
err := kongcli.Run()
|
||||
|
@@ -104,6 +104,12 @@ func TestMain(t *testing.T) {
|
||||
path: "tests/logs/operator_split/*",
|
||||
},
|
||||
|
||||
{
|
||||
name: "operator_auto_ambiguous_ips_list_all_no_color",
|
||||
cmd: []string{"list", "--all", "--no-color"},
|
||||
path: "tests/logs/operator_ambiguous_ips/*",
|
||||
},
|
||||
|
||||
{
|
||||
name: "conflict_conflicts",
|
||||
cmd: []string{"conflicts"},
|
||||
|
@@ -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) {
|
||||
|
@@ -50,7 +50,7 @@ var PXCOperatorMap = types.RegexMap{
|
||||
"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")
|
||||
},
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,9 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
OperatorLogPrefix = `{"log":"`
|
||||
)
|
||||
|
||||
type OperatorMetadata struct {
|
||||
PodName string
|
||||
Deployment string
|
||||
|
Reference in New Issue
Block a user