Skip to content
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

Ignore fields with NaN or Inf floats in the JSON serializer #7426

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

danielnelson
Copy link
Contributor

With this change it is possible to have a metric with no encodeable fields. I debated having the serializer skip the metric and potentially return an empty buffer, this would be similar to what the influx serializer does, but decided against it in this case. With line protocol, it isn't possible to write a line without fields, but with JSON it is still possible to write the remaining data and guarantees that something will be written. Since this data format is often used for debugging I think this will be the best behavior.

closes #7388

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson danielnelson added fix pr to fix corresponding bug area/json json and json_v2 parser/serialiser related labels Apr 28, 2020
@danielnelson danielnelson added this to the 1.14.2 milestone Apr 28, 2020
@danielnelson danielnelson requested a review from reimda April 28, 2020 17:50
Comment on lines +54 to +58
tags := make(map[string]string, len(metric.TagList()))
for _, tag := range metric.TagList() {
tags[tag.Key] = tag.Value
}
m["tags"] = tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why this is better than before. Is it better not to refer to the same map? Kind of a deep copy but what's the benefit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to remove the metric.Tags() and Fields() method the interface, they are marked as deprecated now, so I just took the liberty to do stop using them here. We don't use a map in the metric implementation anymore, since a list is more memory and GC friendly in most cases. Both of these functions make a new map and are basically equivalent to what I've done here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, thanks

@danielnelson danielnelson merged commit c4e9f72 into master Apr 28, 2020
@danielnelson danielnelson deleted the json-nan-inf branch April 28, 2020 20:41
danielnelson added a commit that referenced this pull request Apr 28, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/json json and json_v2 parser/serialiser related fix pr to fix corresponding bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus plugin - series with +Inf , -Inf, NaN values fail for json output as its not a valid json for value
2 participants