Skip to content
Jon R. Humphrey edited this page Sep 17, 2024 · 13 revisions

HMLR linked-data applications landing site

This repo provides the landing page experience for visitors to landregistry.data.gov.uk. The landing page provides links to the various open data services, and hosts the qonsole app, which allows users to run SPARQL queries against the linked-data dataset.

Please see the other repositories in the HM Land Registry Open Data project for more details.

Operator Notes

Runtime Configuration environment variables

We can use a number of environment variables to determine the runtime behaviour of the application while developing the codebase locally:

name description
SENTRY_API_KEY The Sentry DSN client key for the lr-dgu-landing Sentry app

Prometheus monitoring

Prometheus is set up to provide metrics on the /metrics endpoint. The following metrics are recorded:

  • api_status (counter) Response from data API, labelled by response status code
  • api_requests (counter) Count of requests to the data API, labelled by result success/failure
  • api_connection_failure (counter) Could not connect to back-end data API, labelled by message
  • api_service_exception (counter) The response from the back-end data API was not processed, labelled by message
  • internal_application_error (counter) Unexpected events and internal error count, labelled by message
  • memory_used_mb (gauge) Process memory usage in megabytes
  • process_threads (gauge) The number of currently threads, labelled by status:
    • "aborting": If this thread is aborting
    • "sleep": Returned if this thread is sleeping or waiting on I/O
    • "run": When this thread is executing
    • "false": When this thread is terminated normally
    • "nil": If the thread is terminated with an exception
  • api_response_times (histogram) Histogram of response times of successful API calls.

Internally, we use ActiveSupport Notifications to emit events which are monitored and collected by the Prometheus store. Relevant pieces of the app include:

  • config/initializers/prometheus.rb Defines the Prometheus counters that the app knows about, and registers them in the metrics store (see above)
  • config/initializers/load_notification_subscribers.rb Some boiler-plate code to ensure that all of the notification subscribers are loaded when the app starts
  • app/subscribers Folder where the subscribers to the known ActiveSupport notifications are defined. This is where the transform from ActiveSupport::Notification to Prometheus counter or gauge is performed.

In addition to the metrics we define, there is a collection of standard metrics provided automatically by the Ruby Prometheus client

To test Prometheus when developing locally, there needs to be a Prometheus server running. Tip for Linux users: do not install the Prometheus apt package. This starts a locally running daemon with a pre-defined configuration, which is useful when monitoring the machine on which the server is running. A better approach for testing Prometheus is to download the server package and run it locally, with a suitable configuration. A basic config for monitoring a Rails application is provided in test/prometheus/dev.yml.

Using this approach, and assuming you install your local copy of Prometheus into ~/apps, a starting command line would be something like:

~/apps/prometheus/prometheus-2.32.1.linux-amd64/prometheus \
  --config.file=test/prometheus/dev.yml \
  --storage.tsdb.path=./tmp/metrics2

Something roughly equivalent should be possible on Windows and Mac as well.

Developer Notes