Skip to content

Commit ab1d0fe

Browse files
author
Andrew Mason
authored
Purge logs without panicking (vitessio#12187) (vitessio#12617)
* Purge logs without panicking * Purge logs without panicking * try moving the goroutine to the func itself --------- Signed-off-by: Andrew Mason <andrew@planetscale.com>
1 parent 5e9de1f commit ab1d0fe

File tree

9 files changed

+20
-31
lines changed

9 files changed

+20
-31
lines changed

go/cmd/query_analyzer/query_analyzer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func main() {
7070
acl.RegisterFlags(fs)
7171
servenv.RegisterMySQLServerFlags(fs)
7272
_flag.Parse(fs)
73+
logutil.PurgeLogs()
7374
for _, filename := range _flag.Args() {
7475
fmt.Printf("processing: %s\n", filename)
7576
if err := processFile(filename); err != nil {

go/cmd/rulesctl/cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/spf13/cobra"
55

66
_flag "vitess.io/vitess/go/internal/flag"
7+
"vitess.io/vitess/go/vt/logutil"
78
)
89

910
var configFile string
@@ -14,6 +15,7 @@ func Main() *cobra.Command {
1415
Args: cobra.NoArgs,
1516
PreRun: func(cmd *cobra.Command, args []string) {
1617
_flag.TrickGlog()
18+
logutil.PurgeLogs()
1719
},
1820
Run: func(cmd *cobra.Command, _ []string) { cmd.Help() },
1921
}

go/cmd/vtadmin/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"vitess.io/vitess/go/trace"
2828
"vitess.io/vitess/go/vt/log"
29+
"vitess.io/vitess/go/vt/logutil"
2930
"vitess.io/vitess/go/vt/servenv"
3031
"vitess.io/vitess/go/vt/vtadmin"
3132
"vitess.io/vitess/go/vt/vtadmin/cache"
@@ -58,6 +59,7 @@ var (
5859
Use: "vtadmin",
5960
PreRun: func(cmd *cobra.Command, args []string) {
6061
_flag.TrickGlog()
62+
logutil.PurgeLogs()
6163

6264
if opts.EnableTracing || httpOpts.EnableTracing {
6365
startTracing(cmd)

go/cmd/vtclient/vtclient.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ func run() (*results, error) {
184184
_flag.Parse(fs)
185185
args := _flag.Args()
186186

187+
logutil.PurgeLogs()
188+
187189
if len(args) == 0 {
188190
pflag.Usage()
189191
return nil, errors.New("no arguments provided. See usage above")

go/cmd/vtctldclient/command/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/spf13/cobra"
2727

2828
"vitess.io/vitess/go/trace"
29+
"vitess.io/vitess/go/vt/logutil"
2930
"vitess.io/vitess/go/vt/servenv"
3031
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
3132
)
@@ -49,6 +50,7 @@ var (
4950
// We use PersistentPreRun to set up the tracer, grpc client, and
5051
// command context for every command.
5152
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
53+
logutil.PurgeLogs()
5254
traceCloser = trace.StartTracing("vtctldclient")
5355
if VtctldClientProtocol != "local" {
5456
if err := ensureServerArg(); err != nil {

go/cmd/zk/zkcmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func main() {
147147
}
148148

149149
pflag.Parse()
150+
logutil.PurgeLogs()
150151

151152
if help || pflag.Arg(0) == "help" {
152153
pflag.Usage()

go/vt/logutil/purge.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ func PurgeLogs() {
127127
logDir := f.Value.String()
128128
program := filepath.Base(os.Args[0])
129129
ticker := time.NewTicker(purgeLogsInterval)
130-
for range ticker.C {
131-
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
132-
}
130+
131+
go func() {
132+
for range ticker.C {
133+
purgeLogsOnce(time.Now(), logDir, program, keepLogsByCtime, keepLogsByMtime)
134+
}
135+
}()
133136
}

go/vt/servenv/purgelogs.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

go/vt/servenv/servenv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ func ParseFlags(cmd string) {
319319
_flag.Usage()
320320
log.Exitf("%s doesn't take any positional arguments, got '%s'", cmd, strings.Join(args, " "))
321321
}
322+
323+
logutil.PurgeLogs()
322324
}
323325

324326
// GetFlagSetFor returns the flag set for a given command.
@@ -348,6 +350,8 @@ func ParseFlagsWithArgs(cmd string) []string {
348350
log.Exitf("%s expected at least one positional argument", cmd)
349351
}
350352

353+
logutil.PurgeLogs()
354+
351355
return args
352356
}
353357

0 commit comments

Comments
 (0)