2019-04-10 19:57:15 +08:00
|
|
|
package hbase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/tsuna/gohbase/hrpc"
|
|
|
|
|
2019-04-11 17:07:06 +08:00
|
|
|
"github.com/bilibili/kratos/pkg/log"
|
2019-04-10 19:57:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewSlowLogHook log slow operation.
|
|
|
|
func NewSlowLogHook(threshold time.Duration) HookFunc {
|
|
|
|
return func(ctx context.Context, call hrpc.Call, customName string) func(err error) {
|
|
|
|
start := time.Now()
|
|
|
|
return func(error) {
|
|
|
|
duration := time.Since(start)
|
|
|
|
if duration < threshold {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("hbase slow log: %s %s %s time: %s", customName, call.Table(), call.Key(), duration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|