Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ jobs:
working-directory: client-app
run: pnpm run test:ember

website:
runs-on: ubuntu-latest

services:
redis:
image: redis:8.10
ports:
- 6379:6379

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/website/Gemfile

steps:
- uses: actions/checkout@v7

- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "4.0"
bundler-cache: true

- name: Website tests
working-directory: website
run: bundle exec rake test

linting:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -183,7 +208,7 @@ jobs:

publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [backend, rack, frontend, linting]
needs: [backend, rack, frontend, website, linting]
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- FIX: Correct pattern settings state handling for plain JSON arrays and newly created or removed patterns
- DEV: Upgrade the client from Ember 3.28 to Ember 7.2 and serve the scripts and stylesheets listed in a manifest generated by the Ember build
- DEV: Convert the client components and route templates to Glimmer GJS
- DEV: Add a unified `bundle exec rake dev` workflow that installs dependencies, starts the backend and frontend, waits for readiness, and opens the app
- DEV: Add a reusable sample-data loader and richer development fixtures, and run the website tests in CI
- DEV: Ship only the runtime files and the built frontend assets in the gem, and verify the packaged assets before a release

- 2026-04-29: 2.21.0
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ Logster UI is built using [Ember.js](http://emberjs.com/)

1. Fork it ( https://github.com/discourse/logster/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Run `cd client-app && pnpm install`
4. Run `cd website && bundle install`
5. In the root directory, run `bundle exec rake client_dev` to start the Sinatra server (port 9292) and the Vite dev server (port 4200). Use the Vite server for hot reload of client code. It forwards the viewer's endpoints to Sinatra; set `LOGSTER_BACKEND` if the backend is not on `http://127.0.0.1:9292`.
6. Visit `http://localhost:4200/logs/` (with trailing slash) to test the application. Reload `http://localhost:4200/report_error` to add sample log data.
7. Once you're done making changes, run `./build_client_app.sh` to make and copy a production build to the assets folder.
8. Commit your changes (`git commit -am 'Add some feature'`)
9. Push to the branch (`git push origin my-new-feature`)
10. Create a new Pull Request
3. Run `bundle install`
4. Run `bundle exec rake dev`. This installs any missing frontend and website dependencies, starts both development servers, and opens Logster in your browser.
5. Visit `http://localhost:9292/report_error` to add sample log data. The Ember app at `http://localhost:4200/logs/` reloads automatically as you make frontend changes.
6. Once you're done making changes, run `./build_client_app.sh` to make and copy a production build to the assets folder.
7. Commit your changes (`git commit -am 'Add some feature'`)
8. Push to the branch (`git push origin my-new-feature`)
9. Create a new Pull Request
233 changes: 222 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "net/http"
require "rake/testtask"
require "rbconfig"
require "redis"
require "socket"
require "uri"
require_relative "dev_server_process"
require_relative "frontend_assets"

Rake::TestTask.new do |t|
Expand All @@ -27,16 +33,221 @@ end

task build: :build_client_app

desc "Starts Sinatra and Ember servers"
task :client_dev do
begin
pid = spawn("cd website && LOGSTER_ENV=development BUNDLE_GEMFILE=Gemfile bundle exec puma")
pid2 = spawn("cd client-app && pnpm start --port 4200")
Process.wait pid
Process.wait pid2
rescue Interrupt => e
sleep 0.5
puts "Done!"
exit 0
module DevServer
extend self

ROOT = File.expand_path(__dir__)
CLIENT_DIR = File.join(ROOT, "client-app")
WEBSITE_DIR = File.join(ROOT, "website")

def run
backend_port = Integer(ENV.fetch("BACKEND_PORT", 9292))
frontend_port = Integer(ENV.fetch("FRONTEND_PORT", 4200))
backend_url = "http://127.0.0.1:#{backend_port}"
frontend_url = "http://127.0.0.1:#{frontend_port}/logs/"
processes = []

check_redis!
check_pnpm!
ensure_port_available!(backend_port)
ensure_port_available!(frontend_port)
install_frontend_dependencies!
install_website_dependencies!

puts "Starting Logster development servers..."
processes << ["backend", spawn_backend(backend_port)]
processes << ["frontend", spawn_frontend(frontend_port, backend_url)]

wait_for!("backend", "#{backend_url}/", processes)
wait_for!("frontend", frontend_url, processes)

puts
puts "Logster is ready at #{frontend_url}"
puts "Generate rich test data at #{backend_url}/report_error"
puts "Press Ctrl-C to stop."
open_browser(frontend_url)

name, pid = DevServerProcess.wait_for_process_exit(processes)
abort "#{name.capitalize} process #{pid} stopped unexpectedly"
rescue Interrupt
puts "\nStopping Logster..."
ensure
stop_processes(processes || [])
end

private

def check_redis!
Redis.new.ping
puts "✓ Redis is available"
rescue Redis::BaseError, SystemCallError => error
abort <<~MESSAGE
Redis is not available: #{error.message}

Start Redis, then run `bundle exec rake dev` again.
MESSAGE
end

def check_pnpm!
available = system("pnpm", "--version", out: File::NULL, err: File::NULL)
abort "pnpm is required. Run `npm install -g pnpm`, then try again." unless available

puts "✓ pnpm is available"
rescue Errno::ENOENT
abort "pnpm is required. Run `npm install -g pnpm`, then try again."
end

def ensure_port_available!(port)
socket = Socket.tcp("127.0.0.1", port, connect_timeout: 0.2)
socket.close
abort "Port #{port} is already in use. Set #{port == 9292 ? "BACKEND_PORT" : "FRONTEND_PORT"} to use another port."
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT
nil
end

def install_frontend_dependencies!
installed = File.join(CLIENT_DIR, "node_modules", ".pnpm", "lock.yaml")
lockfile = File.join(CLIENT_DIR, "pnpm-lock.yaml")
if File.exist?(installed) && File.read(installed) == File.read(lockfile)
return puts("✓ Frontend dependencies are current")
end

puts "Installing frontend dependencies..."
unless system("pnpm", "install", "--dir", CLIENT_DIR)
abort "Frontend dependency installation failed"
end

puts "✓ Frontend dependencies are current"
end

def install_website_dependencies!
gemfile = File.join(WEBSITE_DIR, "Gemfile")
env = { "BUNDLE_GEMFILE" => gemfile }
available =
Bundler.with_unbundled_env do
system(env, "bundle", "check", chdir: WEBSITE_DIR, out: File::NULL)
end
return puts("✓ Website dependencies are current") if available

puts "Installing website dependencies..."
installed = Bundler.with_unbundled_env { system(env, "bundle", "install", chdir: WEBSITE_DIR) }
abort "Website dependency installation failed" unless installed

puts "✓ Website dependencies are current"
end

def spawn_backend(port)
env = {
"BUNDLE_GEMFILE" => File.join(WEBSITE_DIR, "Gemfile"),
"LOGSTER_ENV" => "development",
"LOGSTER_ENABLE_CUSTOM_PATTERNS_VIA_UI" => "1",
}
spawn(
env,
"bundle",
"exec",
"puma",
"-p",
port.to_s,
"-e",
"development",
chdir: WEBSITE_DIR,
pgroup: true,
)
end

def spawn_frontend(port, backend_url)
spawn(
{ "LOGSTER_BACKEND" => backend_url },
"pnpm",
"start",
"--host",
"127.0.0.1",
"--port",
port.to_s,
chdir: CLIENT_DIR,
pgroup: true,
)
end

def wait_for!(name, url, processes, timeout: 90)
uri = URI(url)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout

loop do
stopped = processes.find { |_, pid| Process.waitpid(pid, Process::WNOHANG) }
abort "#{stopped.first.capitalize} stopped before #{name} was ready" if stopped

begin
response =
Net::HTTP.start(uri.host, uri.port, open_timeout: 1, read_timeout: 1) do |http|
http.get(uri.request_uri)
end
if response.code.to_i < 500
puts "✓ #{name.capitalize} is ready"
return
end
rescue SystemCallError, Timeout::Error, EOFError
# The server is still starting.
end

if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
abort "Timed out waiting for #{name} at #{url}"
end
sleep 0.25
end
end

def open_browser(url)
return puts("Browser opening disabled; visit #{url}") if ENV["NO_OPEN"] == "1"

command =
case RbConfig::CONFIG["host_os"]
when /darwin/
["open", url]
when /mswin|mingw|cygwin/
["cmd", "/c", "start", "", url]
else
["xdg-open", url]
end

pid = spawn(*command, out: File::NULL, err: File::NULL)
Process.detach(pid)
rescue Errno::ENOENT
puts "Could not open a browser automatically; visit #{url}"
end

def stop_processes(processes)
processes.reverse_each do |_, pid|
Process.kill("TERM", -pid)
rescue Errno::ESRCH
nil
end

remaining = processes.map(&:last)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
while remaining.any? && Process.clock_gettime(Process::CLOCK_MONOTONIC) < deadline
remaining.reject! do |pid|
Process.waitpid(pid, Process::WNOHANG)
rescue Errno::ECHILD
true
end
sleep 0.1 if remaining.any?
end

remaining.each do |pid|
Process.kill("KILL", -pid)
Process.waitpid(pid)
rescue Errno::ESRCH, Errno::ECHILD
nil
end
end
end

desc "Start the Logster backend and frontend development servers"
task :dev do
DevServer.run
end

desc "Deprecated alias for dev"
task client_dev: :dev
10 changes: 10 additions & 0 deletions dev_server_process.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module DevServerProcess
module_function

def wait_for_process_exit(processes, wait: -> { Process.wait })
stopped_pid = wait.call
processes.find { |_, process_pid| process_pid == stopped_pid } || ["server", stopped_pid]
end
end
14 changes: 14 additions & 0 deletions test/test_dev_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative "test_helper"
require_relative "../dev_server_process"

class TestDevServerProcess < Minitest::Test
def test_identifies_the_first_process_that_exits
processes = [["backend", 101], ["frontend", 202]]

stopped = DevServerProcess.wait_for_process_exit(processes, wait: -> { 202 })

assert_equal(["frontend", 202], stopped)
end
end
5 changes: 5 additions & 0 deletions website/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ gem "sinatra"
gem "redis"
gem "logster", path: "../"
gem "puma"

group :development, :test do
gem "minitest"
gem "rake"
end
8 changes: 8 additions & 0 deletions website/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ GEM
specs:
base64 (0.3.0)
connection_pool (3.0.2)
drb (2.2.3)
logger (1.7.0)
minitest (6.0.6)
drb (~> 2.0)
prism (~> 1.5)
mustermann (3.1.1)
nio4r (2.7.5)
prism (1.9.0)
puma (8.0.2)
nio4r (~> 2.0)
rack (3.2.7)
Expand All @@ -21,6 +26,7 @@ GEM
rack-session (2.1.2)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rake (13.4.2)
redis (6.0.0)
redis-client (= 0.30.1)
redis-client (0.30.1)
Expand All @@ -39,7 +45,9 @@ PLATFORMS

DEPENDENCIES
logster!
minitest
puma
rake
redis
sinatra

Expand Down
Loading
Loading