Skip to content

Commit 4164a3c

Browse files
committed
jobs: dump debug files date first
Previously we suffixed files with the time they were made. This meant that if you requested new files, you needed do look through all the files, including the old ones, to find those your request made. Instead, all files produced by one request now sort together. Release note: none. Epic: none.
1 parent 16034b5 commit 4164a3c

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

pkg/jobs/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *Registry) maybeDumpTrace(resumerCtx context.Context, resumer Resumer, j
7676
}
7777

7878
resumerTraceFilename := fmt.Sprintf("%s/resumer-trace/%s",
79-
r.ID().String(), timeutil.Now().Format("20060102_150405.00"))
79+
timeutil.Now().Format("20060102_150405.00"), r.ID().String())
8080
td := jobspb.TraceData{CollectedSpans: sp.GetConfiguredRecording()}
8181
if err := r.db.Txn(dumpCtx, func(ctx context.Context, txn isql.Txn) error {
8282
return WriteProtobinExecutionDetailFile(dumpCtx, resumerTraceFilename, &td, txn, jobID)

pkg/server/job_profiler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (e *executionDetailsBuilder) addLabelledGoroutines(ctx context.Context) {
127127
log.Errorf(ctx, "failed to collect goroutines for job %d: %v", e.jobID, err.Error())
128128
return
129129
}
130-
filename := fmt.Sprintf("goroutines.%s.txt", timeutil.Now().Format("20060102_150405.00"))
130+
filename := fmt.Sprintf("%s/job-goroutines.txt", timeutil.Now().Format("20060102_150405.00"))
131131
if err := e.db.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
132132
return jobs.WriteExecutionDetailFile(ctx, filename, resp.Data, txn, e.jobID)
133133
}); err != nil {
@@ -146,7 +146,7 @@ func (e *executionDetailsBuilder) addDistSQLDiagram(ctx context.Context) {
146146
}
147147
if row != nil && row[0] != tree.DNull {
148148
dspDiagramURL := string(tree.MustBeDString(row[0]))
149-
filename := fmt.Sprintf("distsql.%s.html", timeutil.Now().Format("20060102_150405.00"))
149+
filename := fmt.Sprintf("%s/distsql-plan.html", timeutil.Now().Format("20060102_150405.00"))
150150
if err := e.db.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
151151
return jobs.WriteExecutionDetailFile(ctx, filename,
152152
[]byte(fmt.Sprintf(`<meta http-equiv="Refresh" content="0; url=%s">`, dspDiagramURL)),
@@ -172,7 +172,7 @@ func (e *executionDetailsBuilder) addClusterWideTraces(ctx context.Context) {
172172
return
173173
}
174174

175-
filename := fmt.Sprintf("trace.%s.zip", timeutil.Now().Format("20060102_150405.00"))
175+
filename := fmt.Sprintf("%s/trace.zip", timeutil.Now().Format("20060102_150405.00"))
176176
if err := e.db.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
177177
return jobs.WriteExecutionDetailFile(ctx, filename, zippedTrace, txn, e.jobID)
178178
}); err != nil {

pkg/sql/jobs_profiler_execution_details_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ func TestListProfilerExecutionDetails(t *testing.T) {
378378
files := listExecutionDetails(t, s, jobspb.JobID(importJobID))
379379

380380
patterns := []string{
381-
"distsql\\..*\\.html",
381+
".*/distsql-plan.html",
382382
}
383383
if !s.DeploymentMode().IsExternal() {
384-
patterns = append(patterns, "goroutines\\..*\\.txt")
384+
patterns = append(patterns, ".*/job-goroutines.txt")
385385
}
386-
patterns = append(patterns, "trace\\..*\\.zip")
386+
patterns = append(patterns, ".*/trace.zip")
387387

388388
require.Len(t, files, len(patterns))
389389
for i, pattern := range patterns {
@@ -426,17 +426,19 @@ func TestListProfilerExecutionDetails(t *testing.T) {
426426
return nil
427427
})
428428
patterns = []string{
429-
"[0-9]/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb",
430-
"[0-9]/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb.txt",
431-
"[0-9]/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb",
432-
"[0-9]/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb.txt",
433-
"distsql\\..*\\.html",
434-
"distsql\\..*\\.html",
429+
".*/distsql-plan.html",
430+
".*/distsql-plan.html",
435431
}
436432
if !s.DeploymentMode().IsExternal() {
437-
patterns = append(patterns, "goroutines\\..*\\.txt", "goroutines\\..*\\.txt")
433+
patterns = append(patterns, ".*/job-goroutines.txt", ".*/job-goroutines.txt")
438434
}
439-
patterns = append(patterns, "trace\\..*\\.zip", "trace\\..*\\.zip")
435+
patterns = append(patterns,
436+
"[0-9_.]*/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb",
437+
"[0-9_.]*/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb",
438+
"[0-9_.]*/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb.txt",
439+
"[0-9_.]*/resumer-trace/.*~cockroach\\.sql\\.jobs\\.jobspb\\.TraceData\\.binpb.txt",
440+
)
441+
patterns = append(patterns, ".*/trace.zip", ".*/trace.zip")
440442
for i, pattern := range patterns {
441443
require.Regexp(t, pattern, files[i])
442444
}
@@ -465,8 +467,9 @@ func listExecutionDetails(
465467

466468
edResp := serverpb.ListJobProfilerExecutionDetailsResponse{}
467469
require.NoError(t, protoutil.Unmarshal(body, &edResp))
470+
// Sort the responses with the variable date/time digits in the prefix removed.
468471
sort.Slice(edResp.Files, func(i, j int) bool {
469-
return edResp.Files[i] < edResp.Files[j]
472+
return strings.TrimLeft(edResp.Files[i], "0123456789_.") < strings.TrimLeft(edResp.Files[j], "0123456789_.")
470473
})
471474
return edResp.Files
472475
}

0 commit comments

Comments
 (0)