Files
percona-toolkit/src/go/pt-galera-log-explainer/main.go
Yoann La Cancellera 2091c1a1f0 Refactoring: migrate translations to singleton
It was using maps in each context, which would be merged between
contexts, then injected each time we needed a message to display.

It had a limitation on complicated operator setups: historical
information would be overriden by newer associations.
(e.g, that IP was for node0 yesterday, now it's node1, so associations
have been overwritten and incorrect)

It also introduced complexity, such as forcing to define closures too
many times, merging maps, it would be harder to debug, and every files
were starting from empty translation maps.
Moreover, iterating on maps is guaranteed to be random so it could create
hard-to-debug output variations on complex cases.

Now it is a singleton in translate package, still using maps but now it
associates an array of "units" storing the timestamp with each piece of information.
It is protected by rwmutex, because map are not threadsafe. (there's no
parallel processing for now)

No regressions, and it passes "operator_ambiguous_ips_list_all_no_color"
where the old system failed.
It nows also can be used as an easy to read source of information in
itself
2023-12-22 23:10:32 +03:00

75 lines
2.6 KiB
Go

package main
import (
"fmt"
"os"
"time"
"github.com/alecthomas/kong"
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/translate"
"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"
"github.com/rs/zerolog/log"
)
const (
toolname = "pt-galera-log-explainer"
)
// We do not set anything here, these variables are defined by the Makefile
var (
Build string //nolint
GoVersion string //nolint
Version string //nolint
Commit string //nolint
)
var buildInfo = fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s", toolname, Version, Build, GoVersion, Commit)
var CLI struct {
NoColor bool
Since *time.Time `help:"Only list events after this date, format: 2023-01-23T03:53:40Z (RFC3339)"`
Until *time.Time `help:"Only list events before this date"`
Verbosity types.Verbosity `type:"counter" short:"v" default:"0" help:"-v: DebugMySQL (add every mysql info the tool used), -vv: Debug (internal tool debug)"`
PxcOperator bool `default:"false" help:"Analyze logs from Percona PXC operator. Off by default because it negatively impacts performance for non-k8s setups"`
ExcludeRegexes []string `help:"Remove regexes from analysis. List regexes using 'pt-galera-log-explainer regex-list'"`
MergeByDirectory bool `help:"Instead of relying on identification, merge contexts and columns by base directory. Very useful when dealing with many small logs organized per directories."`
List list `cmd:""`
Whois whois `cmd:""`
Sed sed `cmd:""`
Ctx ctx `cmd:""`
RegexList regexList `cmd:""`
Conflicts conflicts `cmd:""`
Version kong.VersionFlag
GrepCmd string `help:"'grep' command path. Could need to be set to 'ggrep' for darwin systems" default:"grep"`
GrepArgs string `help:"'grep' arguments. perl regexp (-P) is necessary. -o will break the tool" default:"-P"`
}
func main() {
ctx := kong.Parse(&CLI,
kong.Name(toolname),
kong.Description("An utility to merge and help analyzing Galera logs"),
kong.UsageOnError(),
kong.Vars{
"version": buildInfo,
},
)
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.SetGlobalLevel(zerolog.WarnLevel)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
if CLI.Verbosity == types.Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
utils.SkipColor = CLI.NoColor
translate.AssumeIPStable = !CLI.PxcOperator
err := ctx.Run()
ctx.FatalIfErrorf(err)
}