Skip to content
Andrew Pickin edited this page Oct 11, 2024 · 10 revisions

UK House Price Index (UKHPI) open data application

This is the repo for the application that presents UKHPI open data on behalf of Land Registry (England and Wales), Registers of Scotland, Land and Property Services (Northern Ireland) and the UK Office for National Statistics (ONS).

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

Development work was carried out by Epimorphics Ltd, funded by HM Land Registry.

Code in this repository is open-source under the MIT license. The UKHPI data itself is freely available under the terms of the Open Government License

Operator Notes

Runtime Configuration environment variables

A number of environment variables to determine the runtime behaviour of the application:

name description default value
API_SERVICE_URL The base URL from which data is accessed, including the HTTP scheme eg. None
http://localhost:8888 if running a data-api service locally
http://data-api:8080 if running a data-api docker image locally
SECRET_KEY_BASE See description.
For development mode a acceptable value is already configured; in production mode, this should be set to the output of rails secret.
This is handled automatically when starting a docker container, or the server make target
SENTRY_API_KEY The Data Source Name (DSN) for sending reports to the Sentry account None

Prometheus Metrics

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.

Developer Notes

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 toInternally, 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 confi 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.