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

Refs #28506 - fixed telemetry boot require #7271

Merged
merged 1 commit into from
Dec 19, 2019
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
8 changes: 0 additions & 8 deletions config/initializers/5_telemetry.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Set multiprocess-friendly data store
require 'prometheus/client'
require 'prometheus/client/data_stores/direct_file_store'
PROMETHEUS_STORE_DIR = File.join(Rails.root, 'tmp', 'prometheus')
FileUtils.mkdir_p(PROMETHEUS_STORE_DIR)
Prometheus::Client.config.data_store =
Prometheus::Client::DataStores::DirectFileStore.new(dir: PROMETHEUS_STORE_DIR)

# Foreman telemetry global setup.
telemetry = Foreman::Telemetry.instance
if SETTINGS[:telemetry] && (Rails.env.production? || Rails.env.development?)
Expand Down
7 changes: 7 additions & 0 deletions lib/foreman/telemetry_sinks/prometheus_sink.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module Foreman::TelemetrySinks
class PrometheusSink
PROMETHEUS_STORE_DIR = File.join(Rails.root, 'tmp', 'prometheus')

def initialize(opts = {})
require 'prometheus/client'
require 'prometheus/client/data_stores/direct_file_store'
# Set multiprocess-friendly data store
FileUtils.mkdir_p(PROMETHEUS_STORE_DIR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a global, should this be store_dir = opts[:store_dir] || File.join(Rails.root, 'tmp', 'prometheus')?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like introducing new option, then setting, then installer. Let's be opinionated here - these files will rarely be larger than few MBs so Rails cache is an ideal place. You can lost them and it gets regenerated on restart, no big deal too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a parameter to the method, which also allows unit testing. I wasn't calling for it to be configurable at the setting/installer level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the constant is not necessary as it doesn't need to be this exact dir, it's only a sane default, so why not to have the method more robust. I'm ok with this as well though.

Prometheus::Client.config.data_store =
Prometheus::Client::DataStores::DirectFileStore.new(dir: PROMETHEUS_STORE_DIR)
@prom = ::Prometheus::Client.registry
end

Expand Down