本文整理汇总了Golang中github.com/youtube/vitess/go/vt/callerid.GetPrincipal函数的典型用法代码示例。如果您正苦于以下问题:Golang GetPrincipal函数的具体用法?Golang GetPrincipal怎么用?Golang GetPrincipal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetPrincipal函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addUserTableQueryStats
func addUserTableQueryStats(queryServiceStats *QueryServiceStats, ctx context.Context, tableName string, queryType string, duration int64) {
username := callerid.GetPrincipal(callerid.EffectiveCallerIDFromContext(ctx))
if username == "" {
username = callerid.GetUsername(callerid.ImmediateCallerIDFromContext(ctx))
}
queryServiceStats.UserTableQueryCount.Add([]string{tableName, username, queryType}, 1)
queryServiceStats.UserTableQueryTimesNs.Add([]string{tableName, username, queryType}, int64(duration))
}
示例2: Rollback
func (c *errorClient) Rollback(ctx context.Context, session *vtgatepb.Session) error {
// The client sends the error request through the callerid, as there are no other parameters
cid := callerid.EffectiveCallerIDFromContext(ctx)
request := callerid.GetPrincipal(cid)
if err := requestToError(request); err != nil {
return err
}
return c.fallbackClient.Rollback(ctx, session)
}
示例3: Format
// Format returns a printable version of the connection info.
func (txc *TxConnection) Format(params url.Values) string {
return fmt.Sprintf(
"%v\t'%v'\t'%v'\t%v\t%v\t%.6f\t%v\t%v\t\n",
txc.TransactionID,
callerid.GetPrincipal(txc.EffectiveCallerID),
callerid.GetUsername(txc.ImmediateCallerID),
txc.StartTime.Format(time.StampMicro),
txc.EndTime.Format(time.StampMicro),
txc.EndTime.Sub(txc.StartTime).Seconds(),
txc.Conclusion,
strings.Join(txc.Queries, ";"),
)
}
示例4: log
func (txc *TxConnection) log(conclusion string) {
txc.Conclusion = conclusion
txc.EndTime = time.Now()
username := callerid.GetPrincipal(txc.EffectiveCallerID)
if username == "" {
username = callerid.GetUsername(txc.ImmediateCallerID)
}
duration := txc.EndTime.Sub(txc.StartTime)
txc.pool.queryServiceStats.UserTransactionCount.Add([]string{username, conclusion}, 1)
txc.pool.queryServiceStats.UserTransactionTimesNs.Add([]string{username, conclusion}, int64(duration))
if txc.LogToFile.Get() != 0 {
log.Infof("Logged transaction: %s", txc.Format(nil))
}
TxLogger.Send(txc)
}
示例5: discard
func (txc *TxConnection) discard(conclusion string) {
txc.Conclusion = conclusion
txc.EndTime = time.Now()
username := callerid.GetPrincipal(txc.EffectiveCallerID)
if username == "" {
username = callerid.GetUsername(txc.ImmediateCallerID)
}
duration := txc.EndTime.Sub(txc.StartTime)
txc.pool.queryServiceStats.UserTransactionCount.Add([]string{username, conclusion}, 1)
txc.pool.queryServiceStats.UserTransactionTimesNs.Add([]string{username, conclusion}, int64(duration))
txc.pool.activePool.Unregister(txc.TransactionID)
txc.DBConn.Recycle()
// Ensure PoolConnection won't be accessed after Recycle.
txc.DBConn = nil
if txc.LogToFile.Get() != 0 {
log.Infof("Logged transaction: %s", txc.Format(nil))
}
TxLogger.Send(txc)
}
示例6: RunTests
// RunTests performs the necessary testsuite for CallerID operations
func RunTests(t *testing.T, im *querypb.VTGateCallerID, ef *vtrpcpb.CallerID, newContext func(context.Context, *vtrpcpb.CallerID, *querypb.VTGateCallerID) context.Context) {
ctx := context.TODO()
ctxim := callerid.ImmediateCallerIDFromContext(ctx)
// For Contexts without immediate CallerID, ImmediateCallerIDFromContext should fail
if ctxim != nil {
t.Errorf("Expect nil from ImmediateCallerIDFromContext, but got %v", ctxim)
}
// For Contexts without effective CallerID, EffectiveCallerIDFromContext should fail
ctxef := callerid.EffectiveCallerIDFromContext(ctx)
if ctxef != nil {
t.Errorf("Expect nil from EffectiveCallerIDFromContext, but got %v", ctxef)
}
ctx = newContext(ctx, nil, nil)
ctxim = callerid.ImmediateCallerIDFromContext(ctx)
// For Contexts with nil immediate CallerID, ImmediateCallerIDFromContext should fail
if ctxim != nil {
t.Errorf("Expect nil from ImmediateCallerIDFromContext, but got %v", ctxim)
}
// For Contexts with nil effective CallerID, EffectiveCallerIDFromContext should fail
ctxef = callerid.EffectiveCallerIDFromContext(ctx)
if ctxef != nil {
t.Errorf("Expect nil from EffectiveCallerIDFromContext, but got %v", ctxef)
}
// Test GetXxx on nil receivers, should get all empty strings
if u := callerid.GetUsername(ctxim); u != "" {
t.Errorf("Expect empty string from GetUsername(nil), but got %v", u)
}
if p := callerid.GetPrincipal(ctxef); p != "" {
t.Errorf("Expect empty string from GetPrincipal(nil), but got %v", p)
}
if c := callerid.GetComponent(ctxef); c != "" {
t.Errorf("Expect empty string from GetComponent(nil), but got %v", c)
}
if s := callerid.GetSubcomponent(ctxef); s != "" {
t.Errorf("Expect empty string from GetSubcomponent(nil), but got %v", s)
}
ctx = newContext(ctx, ef, im)
ctxim = callerid.ImmediateCallerIDFromContext(ctx)
// retrieved immediate CallerID should be equal to the one we put into Context
if !reflect.DeepEqual(ctxim, im) {
t.Errorf("Expect %v from ImmediateCallerIDFromContext, but got %v", im, ctxim)
}
if u := callerid.GetUsername(im); u != FakeUsername {
t.Errorf("Expect %v from GetUsername(im), but got %v", FakeUsername, u)
}
ctxef = callerid.EffectiveCallerIDFromContext(ctx)
// retrieved effective CallerID should be equal to the one we put into Context
if !reflect.DeepEqual(ctxef, ef) {
t.Errorf("Expect %v from EffectiveCallerIDFromContext, but got %v", ef, ctxef)
}
if p := callerid.GetPrincipal(ef); p != FakePrincipal {
t.Errorf("Expect %v from GetPrincipal(ef), but got %v", FakePrincipal, p)
}
if c := callerid.GetComponent(ef); c != FakeComponent {
t.Errorf("Expect %v from GetComponent(ef), but got %v", FakeComponent, c)
}
if s := callerid.GetSubcomponent(ef); s != FakeSubcomponent {
t.Errorf("Expect %v from GetSubcomponent(ef), but got %v", FakeSubcomponent, s)
}
}
示例7:
<thead>
<tr>
<th>Transaction id</th>
<th>Effective caller</th>
<th>Immediate caller</th>
<th>Start</th>
<th>End</th>
<th>Duration</th>
<th>Decision</th>
<th>Statements</th>
</tr>
</thead>
`)
txlogzFuncMap = template.FuncMap{
"stampMicro": func(t time.Time) string { return t.Format(time.StampMicro) },
"getEffectiveCaller": func(e *vtrpcpb.CallerID) string { return callerid.GetPrincipal(e) },
"getImmediateCaller": func(i *querypb.VTGateCallerID) string { return callerid.GetUsername(i) },
}
txlogzTmpl = template.Must(template.New("example").Funcs(txlogzFuncMap).Parse(`
<tr class="{{.ColorLevel}}">
<td>{{.TransactionID}}</td>
<td>{{.EffectiveCallerID | getEffectiveCaller}}</td>
<td>{{.ImmediateCallerID | getImmediateCaller}}</td>
<td>{{.StartTime | stampMicro}}</td>
<td>{{.EndTime | stampMicro}}</td>
<td>{{.Duration}}</td>
<td>{{.Conclusion}}</td>
<td>
{{ range .Queries }}
{{.}}<br>
{{ end}}
示例8: EffectiveCaller
// EffectiveCaller returns the effective caller stored in LogStats.ctx
func (stats *LogStats) EffectiveCaller() string {
return callerid.GetPrincipal(callerid.EffectiveCallerIDFromContext(stats.ctx))
}