Skip to content

Commit

Permalink
Purge logs without panicking (#12187) (#12616)
Browse files Browse the repository at this point in the history
* Purge logs without panicking



* Purge logs without panicking



* try moving the goroutine to the func itself



---------

Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
Andrew Mason authored Mar 13, 2023
1 parent cec7b1a commit 0489fdb
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 31 deletions.
1 change: 1 addition & 0 deletions go/cmd/query_analyzer/query_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func main() {
acl.RegisterFlags(fs)
servenv.RegisterMySQLServerFlags(fs)
_flag.Parse(fs)
logutil.PurgeLogs()
for _, filename := range _flag.Args() {
fmt.Printf("processing: %s\n", filename)
if err := processFile(filename); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions go/cmd/rulesctl/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

_flag "vitess.io/vitess/go/internal/flag"
"vitess.io/vitess/go/vt/logutil"
)

var configFile string
Expand All @@ -14,6 +15,7 @@ func Main() *cobra.Command {
Args: cobra.NoArgs,
PreRun: func(cmd *cobra.Command, args []string) {
_flag.TrickGlog()
logutil.PurgeLogs()
},
Run: func(cmd *cobra.Command, _ []string) { cmd.Help() },
}
Expand Down
2 changes: 2 additions & 0 deletions go/cmd/vtadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtadmin"
"vitess.io/vitess/go/vt/vtadmin/cache"
Expand Down Expand Up @@ -58,6 +59,7 @@ var (
Use: "vtadmin",
PreRun: func(cmd *cobra.Command, args []string) {
_flag.TrickGlog()
logutil.PurgeLogs()

if opts.EnableTracing || httpOpts.EnableTracing {
startTracing(cmd)
Expand Down
2 changes: 2 additions & 0 deletions go/cmd/vtclient/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func run() (*results, error) {
_flag.Parse(fs)
args := _flag.Args()

logutil.PurgeLogs()

if len(args) == 0 {
pflag.Usage()
return nil, errors.New("no arguments provided. See usage above")
Expand Down
2 changes: 2 additions & 0 deletions go/cmd/vtctldclient/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/spf13/cobra"

"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
)
Expand All @@ -50,6 +51,7 @@ var (
// We use PersistentPreRun to set up the tracer, grpc client, and
// command context for every command.
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
logutil.PurgeLogs()
traceCloser = trace.StartTracing("vtctldclient")
client, err = getClientForCommand(cmd)
ctx := cmd.Context()
Expand Down
1 change: 1 addition & 0 deletions go/cmd/zk/zkcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func main() {
}

pflag.Parse()
logutil.PurgeLogs()

if help || pflag.Arg(0) == "help" {
pflag.Usage()
Expand Down
9 changes: 6 additions & 3 deletions go/vt/logutil/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ func PurgeLogs() {
logDir := f.Value.String()
program := filepath.Base(os.Args[0])
ticker := time.NewTicker(purgeLogsInterval)
for range ticker.C {
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
}

go func() {
for range ticker.C {
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
}
}()
}
28 changes: 0 additions & 28 deletions go/vt/servenv/purgelogs.go

This file was deleted.

4 changes: 4 additions & 0 deletions go/vt/servenv/servenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ func ParseFlags(cmd string) {
_flag.Usage()
log.Exitf("%s doesn't take any positional arguments, got '%s'", cmd, strings.Join(args, " "))
}

logutil.PurgeLogs()
}

// GetFlagSetFor returns the flag set for a given command.
Expand Down Expand Up @@ -364,6 +366,8 @@ func ParseFlagsWithArgs(cmd string) []string {
log.Exitf("%s expected at least one positional argument", cmd)
}

logutil.PurgeLogs()

return args
}

Expand Down

0 comments on commit 0489fdb

Please sign in to comment.