// rpcWrapper handles all the logic for rpc calls. func (agent *ActionAgent) rpcWrapper(ctx context.Context, name string, args, reply interface{}, verbose bool, f func() error, lock, runAfterAction bool) (err error) { from := callinfo.FromContext(ctx).String() defer func() { if x := recover(); x != nil { log.Errorf("TabletManager.%v(%v) panic: %v", name, args, x) err = fmt.Errorf("caught panic during %v: %v", name, x) } }() if lock { beforeLock := time.Now() agent.actionMutex.Lock() defer agent.actionMutex.Unlock() if time.Now().Sub(beforeLock) > rpcTimeout { return fmt.Errorf("server timeout for " + name) } } if err = f(); err != nil { log.Warningf("TabletManager.%v(%v)(from %v) error: %v", name, args, from, err.Error()) return fmt.Errorf("TabletManager.%v on %v error: %v", name, agent.TabletAlias, err) } if verbose { log.Infof("TabletManager.%v(%v)(from %v): %#v", name, args, from, reply) } if runAfterAction { err = agent.refreshTablet(ctx, "RPC("+name+")") } return }
func (qre *QueryExecutor) checkPermissions() { // Skip permissions check if we have a background context. if qre.ctx == context.Background() { return } // Blacklist ci := callinfo.FromContext(qre.ctx) action, desc := qre.plan.Rules.getAction(ci.RemoteAddr(), ci.Username(), qre.bindVars) switch action { case QR_FAIL: panic(NewTabletError(FAIL, "Query disallowed due to rule: %s", desc)) case QR_FAIL_RETRY: panic(NewTabletError(RETRY, "Query disallowed due to rule: %s", desc)) } // ACLs if !qre.plan.Authorized.IsMember(ci.Username()) { errStr := fmt.Sprintf("table acl error: %q cannot run %v on table %q", ci.Username(), qre.plan.PlanId, qre.plan.TableName) if qre.qe.strictTableAcl { panic(NewTabletError(FAIL, "%s", errStr)) } qre.qe.accessCheckerLogger.Errorf("%s", errStr) } }
// GetQueryzRows returns a list of QueryDetailzRow sorted by start time func (ql *QueryList) GetQueryzRows() []QueryDetailzRow { ql.mu.Lock() rows := []QueryDetailzRow{} for _, qd := range ql.queryDetails { row := QueryDetailzRow{ Query: qd.query, ContextHTML: callinfo.FromContext(qd.context).HTML(), Start: qd.start, Duration: time.Now().Sub(qd.start), ConnID: qd.connID, } rows = append(rows, row) } ql.mu.Unlock() sort.Sort(byStartTime(rows)) return rows }
func (log *SQLQueryStats) ContextHTML() template.HTML { return callinfo.FromContext(log.context).HTML() }
func (log *SQLQueryStats) Username() string { return callinfo.FromContext(log.context).Username() }
func (log *SQLQueryStats) RemoteAddr() string { return callinfo.FromContext(log.context).RemoteAddr() }