Skip to content

Commit

Permalink
Add stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
aadi-shopify committed Oct 10, 2024
1 parent cf566e1 commit 4ad6411
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion go/vt/topo/stats_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package topo

import (
"context"
"fmt"
"runtime"
"time"

"vitess.io/vitess/go/stats"
Expand Down Expand Up @@ -110,13 +112,33 @@ func (st *StatsConn) Get(ctx context.Context, filePath string) ([]byte, Version,
defer topoStatsConnTimings.Record(statsKey, startTime)
bytes, version, err := st.conn.Get(ctx, filePath)
if err != nil {
log.Warningf("Get failed for cell %s, filePath %s: %v", st.cell, filePath, err)
stack := stackTrace()
log.Warningf("Get failed for cell %s, filePath %s: %v\n%s", st.cell, filePath, err, stack)
topoStatsConnErrors.Add(statsKey, int64(1))
return bytes, version, err
}
return bytes, version, err
}

func stackTrace() []string {
pc := make([]uintptr, 10)
n := runtime.Callers(0, pc)
if n == 0 {
return []string{}
}
pc = pc[:n]
frames := runtime.CallersFrames(pc)
stack := []string{}
for {
frame, more := frames.Next()
if !more {
break
}
stack = append(stack, fmt.Sprintf("%s (%s:%d)", frame.Function, frame.File, frame.Line))
}
return stack
}

// List is part of the Conn interface
func (st *StatsConn) List(ctx context.Context, filePathPrefix string) ([]KVInfo, error) {
startTime := time.Now()
Expand Down

0 comments on commit 4ad6411

Please sign in to comment.