Skip to content

Commit

Permalink
Merge pull request #451 from epimorphics/issue/449-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 8661fa2 + 4955cd2 commit 90b8c9d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@

## 1.7.5 - 2024-09

- (Dan) Updates Welsh translation to the official Welsh translation [GH-435](https://github.com/epimorphics/ukhpi/issues/435)
- (Jon) Created a `local` makefile target to allow for local development without
asset compilation
- (Jon) Updated the puma-stats to display in the footer while in development
[GH-449](https://github.com/epimorphics/ukhpi/issues/449)
- (Jon) Updated the application exceptions controller to instrument the
`ActiveSupport::Notifications` for internal errors albeit this is not
currently in use in the application
[GH-449](https://github.com/epimorphics/ukhpi/issues/449)
- (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-449](https://github.com/epimorphics/ukhpi/issues/449)
- (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-449](https://github.com/epimorphics/ukhpi/issues/449)
- (Dan) Updates Welsh translation to the official Welsh translation
[GH-435](https://github.com/epimorphics/ukhpi/issues/435)
- (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
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ image: auth
lint: assets
@./bin/bundle exec rubocop

local:
@echo "Installing bundler packages ..."
@./bin/bundle install
@echo "Installing yarn packages ..."
@yarn install
@echo "Starting local server ..."
@./bin/rails server -p ${PORT}

publish: image
@echo Publishing image: ${REPO}:${TAG} ...
@docker tag ${NAME}:${TAG} ${REPO}:${TAG} 2>&1
Expand Down
5 changes: 0 additions & 5 deletions app/views/common/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@
%p.u-muted--footer
= t('common.footer.application_release')
= Version::VERSION
- if Rails.env.development?
%pre
[puma stats:
= JSON.pretty_generate(JSON.parse(Puma.stats, symbolize_names: true))
, time: #{Time.now}]
5 changes: 5 additions & 0 deletions app/views/common/_puma_stats.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

%div
%pre
%code
= "[#{JSON.pretty_generate(puma_stats: JSON.parse(Puma.stats), time: Time.now)}]"
1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@


= render partial: 'common/footer'
= render partial: 'common/puma_stats' if Rails.env.development?
4 changes: 4 additions & 0 deletions config/initializers/prometheus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
docstring: 'Histogram of response times for API requests',
buckets: Prometheus::Client::Histogram.exponential_buckets(start: 0.005, 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')
13 changes: 10 additions & 3 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
min_threads_count = ENV.fetch('RAILS_MIN_THREADS', max_threads_count)
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch('PORT', 3000)
# Specifies the `port` that Puma will listen on to receive requests;
# default is 3000.
port ENV.fetch('PORT', 3000)

# Specifies the `metrics_port` that Puma will listen on to export metrics;
# default is 9393.
# metrics_port = ENV.fetch('METRICS_PORT', 9393)

# Specifies the `environment` that Puma will run in.
#
Expand Down Expand Up @@ -51,7 +55,10 @@

# 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:#{metrics_port}" if Rails.env.development?

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

0 comments on commit 90b8c9d

Please sign in to comment.