Make it easy to manually test the diagnostics UI

Make it easy to manually test the diagnostics UI
From bba61e3cf1065ff13a7a78bdf17f1c059bc37a0c Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Thu, 6 Dec 2018 16:16:02 -0200
Subject: [PATCH] Make it easy to manually test the diagnostics UI


diff --git a/README.md b/README.md
index 2fef9ca..964a6a0 100644
--- a/README.md
+++ b/README.md
@@ -129,6 +129,10 @@ curl -H "Content-Type: application/x-www-form-urlencoded" -X POST --data "/messa
 
 You should see a reply with the messages of that channel you requested (in this case `/message`) starting at the message ID you requested (`0`). The URL parameter `dlp=t` disables long-polling: we do not want this request to stay open.
 
+### Diagnostics
+
+MessageBus comes with a diagnostics interface, which you can access at `/message-bus/_diagnostics`. This interface allows you visibility into the runtime behaviour of message_bus.
+
 ### Transport
 
 MessageBus ships with 3 transport mechanisms.
@@ -585,3 +589,7 @@ While working on documentation, it is useful to automatically re-build it as you
 ### Benchmarks
 
 Some simple benchmarks are implemented in `spec/performance` and can be executed using `rake performance` (or `docker-compose run tests rake performance`). You should run these before and after your changes to avoid introducing performance regressions.
+
+### Diagnostics Interface
+
+It is possible to manually test the diagnostics interface by executing `docker-compose up example` and then `open http://localhost:9292`.
diff --git a/docker-compose.yml b/docker-compose.yml
index c760a5b..a593271 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -33,6 +33,19 @@ services:
       - bundle:/usr/local/bundle
     ports:
       - 8808:8808
+  example:
+    build:
+      context: .
+    command: bash -c "cd examples/diagnostics && bundle install && bundle exec rackup --server puma --host 0.0.0.0"
+    environment:
+      BUNDLE_TO: /usr/local/bundle
+      REDISURL: redis://redis:6379
+    volumes:
+      - .:/usr/src/app
+      - bundle_config:/home/src/app/.bundle
+      - bundle:/usr/local/bundle
+    ports:
+      - 9292:9292
   redis:
     image: redis:5.0
     volumes:
diff --git a/examples/diagnostics/Gemfile b/examples/diagnostics/Gemfile
new file mode 100644
index 0000000..5ba0587
--- /dev/null
+++ b/examples/diagnostics/Gemfile
@@ -0,0 +1,5 @@
+source 'https://rubygems.org'
+
+gem 'message_bus', path: '../..'
+gem 'redis'
+gem 'puma'
diff --git a/examples/diagnostics/config.ru b/examples/diagnostics/config.ru
new file mode 100644
index 0000000..2fd4b6a
--- /dev/null
+++ b/examples/diagnostics/config.ru
@@ -0,0 +1,21 @@
+require 'message_bus'
+
+MessageBus.configure(backend: :redis, url: ENV['REDISURL'])
+MessageBus.enable_diagnostics
+
+MessageBus.user_id_lookup do |_env|
+  1
+end
+
+MessageBus.is_admin_lookup do |_env|
+  true
+end
+
+use MessageBus::Rack::Middleware
+run lambda { |_env|
+  [
+    200,
+    { "Content-Type" => "text/html" },
+    ['Howdy. Check out <a href="/message-bus/_diagnostics">the diagnostics UI</a>.']
+  ]
+}

GitHub

MessageBus comes with a diagnostics interface

We got to explain how security works here, in particular:

Also triple confirm you only get acces if is_admin_lookup returns true.

1 Like

Ahh I see, missed the followup commit …