InfluxCommunity / influxdb-ruby

Ruby client for InfluxDB
MIT License
370 stars 133 forks source link

Querying outside data w/ InfluxDB v1.0 now crashes the Ruby gem #165

Closed tristanjcook closed 8 years ago

tristanjcook commented 8 years ago

Hi there,

Just updated to version 1.0.0 of InfluxDB, and a simple test to check that querying outside the time range of my dataset returned no results is now crashing with the following error:

     Failure/Error: query_results = @database.query(query_expression)

     Zlib::BufError:
       buffer error

     # ------------------
     # --- Caused by: ---
     # EOFError:
     #   end of file reached
     #   /gems/influxdb-0.3.8/lib/influxdb/client/http.rb:73:in do_request'

Previous behaviour was to simply return an empty set of results.

dmke commented 8 years ago

I will have a look. Which Ruby version do you use?

tristanjcook commented 8 years ago

Thank you.

ruby 2.1.2p95 x86_64-linux-gnu

dmke commented 8 years ago

Can you modify my reproduction code (Gist)? I got this:

$ bundle exec ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

$ bundle exec ruby issue165.rb
drop/re-create database
write some data
(1) verify number of data points written (360 points)
[PASS]
(2) ensure no data points after last entry
[PASS]
(3) ensure no data points before first entry
[PASS]
dmke commented 8 years ago

Alternatively/additionally can you try to run your query against the database with curl, like

curl -iH 'Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3' 'http(s)://$hostname/query?u=$username&p=$password&db=$database&q=$query'

substituting $hostname, $username, $password, $database with their actual value and $query with the actual query (but URL encoded).

You can get the URL with this snippet (works in 0.3.8):

require "influxdb"

influxdb = InfluxDB::Client.new # ...

def url_for_curl(client, query, opts={})
  query   = client.builder.build query, opts[:params]
  params  = client.send :query_params, query, opts
  path    = client.send :full_url, "/query", params

  tls = client.config.use_ssl ? "s" : ""
  ["http", tls, "://", client.config.send(:next_host), path].join ""
end

# instead of `influxdb.query QUERY, OPTIONS`:
puts url_for_curl(influxdb, QUERY, OPTIONS)
tristanjcook commented 8 years ago

I've played around with the specific query and database using curl and the CLI, and it seems that this error indicates that the InfluxDB back-end has run out of memory and crashed while processing the query. I removed some of the data from the database and the behaviour was as previously expected.

Previously (pre-v1.0) when InfluxDB ran out of memory it would just silently crash and attempt to rerun the query, getting stuck in an endless loop, whereas it now seems to crash, send this error and abort the query.

If you can confirm that my suspicions are correct and this is an out-of-memory error, it could be worth catching it in the Ruby gem, as "EOFError" is not particularly descriptive or helpful. Either way, I'll close this issue as it appears to be a change in behaviour of the back-end, and not a problem with the Ruby gem.

Thanks for your help, @dmke!

dmke commented 8 years ago

If you can confirm that my suspicions are correct and this is an out-of-memory error

I will somehow need to double check, but the behaviour fits an OOM exception.

it could be worth catching it in the Ruby gem, as "EOFError" is not particularly descriptive or helpful.

That sounds like a sensible action. Did you record the data send back from the server (ideally a tcpdump pcap, or the output of curl -i)?

A Zlib::Error indicates that something was sent back which looks to Ruby like a compressed but defunct chunk of data. An empty response would otherwise lead to a JSON::ParseError ("A JSON text must at least contain two octets").