When Looking at memory profiles for cockroachdb/cockroach, we observed
that the intermediate metadata.MD array constructed to iterate over
appended metadata escaped to the heap. Fortunately, this is easily
rectifiable.
go build -gcflags '-m' google.golang.org/grpc/metadata
...
google.golang.org/grpc/metadata/metadata.go:198:13: make([]MD, 0, len(raw.added) + 1) escapes to heap
* Modified tests to use tlogger.
* Fail on errors, with error expectations.
* Added expects and MixedCapsed grpclb_config tests
* Moved tlogger to grpctest, moved leakcheck tester to grpctest.go
* Added ExpectErrorN()
* Removed redundant leak checks
* Fixed new test
* Made tlogger globals into tlogger methods
* ErrorsLeft -> EndTest
* Removed some redundant lines
* Fixed error in test and empty map in EndTest
- Provide AppendToOutgoingContext interface for imrproved performance
over manually creating md and joining with existing md
- Add benchmarks for old/new approaches
Fixes#1390
This is in preparation for preventing any user-supplied metadata starting with "grpc-", which is reserved.
* stats: add methods to allow setting grpc-trace-bin and grpc-tags-bin headers
Pick these up in grpc's transport when sending and fill them when receiving.
* Add tags/trace to metadata and tests for that behavior
This is temporary to maintain compatibility and provide a migration strategy.
This change ensures consistency for the user when accessing metadata values:
they are never encoded except when sent on the wire. Previously, they would
appear encoded to client code, but not to server code. As such, this
represents a behavior change, but one unlikely to affect user code, as it's
unusual to inspect the metadata after setting it.
This will prevent the incoming RPCs' metadata from appearing in outgoing RPCs
unless it is explicitly copied, e.g.:
incomingMD, ok := metadata.FromContext(ctx)
if ok {
ctx = metadata.NewContext(ctx, incomingMD)
}
Fixes#1148
Previously metadata.NewContext(ctx, md) replaces whatever metadata in
ctx with md.
This patch merges the old metadata with md before returning the new
context.
Fixes#902.