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 Sidekiq Prometheus instrumentation #255

Merged
merged 1 commit into from
Aug 12, 2022
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
2 changes: 1 addition & 1 deletion lib/govuk_app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# This require is deprecated and should be removed on next major version bump
# and should be required by applications directly.
require "govuk_app_config/govuk_unicorn"
require "govuk_app_config/govuk_prometheus_exporter"

if defined?(Rails)
require "govuk_app_config/govuk_prometheus_exporter"
require "govuk_app_config/govuk_logging"
require "govuk_app_config/govuk_content_security_policy"
require "govuk_app_config/railtie"
Expand Down
34 changes: 28 additions & 6 deletions lib/govuk_app_config/govuk_prometheus_exporter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
module GovukPrometheusExporter
def self.should_configure
ENV["GOVUK_PROMETHEUS_EXPORTER"] == "true" && !(defined?(Rails) && Rails.env == "test")
end

def self.configure
unless Rails.env == "test" || (ENV["GOVUK_PROMETHEUS_EXPORTER"]) != "true"
require "prometheus_exporter"
require "prometheus_exporter/server"
require "prometheus_exporter/middleware"
return unless should_configure

require "prometheus_exporter"
require "prometheus_exporter/server"
require "prometheus_exporter/middleware"

if defined?(Sidekiq)
Sidekiq.configure_server do |config|
require "prometheus_exporter/instrumentation"
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
config.on :startup do
PrometheusExporter::Instrumentation::Process.start(type: "sidekiq")
PrometheusExporter::Instrumentation::SidekiqProcess.start
PrometheusExporter::Instrumentation::SidekiqQueue.start
PrometheusExporter::Instrumentation::SidekiqStats.start
end
end
end

server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start
server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start

if defined?(Rails)
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
end
Expand Down