Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout on metric HTTP requests #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions bin/que
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require "ostruct"
require "que"
require "rack"
require "prometheus/middleware/exporter"
require "rack-timeout"

$stdout.sync = true

Expand Down Expand Up @@ -54,6 +55,10 @@ OptionParser.new do |opts|
options.timeout = timeout
end

opts.on("--metrics-request-timeout [TIMEOUT]", Integer, "Max duration (in seconds) for metrics HTTP requests to be served") do |timeout|
options.metrics_request_timeout = timeout
end

opts.on("-v", "--version", "Show Que version") do
require "que"
$stdout.puts "Que version #{Que::Version}"
Expand Down Expand Up @@ -83,12 +88,13 @@ rescue LoadError
$stdout.puts "Could not load file '#{file}'"
end

log_level = options.log_level || ENV["QUE_LOG_LEVEL"] || "info"
queue_name = options.queue_name || ENV["QUE_QUEUE"] || Que::Worker::DEFAULT_QUEUE
wake_interval = options.wake_interval || ENV["QUE_WAKE_INTERVAL"]&.to_f || Que::Worker::DEFAULT_WAKE_INTERVAL
cursor_expiry = options.cursor_expiry || wake_interval
worker_count = options.worker_count || 1
timeout = options.timeout
log_level = options.log_level || ENV["QUE_LOG_LEVEL"] || "info"
queue_name = options.queue_name || ENV["QUE_QUEUE"] || Que::Worker::DEFAULT_QUEUE
wake_interval = options.wake_interval || ENV["QUE_WAKE_INTERVAL"]&.to_f || Que::Worker::DEFAULT_WAKE_INTERVAL
cursor_expiry = options.cursor_expiry || wake_interval
worker_count = options.worker_count || 1
timeout = options.timeout
metrics_timeout = options.metrics_request_timeout || ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] || 30

Que.logger ||= Logger.new(STDOUT)

Expand Down Expand Up @@ -130,6 +136,7 @@ if options.metrics_port

app = Rack::URLMap.new(
"/" => Rack::Builder.new do
use Rack::Timeout, service_timeout: metrics_timeout
use Que::Middleware::WorkerCollector, worker_group: worker_group
use Prometheus::Middleware::Exporter

Expand All @@ -138,6 +145,7 @@ if options.metrics_port
"/queue" => Rack::Builder.new do
registry = Prometheus::Client::Registry.new

use Rack::Timeout, service_timeout: metrics_timeout
use Que::Middleware::QueueCollector, registry: registry
use Prometheus::Middleware::Exporter, registry: registry

Expand Down
1 change: 1 addition & 0 deletions que.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "prometheus-client"

spec.add_dependency "rack", "~> 2.0"
spec.add_dependency "rack-timeout", "~> 0.6"

spec.add_runtime_dependency "activesupport"
end