mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 19:11:00 +08:00
scaffolding for message bus diags
This commit is contained in:
parent
818b84f02c
commit
bdba0a78c4
vendor/gems/message_bus
18
vendor/gems/message_bus/lib/message_bus.rb
vendored
18
vendor/gems/message_bus/lib/message_bus.rb
vendored
@ -10,6 +10,7 @@ require "message_bus/client"
|
|||||||
require "message_bus/connection_manager"
|
require "message_bus/connection_manager"
|
||||||
require "message_bus/message_handler"
|
require "message_bus/message_handler"
|
||||||
require "message_bus/rack/middleware"
|
require "message_bus/rack/middleware"
|
||||||
|
require "message_bus/rack/diagnostics"
|
||||||
|
|
||||||
# we still need to take care of the logger
|
# we still need to take care of the logger
|
||||||
if defined?(::Rails)
|
if defined?(::Rails)
|
||||||
@ -71,19 +72,28 @@ module MessageBus::Implementation
|
|||||||
end
|
end
|
||||||
|
|
||||||
def site_id_lookup(&blk)
|
def site_id_lookup(&blk)
|
||||||
@site_id_lookup ||= blk
|
@site_id_lookup = blk if blk
|
||||||
|
@site_id_lookup
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_id_lookup(&blk)
|
def user_id_lookup(&blk)
|
||||||
@user_id_lookup ||= blk
|
@user_id_lookup = blk if blk
|
||||||
|
@user_id_lookup
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_admin_lookup(&blk)
|
||||||
|
@is_admin_lookup = blk if blk
|
||||||
|
@is_admin_lookup
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_connect(&blk)
|
def on_connect(&blk)
|
||||||
@on_connect ||= blk
|
@on_connect = blk if blk
|
||||||
|
@on_connect
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_disconnect(&blk)
|
def on_disconnect(&blk)
|
||||||
@on_disconnect ||= blk
|
@on_disconnect = blk if blk
|
||||||
|
@on_disconnect
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_broadcast=(val)
|
def allow_broadcast=(val)
|
||||||
|
35
vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb
vendored
Normal file
35
vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
module MessageBus::Rack; end
|
||||||
|
|
||||||
|
class MessageBus::Rack::Diagnostics
|
||||||
|
def initialize(app, config = {})
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
html = <<HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
<h2>Message Bus Diags</h2>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
return [200, {"content-type" => "text/html;"}, html]
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
|
||||||
|
return @app.call(env) unless env['PATH_INFO'].start_with? '/message-bus/_diagnostics'
|
||||||
|
|
||||||
|
route = env['PATH_INFO'].split('/message_bus/_diagnostics')[1]
|
||||||
|
|
||||||
|
if MessageBus.is_admin_lookup.nil? || !MessageBus.is_admin_lookup.call
|
||||||
|
return [403, {}, ["not allowed"]]
|
||||||
|
end
|
||||||
|
|
||||||
|
return index unless route
|
||||||
|
|
||||||
|
return [404, {}, ["not found"]]
|
||||||
|
end
|
||||||
|
end
|
@ -46,6 +46,11 @@ class MessageBus::Rack::Middleware
|
|||||||
return [200,{"Content-Type" => "text/html"},["sent"]]
|
return [200,{"Content-Type" => "text/html"},["sent"]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if env['PATH_INFO'].start_with? '/message-bus/_diagnostics'
|
||||||
|
diags = MessageBus::Rack::Diagnostics.new(@app)
|
||||||
|
return diags.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
client_id = env['PATH_INFO'].split("/")[2]
|
client_id = env['PATH_INFO'].split("/")[2]
|
||||||
return [404, {}, ["not found"]] unless client_id
|
return [404, {}, ["not found"]] unless client_id
|
||||||
|
|
||||||
|
@ -107,11 +107,22 @@ describe MessageBus::Rack::Middleware do
|
|||||||
ensure
|
ensure
|
||||||
MessageBus.long_polling_interval = 5000
|
MessageBus.long_polling_interval = 5000
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "diagnostics" do
|
||||||
|
|
||||||
|
it "should return a 403 if a user attempts to get at the _diagnostics path" do
|
||||||
|
get "/message-bus/_diagnostics"
|
||||||
|
last_response.status.should == 403
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should get a 200 with html for an authorized user" do
|
||||||
|
MessageBus.stub(:is_admin_lookup).and_return(lambda{ true })
|
||||||
|
get "/message-bus/_diagnostics"
|
||||||
|
last_response.status.should == 200
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "polling" do
|
describe "polling" do
|
||||||
before do
|
before do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user