Skip to content

Fix print_metric and print_property for is_null values. #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

robinmholt
Copy link

Please see the commit message for details.

Currently, the library will not properly format metrics and/or
properties with the is_null flag being set and NULL values.  In either
case, the library still tries to check the value's which_type which
is initiliazed to 0, an invalid value.

The fix is a simple check for is_null and printing an appropriate
message.

Here is the output before the change:
$ ./testing_formatting_null
Add property to set...
Init metric...
Add propertyset to metric...
Adding metric to payload...
-----PAYLOAD BEGIN-----
metrics=[0x556afa369750] (count=1)
metric[0].name=nullMetric [0x556afa369730]
metric[0].datatype=3
metric[0].is_null=1
metric[0].properties.keys=[0x556afa3696b0] (count=1)
metric[0].properties. keys[0]=nullProperty [0x556afa369710]
metric[0].properties.values=[0x556afa3696d0] (count=1)
metric[0].properties.values[0].type=3
metric[0].properties.values[0].is_null=1
metric[0].properties.values[0].invalid which_value=0
metric[0].invalid which_type=0
-----PAYLOAD END-----

Here is the output with the fix:
$ ./testing_formatting_null
Add property to set...
Init metric...
Add propertyset to metric...
Adding metric to payload...
-----PAYLOAD BEGIN-----
metrics=[0x5592e32d0750] (count=1)
metric[0].name=nullMetric [0x5592e32d0730]
metric[0].datatype=3
metric[0].is_null=1
metric[0].properties.keys=[0x5592e32d06b0] (count=1)
metric[0].properties. keys[0]=nullProperty [0x5592e32d0710]
metric[0].properties.values=[0x5592e32d06d0] (count=1)
metric[0].properties.values[0].type=3
metric[0].properties.values[0].is_null=1
-----PAYLOAD END-----

Here is the test application
$ cat testing_formatting_null.cpp

int main(int argc, char **argv)
{
  auto payload_out = org_eclipse_tahu_protobuf_Payload(org_eclipse_tahu_protobuf_Payload_init_zero);
  auto nullMetric = org_eclipse_tahu_protobuf_Payload_Metric(org_eclipse_tahu_protobuf_Payload_Metric_init_default);
  auto nullMetricPropertySet = org_eclipse_tahu_protobuf_Payload_PropertySet(org_eclipse_tahu_protobuf_Payload_PropertySet_init_default);

  add_property_to_set(&nullMetricPropertySet, "nullProperty", METRIC_DATA_TYPE_INT32, NULL, 0);

  init_metric(&nullMetric, "nullMetric", false, 0, METRIC_DATA_TYPE_INT32, false, false, NULL, 0);

  add_propertyset_to_metric(&nullMetric, &nullMetricPropertySet);

  add_metric_to_payload(&payload_out, &nullMetric);

  print_payload(&payload_out);

  return 0;
}
@robinmholt robinmholt force-pushed the bug/fix_printing_is_null_values branch from 30fea7f to 9e730af Compare February 13, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant