veyron/runtimes/google: Minor tweaks to vlog and vtrace messages.
Change-Id: Ia31f9124c9fe4e1be78395abc0b9f0823f463f5d
diff --git a/runtimes/google/ipc/client.go b/runtimes/google/ipc/client.go
index 1569270..8253f05 100644
--- a/runtimes/google/ipc/client.go
+++ b/runtimes/google/ipc/client.go
@@ -897,7 +897,7 @@
// with retrying again and again with this discharge. As there is no direct way
// to detect it, we conservatively flush all discharges we used from the cache.
// TODO(ataly,andreser): add verror.BadDischarge and handle it explicitly?
- vlog.VI(3).Infof("Discarging %d discharges as RPC failed with %v", len(fc.discharges), fc.response.Error)
+ vlog.VI(3).Infof("Discarding %d discharges as RPC failed with %v", len(fc.discharges), fc.response.Error)
fc.dc.Invalidate(fc.discharges...)
}
return fc.close(verror.Convert(verror.Internal, fc.ctx, fc.response.Error))
diff --git a/runtimes/google/ipc/discharges.go b/runtimes/google/ipc/discharges.go
index 07b9e48..f12f554 100644
--- a/runtimes/google/ipc/discharges.go
+++ b/runtimes/google/ipc/discharges.go
@@ -55,20 +55,19 @@
// Gather discharges from cache.
discharges := make([]security.Discharge, len(caveats))
- d.cache.Discharges(caveats, discharges)
-
- // Fetch discharges for caveats for which no discharges were found
- // in the cache.
- if ctx == nil {
- ctx = d.defaultCtx
+ if d.cache.Discharges(caveats, discharges) > 0 {
+ // Fetch discharges for caveats for which no discharges were found
+ // in the cache.
+ if ctx == nil {
+ ctx = d.defaultCtx
+ }
+ if ctx != nil {
+ var span vtrace.Span
+ ctx, span = vtrace.SetNewSpan(ctx, "Fetching Discharges")
+ defer span.Finish()
+ }
+ d.fetchDischarges(ctx, caveats, impetus, discharges)
}
- if ctx != nil {
- var span vtrace.Span
- ctx, span = vtrace.SetNewSpan(ctx, "Fetching Discharges")
- defer span.Finish()
- }
-
- d.fetchDischarges(ctx, caveats, impetus, discharges)
for _, d := range discharges {
if d != nil {
ret = append(ret, d)
@@ -93,10 +92,12 @@
discharge security.Discharge
}
discharges := make(chan fetched, len(caveats))
+ want := 0
for i := range caveats {
if out[i] != nil {
continue
}
+ want++
wg.Add(1)
go func(i int, ctx *context.T, cav security.ThirdPartyCaveat) {
defer wg.Done()
@@ -114,6 +115,8 @@
d, ok := dAny.(security.Discharge)
if !ok {
vlog.Errorf("fetchDischarges: server at %s sent a %T (%v) instead of a Discharge", cav.Location(), dAny, dAny)
+ } else {
+ vlog.VI(3).Infof("Fetched discharge for %v: %v", cav, d)
}
discharges <- fetched{i, d}
}(i, ctx, caveats[i])
@@ -126,8 +129,10 @@
out[fetched.idx] = fetched.discharge
got++
}
- vlog.VI(2).Infof("fetchDischarges: got %d discharges", got)
- if got == 0 {
+ if want > 0 {
+ vlog.VI(3).Infof("fetchDischarges: got %d of %d discharge(s) (total %d caveats)", got, want, len(caveats))
+ }
+ if got == 0 || got == want {
return
}
}
@@ -152,16 +157,20 @@
// Discharges takes a slice of caveats and a slice of discharges of the same
// length and fills in nil entries in the discharges slice with discharges
// from the cache (if there are any).
+//
// REQUIRES: len(caveats) == len(out)
-func (dcc *dischargeCache) Discharges(caveats []security.ThirdPartyCaveat, out []security.Discharge) {
+func (dcc *dischargeCache) Discharges(caveats []security.ThirdPartyCaveat, out []security.Discharge) (remaining int) {
dcc.mu.Lock()
for i, d := range out {
if d != nil {
continue
}
- out[i] = dcc.cache[caveats[i].ID()]
+ if out[i] = dcc.cache[caveats[i].ID()]; out[i] == nil {
+ remaining++
+ }
}
dcc.mu.Unlock()
+ return
}
func (dcc *dischargeCache) invalidate(discharges ...security.Discharge) {
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index b786382..342e7b5 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -126,7 +126,7 @@
}
if err := rt.initSecurity(handle, rt.flags.Credentials); err != nil {
- return nil, fmt.Errorf("failed to init sercurity: %s", err)
+ return nil, fmt.Errorf("failed to init security: %s", err)
}
if len(rt.flags.I18nCatalogue) != 0 {