Skip to content

Commit

Permalink
Check for nil before using struct (#6238)
Browse files Browse the repository at this point in the history
* Check for nil before using struct

Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay authored May 29, 2020
1 parent e7c58d5 commit 41c356e
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions go/vt/vttablet/tabletserver/txlogz.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,33 @@ 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)
// not all StatefulConnections contain transactions
if txc.txProps != nil {
writeTransactionData(w, txc)
}
case <-tmr.C:
return
}
}
}

func writeTransactionData(w http.ResponseWriter, txc *StatefulConnection) {
props := txc.txProps
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)
}
}

0 comments on commit 41c356e

Please sign in to comment.