Fix print_metric and print_property for is_null values.#405
Open
robinmholt wants to merge 1 commit intoeclipse-tahu:developfrom
Open
Fix print_metric and print_property for is_null values.#405robinmholt wants to merge 1 commit intoeclipse-tahu:developfrom
robinmholt wants to merge 1 commit intoeclipse-tahu:developfrom
Conversation
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;
}
30fea7f to
9e730af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please see the commit message for details.