From ca3129b14f3a302d142071d75481b4deb5a32f81 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 14 Mar 2015 00:04:55 +0000 Subject: [PATCH] Fix data corruption when creating batches. Previously, we were appending events to the event collection even when the columns did not match! Given the following three events: ```ruby { "name": "my-series", "columns": [ "cpu.user", "time" ], "points": [ [ 5.0, 1426288467 ] ] } { "name": "my-series", "columns": [ "memory.used", "time" ], "points": [ [ 1000, 1426288467 ] ] } { "name": "my-series", "columns": [ "cpu.user", "time" ], "points": [ [ 6.0, 1426288477 ] ] } ``` We would end up with the following batch: ```ruby [ { "name": "my-series", "columns": [ "cpu.user", "time" ], "points": [ [ 5.0, 1426288467 ], [ 6.0, 1426288467 ] ] }, { "name": "my-series", "columns": [ "memory.used", "time" ], "points": [ [ 1000.0, 1426288467 ], [ 6.0, # this shouldn't be here! 1426288467 ] ] } ] --- lib/logstash/outputs/influxdb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 805f884..6af5bfa 100644 --- a/lib/logstash/outputs/influxdb.rb +++ b/lib/logstash/outputs/influxdb.rb @@ -172,7 +172,7 @@ def flush(events, teardown=false) begin if seen_series.has_key?(ev['name']) and (seen_series[ev['name']] == ev['columns']) @logger.info("Existing series data found. Appending points to that series") - event_collection.select {|h| h['points'] << ev['points'][0] if h['name'] == ev['name']} + event_collection.select {|h| h['points'] << ev['points'][0] if h['columns'] == ev['columns']} elsif seen_series.has_key?(ev['name']) and (seen_series[ev['name']] != ev['columns']) @logger.warn("Series '#{ev['name']}' has been seen but columns are different or in a different order. Adding to batch but not under existing series") @logger.warn("Existing series columns were: #{seen_series[ev['name']].join(",")} and event columns were: #{ev['columns'].join(",")}")