Skip to content

Commit

Permalink
Merge pull request #6573 from ChrisBr/influx-backend
Browse files Browse the repository at this point in the history
Fix InfluxDB backend subscriber
  • Loading branch information
ChrisBr committed Dec 11, 2018
2 parents 4dab810 + a21ea6b commit 71a9688
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/api/lib/influxdb_obs/obs/middleware/backend_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(_name, _started, finished, _unique_id, data)
InfluxDB::Rails.client.write_point(series_name,
tags: tags(data),
values: values(data[:runtime]),
timestamp: InfluxDB.convert_timestamp(finished.utc))
timestamp: timestamp(finished))
rescue StandardError => e
logger.info "[InfluxDB Backend Subscriber]: #{e.message}"
end
Expand All @@ -24,12 +24,16 @@ def call(_name, _started, finished, _unique_id, data)

attr_reader :series_name, :logger

def timestamp(time)
InfluxDB.convert_timestamp(time, InfluxDB::Rails.configuration.time_precision)
end

def enabled?
CONFIG['influxdb_hosts'].present?
end

def values(runtime)
{ value: (runtime || 0) * 1000 }
{ value: ((runtime || 0) * 1000).ceil }
end

def tags(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
controller_location: 'UsersController#index',
backend_location: 'Cloud#upload'
},
timestamp: 1_517_567_370
timestamp: 1_517_567_370_000
}
end

before do
stub_const('CONFIG', CONFIG.merge('influxdb_hosts' => ['localhost']))
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:time_precision).and_return('ms')
end

it 'writes to InfluxDB' do
Expand Down

0 comments on commit 71a9688

Please sign in to comment.