raystack / raccoon

Raccoon is a high-throughput, low-latency service to collect events in real-time from your web, mobile apps, and services using multiple network protocols.
https://raystack.github.io/raccoon/
Apache License 2.0
199 stars 29 forks source link

Inconsistent JSON <> Protobuf API standard #67

Open punit-kulal opened 1 year ago

punit-kulal commented 1 year ago

Bug

Context:

  1. Protobuf style guide states that JSON keys should be in camelCase, and protobuf keys/field names should be in snake_case.
  2. The standard for encoding Timestamp is to convert it into a string of RFC 3339.
  3. Thus, when a Request Payload is serialised. It uses CamelCase and also converts the timestamp/sent_time into a string.
  4. However, since raccoon uses standard encoding/json package to deserialise, it does not correctly deserialise camelCase keys of Json.
  5. It also fails to deserialise the date string.

Fix

  1. Start using protobuf's official encoding/protojson package for deserialisation.
  2. It adhere's to the style guide of protobuf, which supports deserialisation of both snake_case and camelCase keys in JSON.
  3. However, existing JSON contract will break since new json contract will expect sent_time to be of type string instead of an object {seconds: number, nanos: number}. This could be fixed by updating existing clients to use protobuf's json encoders instead of language's default json encoders.