File tree Expand file tree Collapse file tree 6 files changed +26
-6
lines changed Expand file tree Collapse file tree 6 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 22
33For the full commit log, [ see here] ( https://github.com/influxdata/influxdb-ruby/commits/master ) .
44
5+ ## unreleased
6+
7+ - Raise a LineProtocolError if attempting to write empty values as field set is required.
8+ Adds descriptive feedback to ` {"error":"unable to parse '{series},{tags} ': invalid field format"} `
9+
510## v0.7.0, released 2019-01-11
611
712- Drop support for Ruby 2.2, since Bundler dropped it and we want to use
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ module InfluxDB # :nodoc:
55 Error = Class . new StandardError
66 AuthenticationError = Class . new Error
77 ConnectionError = Class . new Error
8+ LineProtocolError = Class . new Error
89 SeriesNotFound = Class . new Error
910 JSONParserError = Class . new Error
1011 QueryError = Class . new Error
Original file line number Diff line number Diff line change @@ -46,7 +46,9 @@ def escape(str, type)
4646 end
4747
4848 def escape_values ( values )
49- return if values . nil?
49+ if values . nil? || values . empty?
50+ raise InfluxDB ::LineProtocolError , "Cannot create point with empty values" . freeze
51+ end
5052
5153 values . map do |k , v |
5254 key = escape ( k . to_s , :field_key )
Original file line number Diff line number Diff line change @@ -121,9 +121,13 @@ def fetch_series(response)
121121 end
122122
123123 def generate_payload ( data )
124- data . map do |point |
125- InfluxDB ::PointValue . new ( point ) . dump
126- end . join ( "\n " . freeze )
124+ data . map { |point | generate_point ( point ) } . join ( "\n " . freeze )
125+ end
126+
127+ def generate_point ( point )
128+ InfluxDB ::PointValue . new ( point ) . dump
129+ rescue InfluxDB ::LineProtocolError => e
130+ ( log :error , "Cannot write data: #{ e . inspect } " ) && nil
127131 end
128132
129133 def execute ( query , db : nil , **options )
Original file line number Diff line number Diff line change 1414 it "sends writes to client" do
1515 post_request = stub_request ( :post , stub_url ) . to_return ( status : 204 )
1616
17- ( worker . max_post_points + 100 ) . times do
18- subject . write_point ( 'a' , { } )
17+ ( worker . max_post_points + 100 ) . times do | i |
18+ subject . write_point ( 'a' , values : { i : i } )
1919 end
2020
2121 # The timout code is fragile, and heavily dependent on system load
Original file line number Diff line number Diff line change 4040 expected = series . join ( "," ) + " " + fields . join ( "," )
4141 expect ( point . dump ) . to eq ( expected )
4242 end
43+
44+ context 'with empty values' do
45+ let ( :empty_values_data ) { { series : 'test_series' , values : { } } }
46+
47+ it 'should raise an exception' do
48+ expect { InfluxDB ::PointValue . new ( empty_values_data ) } . to raise_error ( InfluxDB ::LineProtocolError )
49+ end
50+ end
4351 end
4452
4553 describe 'dump' do
You can’t perform that action at this time.
0 commit comments