Skip to content

Commit

Permalink
Merge pull request #138 from epimorphics/issue/135-task-prometheus-me…
Browse files Browse the repository at this point in the history
…trics-update

Task: Prometheus Metrics - Update
  • Loading branch information
jonrandahl authored Sep 18, 2024
2 parents 39fa0b4 + 042471f commit f35330c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@ including the SPARQL Qonsole

## 1.8.0 - 2024-09

- (Bogdan) Updated both english and welsh copies of the accessibility statement [GH-136](https://github.com/epimorphics/lr-landing/issues/136)
- (Jon) Create a `config/initializers/load_notification_subscribers.rb` file to
load all the notification subscribers in the application so that they are
registeredly correctly
[GH-135](https://github.com/epimorphics/lr-landing/issues/135)
- (Jon) Updated the application exceptions controller to instrument the
`ActiveSupport::Notifications` for internal errors
[GH-135](https://github.com/epimorphics/lr-landing/issues/135)
- (Jon) Updated `config/initializers/prometheus.rb` to include the `Middleware
instrumentation` fix for the 0 memory bug by notifying Action Dispatch
subscribers on Prometheus initialise
[GH-135](https://github.com/epimorphics/lr-landing/issues/135)
- (Jon) Updated `config/puma.rb` to include metrics plugin and port information
for the metrics endpoint as environment variable, with default, to enable
running multiple sibling HMLR apps locally if needed without port conflicts
[GH-135](https://github.com/epimorphics/lr-landing/issues/135)
- (Jon) Updated the `lr_common_styles` gem to the latest 1.9.9 patch release.
- (Bogdan) Updated both english and welsh copies of the accessibility statement
[GH-136](https://github.com/epimorphics/lr-landing/issues/136)
- (Jon) Moved all mirrored configuration settings from individual environments
into the application configuration to reduce the need to manage multiple
sources of truth
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ GEM
json
lograge
railties
lr_common_styles (1.9.8)
lr_common_styles (1.9.9)
bootstrap-sass (~> 3.4.0)
font-awesome-rails (~> 4.7.0.1)
govuk_elements_rails (~> 2.0.0)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def change_default_caching_policy
# @param [Exception] exp the exception that caused the error
# @return [ActiveSupport::Notifications::Event] provides an object-oriented
# interface to the event
#!IMPORTANT: This method is not used in the codebase and is only here for reference
def instrument_internal_error(exception)
ActiveSupport::Notifications.instrument('internal_error.application', exception: exception)
end
Expand Down
4 changes: 2 additions & 2 deletions app/subscribers/action_dispatch_prometheus_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ActionDispatchPrometheusSubscriber < ActiveSupport::Subscriber
attach_to :action_controller

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def process_action(_event)
mem = GetProcessMem.new
Prometheus::Client.registry
Expand Down Expand Up @@ -59,5 +59,5 @@ def process_action(_event)
}
)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
end
6 changes: 6 additions & 0 deletions config/initializers/load_notification_subscribers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# Load all the notification subscribers in the application so that they are registered
Dir[Rails.root.join('app', 'subscribers', '**', '*_subscriber.rb')].sort.each do |source|
require source
end
4 changes: 4 additions & 0 deletions config/initializers/prometheus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
docstring: 'Histogram of back-end API response times',
buckets: Prometheus::Client::Histogram.exponential_buckets(start: 0.0005, count: 16)
)

# Middleware instrumentation
# This fixes the 0 memory bug by notifying Action Dispatch subscribers on Prometheus initialise
ActiveSupport::Notifications.instrument('process_middleware.action_dispatch')
7 changes: 7 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

# Uncomment the following line once ruby is updated to 2.7 or greater to allow
# the use of the puma-metrics plugin as we're using puma 6.0.0 or greater
# Additional metrics from the Puma server to be exposed in the /metrics endpoint
# plugin :metrics
# Bind the metric server to "url". "tcp://" is the only accepted protocol.
# metrics_url 'tcp://0.0.0.0:9393'

# Use a custom log formatter to emit Puma log messages in a JSON format
log_formatter do |str|
{
Expand Down

0 comments on commit f35330c

Please sign in to comment.