Skip to content

Commit 027cd4f

Browse files
committed
address review
1 parent 2c1bfeb commit 027cd4f

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

base/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const (
157157
FromConnStrWarningThreshold = 10 * time.Second
158158

159159
// StackFilePrefix is the prefix used when writing stack trace files
160-
StackFilePrefix = "sg_stack_trace_"
160+
StackFilePrefix = "sg_goroutines_"
161161
)
162162

163163
// SyncGatewayRawDocXattrs is a list of xattrs that Sync Gateway will fetch when reading a raw document.

base/util.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,9 +1842,9 @@ func GetStackTrace() (bytes.Buffer, error) {
18421842
return profBuf, err
18431843
}
18441844

1845-
// RotateProfilesIfNeeded will remove old files if there are more than
1845+
// RotateFilenamesIfNeeded will remove old files if there are more than
18461846
// 10 matching the given filename pattern.
1847-
func RotateProfilesIfNeeded(filename string) error {
1847+
func RotateFilenamesIfNeeded(filename string) error {
18481848
existingFiles, err := filepath.Glob(filename)
18491849
if err != nil {
18501850
return fmt.Errorf("Error listing existing profiles in %q: %w", filename, err)
@@ -1868,6 +1868,19 @@ func LogStackTraces(ctx context.Context, logDirectory string, stackTrace bytes.B
18681868
// log to console
18691869
_, _ = fmt.Fprintf(os.Stderr, "Stack trace:\n%s\n", stackTrace.String())
18701870

1871+
err := writeStackTraceFile(ctx, logDirectory, timestamp, stackTrace)
1872+
if err != nil {
1873+
return
1874+
}
1875+
1876+
rotatePath := filepath.Join(logDirectory, StackFilePrefix+"*.log")
1877+
err = RotateFilenamesIfNeeded(rotatePath)
1878+
if err != nil {
1879+
WarnfCtx(ctx, "Error rotating stack trace files in path %s: %v", rotatePath, err)
1880+
}
1881+
}
1882+
1883+
func writeStackTraceFile(ctx context.Context, logDirectory, timestamp string, stackTrace bytes.Buffer) error {
18711884
filename := filepath.Join(logDirectory, StackFilePrefix+timestamp+".log")
18721885
file, err := os.Create(filename)
18731886
defer func() {
@@ -1878,16 +1891,13 @@ func LogStackTraces(ctx context.Context, logDirectory string, stackTrace bytes.B
18781891
}()
18791892
if err != nil {
18801893
WarnfCtx(ctx, "Error opening stack trace file %s: %v", filename, err)
1894+
return err
18811895
}
18821896

18831897
_, err = file.WriteString(fmt.Sprintf("Stack trace:\n%s\n", stackTrace.String()))
18841898
if err != nil {
18851899
WarnfCtx(ctx, "Error writing stack trace to file %s: %v", filename, err)
1900+
return err
18861901
}
1887-
1888-
rotatePath := filepath.Join(logDirectory, StackFilePrefix+"*.log")
1889-
err = RotateProfilesIfNeeded(rotatePath)
1890-
if err != nil {
1891-
WarnfCtx(ctx, "Error rotating stack trace files in path %s: %v", rotatePath, err)
1892-
}
1902+
return nil
18931903
}

rest/stats_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,5 @@ func (statsContext *statsContext) collectMemoryProfile(ctx context.Context, outp
409409

410410
// rotate old profiles
411411
path := filepath.Join(outputDir, pprofPrefix+"*.pb.gz")
412-
return base.RotateProfilesIfNeeded(path)
412+
return base.RotateFilenamesIfNeeded(path)
413413
}

tools-tests/sgcollect_info_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_make_collect_logs_stacktrace(tmpdir):
8181
).encode("utf-8")
8282
),
8383
):
84-
stacktrace_file = tmpdir.join("sg_stack_trace.log")
84+
stacktrace_file = tmpdir.join("sg_goroutines.log")
8585
stacktrace_file.write("foo")
8686
tasks = sgcollect.make_collect_logs_tasks(
8787
sg_url="fakeurl",

tools/sgcollect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def make_http_client_stack_trace_task(
291291
name="Collect stack trace via http client",
292292
auth_headers=auth_headers,
293293
url=stack_trace_url,
294-
log_file="sg_stack_trace.log",
294+
log_file="sg_goroutines.log",
295295
)
296296
stack_trace_task.no_header = True
297297

@@ -386,7 +386,7 @@ def make_collect_logs_tasks(
386386
"sg_debug.log": "sg_debug.log",
387387
"sg_trace.log": "sg_trace.log",
388388
"sg_stats.log": "sg_stats.log",
389-
"sg_stack_trace.log": "sg_stack_trace.log",
389+
"sg_goroutines.log": "sg_goroutines.log",
390390
"sync_gateway_access.log": "sync_gateway_access.log",
391391
"sync_gateway_error.log": "sync_gateway_error.log",
392392
"pprof.pb": "pprof.pb",

0 commit comments

Comments
 (0)