Module: Bigcommerce::Prometheus::Configuration

Included in:
Bigcommerce::Prometheus
Defined in:
lib/bigcommerce/prometheus/configuration.rb

Overview

General configuration for prometheus integration

Constant Summary collapse

VALID_CONFIG_KEYS =
{
  logger: nil,
  client_custom_labels: nil,
  client_max_queue_size: 10_000,
  client_thread_sleep: 0.5,
  enabled: true,
  puma_collection_frequency: 30,
  puma_process_label: 'web',
  resque_collection_frequency: 30,
  resque_process_label: 'resque',
  server_host: '0.0.0.0',
  server_port: PrometheusExporter::DEFAULT_PORT,
  server_timeout: PrometheusExporter::DEFAULT_TIMEOUT,
  server_prefix: PrometheusExporter::DEFAULT_PREFIX,
  web_collectors: [],
  web_type_collectors: []
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Whenever this is extended into a class, setup the defaults



47
48
49
50
51
52
53
# File 'lib/bigcommerce/prometheus/configuration.rb', line 47

def self.extended(base)
  if defined?(Rails)
    Bigcommerce::Prometheus::Integrations::Railtie.config.before_initialize { base.reset }
  else
    base.reset
  end
end

Instance Method Details

#configure {|_self| ... } ⇒ Bigcommerce::Prometheus::Configuration

Yield self for ruby-style initialization

Yields:

  • (_self)

Yield Parameters:

Returns:



61
62
63
64
65
# File 'lib/bigcommerce/prometheus/configuration.rb', line 61

def configure
  reset unless @configured
  yield self
  @configured = true
end

#optionsHash

Return the current configuration options as a Hash

Returns:

  • (Hash)


72
73
74
75
76
77
78
# File 'lib/bigcommerce/prometheus/configuration.rb', line 72

def options
  opts = {}
  VALID_CONFIG_KEYS.each_key do |k|
    opts.merge!(k => send(k))
  end
  opts
end

#process_nameString

Returns:

  • (String)


99
100
101
# File 'lib/bigcommerce/prometheus/configuration.rb', line 99

def process_name
  @process_name ||= ENV.fetch('PROCESS', 'unknown')
end

#resetObject

Set the default configuration onto the extended class



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bigcommerce/prometheus/configuration.rb', line 83

def reset
  VALID_CONFIG_KEYS.each do |k, v|
    send("#{k}=".to_sym, v)
  end
  determine_logger
  self.enabled = ENV.fetch('PROMETHEUS_ENABLED', 1).to_i.positive?
  self.server_host = ENV.fetch('PROMETHEUS_SERVER_HOST', '0.0.0.0').to_s
  self.server_port = ENV.fetch('PROMETHEUS_SERVER_PORT', PrometheusExporter::DEFAULT_PORT).to_i

  self.puma_process_label = ENV.fetch('PROMETHEUS_PUMA_PROCESS_LABEL', 'web').to_s
  self.puma_collection_frequency = ENV.fetch('PROMETHEUS_PUMA_COLLECTION_FREQUENCY', 30).to_i
  self.web_type_collectors = []
end