Skip to content

Commit

Permalink
Merge branch 'feat/DEX-2163/autoload-yabeda-server' into 'master'
Browse files Browse the repository at this point in the history
[DEX-2163] feat: autostart yabeda server

Closes DEX-2163

See merge request nstmrt/rubygems/outbox!90
  • Loading branch information
bibendi committed May 3, 2024
2 parents 0e6b4a8 + 43f16ea commit 06d6589
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - yyyy-mm-dd

## [6.4.0] - 2024-05-02

### Added
- added autostart of the yabeda server via the `enabled` option
- added disabling autorun of probes via the `enabled` option

## [6.3.1] - 2024-05-01

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ The `outbox.yml` configuration file is the main configuration for the gem, where
default: &default
owner: foo-team # optional, used in Yabeda metrics
bucket_size: 16 # optional, default 16, see into about the buckets at the #Concurrency section
metrics:
enabled: true # default false, yabeda server autostart with port: 9090 and path: /metrics
port: 9090 # optional, default, used in Yabeda metrics
probes:
enabled: false # optional, default true
port: 5555 # default, used for Kubernetes probes

outbox_items: # outbox items section
Expand Down
2 changes: 2 additions & 0 deletions lib/generators/outbox/install/templates/outbox.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default: &default
owner: owner-team
bucket_size: 16
metrics:
enabled: true

probes:
port: SET-UP-YOUR-HEALTHCHECK-PORT-HERE
Expand Down
1 change: 1 addition & 0 deletions lib/sbmt/outbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
require_relative "outbox/middleware/builder"
require_relative "outbox/middleware/runner"
require_relative "outbox/probes/probe"
require_relative "outbox/probes/metrics"
require_relative "outbox/redis_client_factory"

module Sbmt
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def start
$stdout.puts AsciiArt.logo
$stdout.puts "Outbox/Inbox worker has been started"
$stdout.puts "Version: #{VERSION}"
$stdout.puts "Starting probes..."
Sbmt::Outbox::Probes::Probe.run_probes
Sbmt::Outbox::Probes::Metrics.run_metrics

worker.start
end
Expand Down
52 changes: 52 additions & 0 deletions lib/sbmt/outbox/probes/metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module Sbmt
module Outbox
module Probes
class Metrics
DEFAULT_YABEDA_PORT = 9090
DEFAULT_YABEDA_PATH = "/metrics"
class << self
def run_metrics
return unless autostart_yabeda_server?

if defined?(Yabeda)
$stdout.puts "Starting metrics http-server..."

start_webrick(
Yabeda::Prometheus::Mmap::Exporter::NOT_FOUND_HANDLER,
middlewares: {::Yabeda::Prometheus::Exporter => {path: DEFAULT_YABEDA_PATH}},
port: yabeda_port
)
end
end

private

def yabeda_port
Sbmt::Outbox.yaml_config.dig(:metrics, :port) || DEFAULT_YABEDA_PORT
end

def start_webrick(app, middlewares:, port:)
Thread.new do
::Rack::Handler::WEBrick.run(
::Rack::Builder.new do
middlewares.each do |middleware, options|
use middleware, **options
end
run app
end,
Host: "0.0.0.0",
Port: port
)
end
end

def autostart_yabeda_server?
Sbmt::Outbox.yaml_config.dig(:metrics, :enabled) || false
end
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/sbmt/outbox/probes/probe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Probe
DEFAULT_PROBE_PORT = 5555
class << self
def run_probes
return unless autostart_probe?

$stdout.puts "Starting probes..."

::HttpHealthCheck.run_server_async(
port: probe_port,
rack_app: HttpHealthCheck::RackApp.configure do |c|
Expand All @@ -31,6 +35,12 @@ def probe_port

Sbmt::Outbox.yaml_config.fetch(:probes).fetch(:port)
end

def autostart_probe?
value = Sbmt::Outbox.yaml_config.dig(:probes, :enabled)
value = true if value.nil?
value
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Outbox
VERSION = "6.3.1"
VERSION = "6.4.0"
end
end

0 comments on commit 06d6589

Please sign in to comment.