Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workload: log histogram write/encode failures, close output file #70484

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pkg/workload/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ func runRun(gen workload.Generator, urls []string, dbName string) error {
return err
}
jsonEnc = json.NewEncoder(jsonF)
defer func() {
if err := jsonF.Sync(); err != nil {
log.Warningf(ctx, "histogram: %v", err)
}

if err := jsonF.Close(); err != nil {
log.Warningf(ctx, "histogram: %v", err)
}
}()
}

everySecond := log.Every(*displayEvery)
Expand All @@ -529,7 +538,9 @@ func runRun(gen workload.Generator, urls []string, dbName string) error {
reg.Tick(func(t histogram.Tick) {
formatter.outputTick(startElapsed, t)
if jsonEnc != nil && rampDone == nil {
_ = jsonEnc.Encode(t.Snapshot())
if err := jsonEnc.Encode(t.Snapshot()); err != nil {
log.Warningf(ctx, "histogram: %v", err)
}
}
})

Expand Down Expand Up @@ -558,7 +569,9 @@ func runRun(gen workload.Generator, urls []string, dbName string) error {
// Note that we're outputting the delta from the last tick. The
// cumulative histogram can be computed by merging all of the
// per-tick histograms.
_ = jsonEnc.Encode(t.Snapshot())
if err := jsonEnc.Encode(t.Snapshot()); err != nil {
log.Warningf(ctx, "histogram: %v", err)
}
}
if ops.ResultHist == `` || ops.ResultHist == t.Name {
if resultTick.Cumulative == nil {
Expand Down