-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Json serialization of timestamps has some issues (they're serialized as objects and not strings, as per protojson format) and @harjotgill created a workaround for that, which converts all timestamp fields manually.
aperture/sdks/aperture-js/sdk/flow.ts
Lines 78 to 108 in bce96d9
| // HACK: Change timestamps to ISO strings since the protobufjs library uses it in a different format | |
| // Issue: https://github.com/protobufjs/protobuf.js/issues/893 | |
| // PR: https://github.com/protobufjs/protobuf.js/pull/1258 | |
| // Current timestamp type: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto | |
| const localCheckResponse = this.checkResponse as any; | |
| localCheckResponse.start = this.protoTimestampToJSON( | |
| this.checkResponse.start, | |
| ); | |
| localCheckResponse.end = this.protoTimestampToJSON( | |
| this.checkResponse.end, | |
| ); | |
| localCheckResponse.waitTime = this.protoDurationToJSON( | |
| this.checkResponse.waitTime, | |
| ); | |
| // Walk through individual decisions and convert waitTime fields, | |
| // then add to localCheckResponse, preserving immutability. | |
| if (this.checkResponse.limiterDecisions) { | |
| const decisions = this.checkResponse.limiterDecisions.map( | |
| (decision) => { | |
| return { | |
| ...decision, | |
| waitTime: this.protoDurationToJSON(decision.waitTime), | |
| }; | |
| }, | |
| ); | |
| localCheckResponse.limiterDecisions = decisions; | |
| } | |
| this.span.setAttribute( | |
| CHECK_RESPONSE_LABEL, | |
| JSON.stringify(localCheckResponse), | |
| ); |
An alternative workaround would be to utilize binary serialization instead of json. We can do it because metricsprocessor accepts aperture.check_response as json but also as base64-encoded protowire. This could even result in a performance improvement as a side-effect.
Note: This requires swapping out the generator, as the current one doesn't provide anything like serializeBinary / encode, etc.
Note: If this requires some more effort, let's stay with current workaround.