-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
feat(parsers.xpath): Add Concise Binary Object Representation parser #13480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome and so simple. What do you think about some additional test cases for other layouts that we can reference as examples? Maybe we can ask the requester for some?
I will let you merge once you hear back from the original requester.
Hi! Sorry for the delay in commenting. Thank you very much for working on this! I like the batch config because it makes it more robust to new keys being added to the messages. Currently, when using this configuration all fields are of type As far as I understood from tests and documentation, Another inconvenience I found when testing with our payloads is that we use numbers as keys. Not even numbers in a string, like "123", just 123. This was done to reduce the size of the messages we send. We map those numerical keys to names on reception. Currently, I don't care about this mapping, I would like to store directly these numbers as field names. (Field names could be strings with the numbers, that's fine). I could not figure out how to match numbers for fields in XPath queries, and even if they were "123" strings, you cannot have names that start with numbers as far as I understood. I don't know if these numbers as keys are really something that could be changed (as it looks like XPath does not support it), but its something that we could change on our end, and send shorter strings instead of numbers, sacrificing some message size. However, respecting the types would be really nice, so that we could use the batch configuration option. I will provide examples derived from our messages, changing the keys, so that they work, but I need a bit more time (and learn more about XPath haha) Thanks again! This is amazing! |
Totally would love to see more test cases/examples! I just don't have real world data so if the requester provides some including "query targets" that would be awesome... |
This should be fixed now. Would love to get a confirmation on this with the latest version.
This is a tricky thing... Numerical node names are not supported in XPath so I need to convert them to strings. Furthermore, Telegraf only supports string-types for field names. This being said, the best I can offer is to use the string-representation of these numbers, but you need to re-convert them to integers on the receiver side... Or even easier you send the field-names/keys as string like In any case, if you can provide some example data and queries with their expected result I would love to add them as test-cases to prevent regressions by future changes and as examples for other users. |
@srebhan thanks for the update. I can confirm that the Regarding the numbers, it would not be a problem if the numbers (123) are converted to strings ("123") in the Telegraf field names. I don't really need them to number once they are received. However, from what I understood numerical node names are not supported even if they are strings with numbers. Hopefully, I am wrong though. I will provide a series of examples, with the original keys that we use, another with the "123" type strings (which I could not really get working with the XPath queries either), and a third variation with regular names as keys. |
As long as the names are strings, the content is irrelevant. A node name of Btw: Did you think about zipping the transmitted packages? If they contain a decent amount of strings you could get out a good compression ratio... |
@srebhan Regarding having numbers as keys. In CBOR they are valid, but not in XPath/Telegraf, so I think it would make sense to always convert the keys to strings (and document it as such in the plugin). Currently, the parser (even when using batch configuration) will output errors like:
and there is no way to configure the plugin to avoid this problem (at least that I can see) and accept the inputs. |
Regarding queries of node names that are numbers only, I am also having trouble with them:
With the following configuration:
However, if I change the keys to start with a letter, for example the timestamp now is
Works, and the timestamp in that key is used as time for the metric. |
I was finally able to put some examples together. I was unsure how to better provide them, so I pushed them here: There you'll find Python code that generates the CBOR (and Json for reference) messages which are cleaned-up versions of real messages we manage, as well as the Telegraf configuration I was using to do the tests. I am happy with the resulting configuration:
However, for this to work, I needed to change the keys from numbers to strings and add a letter at the start ( As stated before, it would be great if:
Regarding the binary data, I tried adding this line:
right after this one, but it did not have any effect. That would be nice to avoid the problem of storing non-character bytes. Not sure if this is not how I am supposed to use it, but I could not make it work and it would be great. |
I forgot to talk about the base64 experiments included in the linked repo. It would be nice to have an option like Having the base64 option is nice because the resulting string is significantly smaller than when encoding as a hex string. |
Thanks for adding support for numerical keys @srebhan! I just tested it here and works great. I really appreciate the work put into this. Out of the things that I tested, the only remaining issue would be that I can't get the option |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
@tulku hex encoding works for me. Added unit-test to show it... |
Thank you very much for the test! I realized what was my problem. This configuration abstract works for me:
Mean that keys However, what I was trying to do and failing was defining a field, and having that field be converted to a hex string, for example:
If in this example, I change Thank you a lot for the clarification and the extra unittests! And sorry for the extra work! Again, it is amazing to have this plugin now. Thank you a lot! From what I could test, this is ready to merge. |
@tulku can you please open a separate issue for the hex-encoding as this is true for all formats XPath supports. If this is ok for you, I would love to merge this PR and handle the bug-fix in another one to get it out in the next bugfix release... |
@powersj can you please give the PR a final review and then we are good to go. As mentioned, the hex-encoding problem is a separate issue that should receive a bug-fix PR so we can roll it out in v1.27.2 in case I manage to fix it in time... |
@srebhan @powersj Again, thanks a lot for this work! I was thinking of adding a base64 encoding option. Would you review/support such a feature? If that is the case, I can create an issue and attempt a PR for it. |
@tulku it is wrong. You request this on explicit fields and it does not work. That's clearly unexpected and a bug. Would be nice if you could open an issue so we do not forget about this. |
resolves #13464
This PR adds support for parsing Concise Binary Object Representation (CBOR) messages using XPath expressions.