OpenTSDB / tcollector

Data collection framework for OpenTSDB
http://opentsdb.net
GNU Lesser General Public License v3.0
513 stars 359 forks source link

Fix order of checking if value is bool #428

Closed bjozet closed 4 years ago

bjozet commented 5 years ago

bool is subclass of int and will match against a check in utils.is_numeric(). This commit checks if v is bool before anything else, so we catch it early.

>>> int.__subclasses__()
[<type 'bool'>]
>>> isinstance(True, (int))
True
>>> isinstance(True, (bool))
True

Previous behaviour was that jolokia tried to send True for booleans as a value to opentsdb, which isn't allowed, and caused java.lang.NumberFormatException: For input string: "True" in application logs.

bjozet commented 5 years ago

Piggy-backing another fix into this PR to fix invalid metric names generated from jolokia. No use in having separate PRs as this one hasn't been reviewed yet anyway.