# Influxdb coerce\_values is causing exception

**URL:** <https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748>\
**Category:** Logstash\
**Created:** [May 23, 2016, 5:29pm UTC](https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748 "2016-05-23T17:29:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![astickler](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@astickler](https://discuss.elastic.co/u/astickler)\
**Post date:** [May 23, 2016, 5:29pm UTC](https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748/1 "2016-05-23T17:29:02Z")

</div>

I have logstash working fine with influxDB, but it is sending numeric values as strings so I can't use the influxDB aggregation functions like mean(). The solution to this seems to be coerce\_values in the influxdb output, but when I try that, I get an exception from ruby, and I can't work out why.

Help would be much appreciated please.  
Thanks,  
Andrew

Example data:  
"sensorID" =\> "59",  
"indoorTemp" =\> "79.0",

Influxdb output defintion:  
influxdb {  
host =\> "127.0.0.1"  
db =\> "test"  
measurement =\> "sensor"  
data\_points =\> { "indoorTemp" =\> "%{indoorTemp}"  
"sensorID" =\> "%{sensorID}"  
}  
send\_as\_tags =\> ["sensorID"]  
coerce\_values =\> { "indoorTemp" =\> "float"  
"sensorID" =\> "integer"   
}  
}

Exception:  
Failed to flush outgoing items {:outgoing\_count=\>1, :exception=\>"NoMethodError", :backtrace=\>["/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:348:in `escaped'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:226:in`events\_to\_request\_body'", "org/jruby/RubyHash.java:1342:in `each'", "org/jruby/RubyEnumerable.java:757:in`map'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:226:in `events_to_request_body'", "org/jruby/RubyArray.java:2414:in`map'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:224:in `events_to_request_body'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:171:in`flush'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:221:in `buffer_flush'", "org/jruby/RubyHash.java:1342:in`each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:216:in `buffer_flush'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:159:in`buffer\_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-influxdb-3.1.2/lib/logstash/outputs/influxdb.rb:165:in `receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/outputs/base.rb:83:in`multi\_receive'", "org/jruby/RubyArray.java:1613:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/outputs/base.rb:83:in`multi\_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/output\_delegator.rb:130:in `worker_multi_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/output_delegator.rb:114:in`multi\_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:301:in `output_batch'", "org/jruby/RubyHash.java:1342:in`each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:301:in `output_batch'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:232:in`worker\_loop'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.1-java/lib/logstash/pipeline.rb:201:in `start\_workers'"], :level=\>:warn}

---

<div class="post-metadata">

**Author:** ![astickler](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@astickler](https://discuss.elastic.co/u/astickler)\
**Post date:** [May 24, 2016, 9:47am UTC](https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748/2 "2016-05-24T09:47:54Z")

</div>

I think I have found the problem. There is a bug in the ruby code that only causes this problem if a field is defined as a tag - the test case in the 'spec' file doesn't set a tag so doesn't find this problem.

The tag value is being passed into the escaped() method, which tries to call gsub(), but the tag value has been changed from type string to type integer by the coerce\_values, and an integer type clearly doesn't have a gsub() method. The fix is to call quoted(), rather than escaped().

IMHO the actual code fix is to change line 226 of V3.1.2 of influxdb.rb from:

> result \<\< "," \<\< event["tags"].map { |tag,value| "#{escaped(tag)}=#{escaped(value)}" }.join(',') if event.has\_key?("tags")

to

> result \<\< "," \<\< event["tags"].map { |tag,value| "#{escaped(tag)}=#{quoted(value)}" }.join(',') if event.has\_key?("tags")

Perhaps someone could verify and produce an official fix please (I edited the source file on my system and confirmed it worked).

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![astickler](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@astickler](https://discuss.elastic.co/u/astickler)\
**Post date:** [May 24, 2016, 11:15am UTC](https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748/3 "2016-05-24T11:15:10Z")

</div>

OK - please ignore this. I just realised that tag values are always stored as strings in InfluxDB, so should never be included in coerce\_values. perhaps the plugin documentation could make that clear.  
Andrew

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:56am UTC](https://discuss.elastic.co/t/influxdb-coerce-values-is-causing-exception/50748/4 "2017-07-06T04:56:27Z")

</div>

Closed on July 6, 2017, 4:56am UTC


