Skip to content

Additional Information

Bogdan Marc edited this page Sep 6, 2024 · 2 revisions

Coding standards

Rubocop should always return no errors or warnings.

Running the tests

rails test

Runtime Configuration environment variables

We use 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 DSN for sending reports to the PPD Sentry account None

Deployment

The detailed deployment mapping is described in deployment.yml. At the time of writing, using the new infrastructure, the deployment process is as follows:

  • commits to the dev-infrastructure branch will deploy the dev server
  • commits to the preprod branch will deploy the pre-production server
  • any commit on the prod branch will deploy the production server as a new release

If the commit is a "new" release, the deployment should be tagged with the same semantic version number matching the BREAKING.FEATURE.PATCH format, e.g. v1.2.3, the same as should be set in the /app/lib/version.rb; also, a short annotation summarising the updates should be included in the tag as well.

Once the production deployment has been completed and verified, please create a release on the repository using the same semantic version number. Utilise the Generate release notes from commit log option to create specific notes on the contained changes as well as the ability to diff agains the previous version.

entrypoint.sh features

  • Workaround to removing the PID lock of the Rails process in the event of the application crashing and not releasing the process.
  • Guards to ensure the required environment variables are set accordingly and trigger the build to fail noisily and log to the system.
  • Rails secret creation for SECRET_KEY_BASE assignment; see Runtime Configuration environment variables.

[^1]: With Docker 1.13.0 or greater, you can configure Docker to use different credential helpers for different registries.

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
  • 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.

Issues

Please add issues to the shared issues list

Clone this wiki locally