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

Check for nil before using struct #6238

Merged
merged 2 commits into from
May 29, 2020
Merged
Changes from 1 commit
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
36 changes: 20 additions & 16 deletions go/vt/vttablet/tabletserver/txlogz.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,26 @@ func txlogzHandler(w http.ResponseWriter, req *http.Request) {
log.Error(err)
continue
}
duration := txc.txProps.EndTime.Sub(txc.txProps.StartTime).Seconds()
var level string
if duration < 0.1 {
level = "low"
} else if duration < 1.0 {
level = "medium"
} else {
level = "high"
}
tmplData := struct {
*StatefulConnection
Duration float64
ColorLevel string
}{txc, duration, level}
if err := txlogzTmpl.Execute(w, tmplData); err != nil {
log.Errorf("txlogz: couldn't execute template: %v", err)
props := txc.txProps
// not all StatefulConnections contain transactions
if props != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna do early return?

Suggested change
if props != nil {
if props == nil {
continue

var level string
duration := props.EndTime.Sub(props.StartTime).Seconds()
if duration < 0.1 {
level = "low"
} else if duration < 1.0 {
level = "medium"
} else {
level = "high"
}
tmplData := struct {
*StatefulConnection
Duration float64
ColorLevel string
}{txc, duration, level}
if err := txlogzTmpl.Execute(w, tmplData); err != nil {
log.Errorf("txlogz: couldn't execute template: %v", err)
}
}
case <-tmr.C:
return
Expand Down