Integrate nanopb to encode and decode metrics#4388
Integrate nanopb to encode and decode metrics#4388Anchit Jain (anchitj) merged 18 commits intodev_kip_714from
Conversation
f02522c to
3058de6
Compare
3058de6 to
f14bced
Compare
Milind L (milindl)
left a comment
There was a problem hiding this comment.
Some comments, but will discuss this more with anchit
c021826 to
f288c9b
Compare
f288c9b to
0bcf681
Compare
| @@ -0,0 +1 @@ | |||
| opentelemetry.proto.metrics.v1.Metric submsg_callback:true; No newline at end of file | |||
There was a problem hiding this comment.
Add comment here
|
|
||
| struct { | ||
| /* TODO: fill this out. */ | ||
| rd_atomic32_t connects; /**< Connection attempts, |
There was a problem hiding this comment.
not urgent but for later, if this is only ever calculated in the main thread, we can make it int32_t (for the historic rkc_c) to prevent any overhead of using atomic values.
There was a problem hiding this comment.
Makes sense, update to int32_t.
| sizeof(rd_bool_t) + strlen(compression_type) + | ||
| metrics_size; | ||
| rkbuf = rd_kafka_buf_new_request(rkb, RD_KAFKAP_PushTelemetry, 1, len); | ||
| rkbuf = rd_kafka_buf_new_flexver_request(rkb, RD_KAFKAP_PushTelemetry, |
There was a problem hiding this comment.
Not this line exactly, but above, in rd_kafka_broker_ApiVersion_supported( rkb, RD_KAFKAP_PushTelemetry, 0, 1, NULL);, we should use rd_kafka_broker_ApiVersion_supported( rkb, RD_KAFKAP_PushTelemetry, 0, 0, NULL); (set max ver = 0, not 1).
There was a problem hiding this comment.
Thanks, updated.
| rd_kafka_buf_write_kbytes(rkbuf, metric_bytes); | ||
| rd_free(metric_bytes); | ||
|
|
||
| /* Let the handler perform retries so that it can pick |
There was a problem hiding this comment.
Comment isn't relevant, should be changed, though I believe NO_RETRIES is legitimate.
There was a problem hiding this comment.
Removed the comment.
| void *metrics_payload = NULL; | ||
| size_t metrics_payload_size; | ||
| void *metrics_payload = encode_metrics(rk, &metrics_payload_size); | ||
| char *compression_type = "gzip"; |
There was a problem hiding this comment.
we should ideally use rd_kafka_compression_t for PushTelemetry request. We can defer this change to later, when we actually implement compression.
There was a problem hiding this comment.
Right. I've added a TODO for this.
| // TODO: Update dummy values | ||
| void *metrics_payload = NULL; | ||
| size_t metrics_payload_size; | ||
| void *metrics_payload = encode_metrics(rk, &metrics_payload_size); |
There was a problem hiding this comment.
Should be const void*
There was a problem hiding this comment.
Thanks, updated.
| #include "nanopb/pb_decode.h" | ||
| #include "opentelemetry/metrics.pb.h" | ||
|
|
||
| rd_bool_t |
There was a problem hiding this comment.
All methods which aren't used by other files, mark them as static, here and elsewhere
That way they won't interfere with functions of the same name elsewhere (encode_string might be a fairly common name for example)
There was a problem hiding this comment.
Makes sense, missed doing this. Made all the file level functions static.
| void *const *arg) { | ||
| opentelemetry_proto_metrics_v1_NumberDataPoint *data_point = | ||
| (opentelemetry_proto_metrics_v1_NumberDataPoint *)*arg; | ||
| if (!pb_encode_tag_for_field(stream, field)) { |
There was a problem hiding this comment.
here and elsewhere, convention is to avoid using braces for single line if/for/whiles
There was a problem hiding this comment.
Updated to this convention everywhere.
| stream, opentelemetry_proto_common_v1_KeyValue_fields, key_value); | ||
| } | ||
|
|
||
| static const char *rd_kafka_type2str(rd_kafka_type_t type) { |
There was a problem hiding this comment.
best to move this to rdkafka_int.h and rdkafka_int.c and mark as non-static (I see it's used in rdkafka.c also)
There was a problem hiding this comment.
Moved to rdkafka_int.h
| } | ||
|
|
||
| // TODO: Update to handle multiple data points. | ||
| rd_bool_t encode_number_data_point(pb_ostream_t *stream, |
There was a problem hiding this comment.
I am sorry about my earlier comment about making them rd_bool_t. I didn't realize they were being used as callbacks for something that expects function ptrs with return type bool(_Bool). It's best to match the callback type in that case. Otherwise the compiler will complain (warning)
There was a problem hiding this comment.
Updated to bool.
| *metric_description = | ||
| "The total number of connections established.", | ||
| *metric_unit = "1", | ||
| *metric_type_str = rd_kafka_type2str(rk->rk_type), *metric_name; |
There was a problem hiding this comment.
I think for all these things, the type should be const char* and not char*, except for metric_name which should be declared separately.
There was a problem hiding this comment.
Thanks, updated.
61d44ad to
d83f3b5
Compare
0eb2dae to
092b429
Compare
Changes done:
src/nanopbfrom https://github.com/nanopb/nanopbsrc/opentelemetry. One of the file metrics.proto needed an option present in metrics.options to create the callback needed foroneoftypes in .proto file which isn't generated by default.rdkafka_telemetry_encode.c. Sample payload for a sum type metric will be likerdkafka_telemetry_decode.c. This is needed for testing, though not needed for functionality.TODO:
Add prefix to both nanopb and opentelemetry structs to not cause conflicts with existing applications dependent on them.