First implementation of telemetry channel
parent
cb49531eb5
commit
e21676afc2
|
@ -57,6 +57,7 @@ module Api
|
|||
status
|
||||
status_v8
|
||||
sync
|
||||
telemetry
|
||||
\\#
|
||||
\\*
|
||||
).map { |x| x + "(\\.|\\z)" }.join("|")
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# A singleton that runs on a separate process than the web server.
|
||||
# Listens to *ALL* incoming logs and stores them to the DB.
|
||||
# Also handles throttling.
|
||||
class TelemetryService < AbstractServiceRunner
|
||||
T = ThrottlePolicy::TimePeriod
|
||||
THROTTLE_POLICY = ThrottlePolicy.new T.new(1.minute) => 0.5 * 1_000,
|
||||
T.new(1.hour) => 0.5 * 10_000,
|
||||
T.new(1.day) => 0.5 * 100_000
|
||||
|
||||
def process(delivery_info, payload)
|
||||
device_key = delivery_info.routing_key.split(".")[1]
|
||||
json = JSON.parse(payload)
|
||||
puts json.merge(device: device_key, is_telemetry: true).to_json
|
||||
end
|
||||
end
|
|
@ -42,6 +42,14 @@ class Transport
|
|||
.bind("amq.topic", routing_key: "bot.*.logs")
|
||||
end
|
||||
|
||||
def telemetry_channel
|
||||
@telemetry_channel ||= self
|
||||
.connection
|
||||
.create_channel
|
||||
.queue("api_telemetry_workers")
|
||||
.bind("amq.topic", routing_key: "bot.*.telemetry")
|
||||
end
|
||||
|
||||
def resource_channel
|
||||
@resource_channel ||= self
|
||||
.connection
|
||||
|
|
|
@ -24,6 +24,7 @@ class RabbitWorker
|
|||
|
||||
loop do
|
||||
ThreadsWait.all_waits([
|
||||
thread { TelemetryService.new.go!(t.telemetry_channel) },
|
||||
thread { LogService.new.go!(t.log_channel) },
|
||||
thread { Resources::Service.new.go!(t.resource_channel) },
|
||||
])
|
||||
|
|
|
@ -205,6 +205,8 @@ describe Api::RmqUtilsController do
|
|||
".status.*",
|
||||
".status",
|
||||
".sync.*",
|
||||
".telemetry.*",
|
||||
".telemetry",
|
||||
".sync",
|
||||
".status_v8.*",
|
||||
".status_v8"].map { |x| expect(random_channel(x).match(r)).to be }
|
||||
|
|
Loading…
Reference in New Issue