Sending UUID as grpc metadata encoding

I am trying to send an UUID as a metadata parameter to a GRPC call. I thought maybe just using the uuidv4 from “” would suffice and that there might be some type of magic that encodes strings, but that doesn’t seem to be the case. I believe on the grpc side it requires a buffer, but I am not sure how to do that on the k6 side.

I thought doing something like this might work but it seems it is too long of an encoding found on the server:

let buf = new Uint8Array([ 0, 112, 177, 110, 123, 190,  75, 139, 134, 253, 85,  92, 185, 106,  65, 159]).buffer
let myID = encoding.b64encode(buf)
const params = { metadata: {'id-bin':  myID} };
const response = client.invoke("Service/Start", {}, params)

but this doesn’t seem to encode it properly. has anyone been successful sending UUID’s as metadata to a grpc call?

thank you!

Can you point me to some documentation that says that? Usually, gRPC metadata are string pairs. The values can be binary, but I don’t see why a UUID specifically needs to be.

And the jslib UUID functions return a string that should be directly usable.

If binary is actually needed, I think you need to pass the Uint8Array’s buffer property directly, though I am not 100% sure, k6 might require some changes for this to actually work as expected :thinking:

Hi, Ned - thanks for the reply.

That first link says are typically strings, but can be binary data. – which in my case I do have a binary key that does metadata validation (hope I am reading the correct code).

I think if my key wasn’t -bin it wouldn’t be a problem sending a string, but unfortunately that isn’t how we designed the proto.

Appreciate the insights,

I was about to open a k6 GitHub issue to add support for binary gRPC metadata, but while looking at the code you linked to, and at the Go gRPC implementation’s metadata package, there is doesn’t seem to be any special support for binary data on the gRPC API level. Instead, the convention seems to be that if the metadata key name ends up with -bin, the Go library will automatically base64-encode it.

So, in your case, you don’t need to manually call encoding.b64encode(), that should be handled automatically when your key ends with -bin, just pass it as a string. I am not sure what happens if you have metadata values that are invalid UTF-16 (because of JS) or UTF-8 (because of Go) strings though :thinking: