Giter Site home page Giter Site logo

forms-runner's Introduction

GOV.UK Forms Runner Tests

GOV.UK Forms is a service for creating forms. GOV.UK Forms Runner is a an application which displays those forms to end users so that they can be filled in. It's a Ruby on Rails application without a database. It uses Redis for state.

Before you start

To run the project, you will need to install:

  • Ruby - we use version 3 of Ruby. Before running the project, double check the .ruby-version file to see the exact version.
  • Node.js - the frontend build requires Node.js. We use Node 20 LTS versions.

We recommend using a version manager to install and manage these, such as:

Getting started

Installing for the first time

# 1. Clone the git repository and change directory to the new folder
git clone [email protected]:alphagov/forms-runner.git
cd forms-runner

# 2. Run the setup script
./bin/setup

Running the app

You can either run the development task:

# Run the foreman dev server. This will also start the frontend dev task
./bin/dev

or run the rails server:

# Run a local Rails server
./bin/rails server

# When running the server, you can use any of the frontend tasks, e.g.:
npm run dev

You will also need to run the forms-api service, as this app needs the API to create and access forms.

Development tools

Running the tests

The app tests are written with rspec-rails, and you can run them with:

bundle exec rspec

Linting

We use RuboCop GOV.UK for linting code. To autocorrect issues, run:

bundle exec rubocop -A

We also use the i18n-tasks tool to keep our locales files in a consistent order. When the tests run, they will check if the locale files are normalised and fail if they are not. To fix the locale files automatically, you can run:

bundle exec i18n-tasks normalize

On GitHub pull requests, we also check our dependencies for security issues using [bundler-audit]. You can run this locally with:

bundle audit

Running tasks with Rake

We have a Rakefile that is set up to follow the GOV.UK conventions for Rails applications.

To lint your changes and run tests with one command, you can run:

bundle exec rake

Changing configuration

Changing settings

Refer to the the config gem to understand the file based settings loading order.

To override file based settings through Machine based env variables settings, you can run:

cat config/settings.yml
file
  based
    settings
      env1: 'foo'
export SETTINGS__FILE__BASED__SETTINGS__ENV1="bar"
puts Settings.file.based.setting.env1
bar

Refer to the settings file for all the settings required to run this app

Environment variables

Name Purpose
REDIS_URL The URL for Redis (optional)

Feature flags

This repo supports the ability to set up feature flags. To do this, add your feature flag in the settings file under the features property. eg:

features:
  some_feature: true

You can then use the feature service to check whether the feature is enabled or not. Eg. FeatureService.enabled?(:some_feature).

You can also nest features:

features:
  some:
    nested_feature: true

And check with FeatureService.enabled?("some.nested_feature").

Testing with features

You can also tag RSpec tests with feature_{name}: true. This will turn that feature on just for the duration of that test.

Configuring Redis

You can enable Redis sessions by providing the Redis connection URL in the environment variable REDIS_URL.

Configuring GOV.UK Notify

We use GOV.UK Notify to send emails from our apps.

If you want to test the Notify functionality locally, you will need to get a test API key from the Notify service. Add it as an environment variable under SETTINGS__GOVUK_NOTIFY__API_KEY or add it to a local config file:

# config/settings.local.yml

# Settings for GOV.UK Notify api & email templates
govuk_notify:
  api_key: <API key from Notify>

Configuring Sentry

We use Sentry to catch and alert us about exceptions in production apps.

We currently have a very basic setup for Sentry in this repo for testing, which we will continue to build upon.

In order to use Sentry locally, you will need to:

  1. Sign in to Sentry using your work Google account.
  2. Create a new project.
  3. Add the Sentry DSN to your environment as SETTINGS__SENTRY__DSN, or add it to a local config file:
# config/settings.local.yml

sentry:
  DSN: <DSN from Sentry>

If you want to deliberately raise an exception to test, uncomment out the triggers in the Sentry initializer script. Whenever you run the app, errors will be raised and should also come through on Sentry.

Deploying apps

The forms-runner app is containerised (see Dockerfile) and can be deployed in the same way you'd normally deploy a containerised app.

We host our apps using Amazon Web Services (AWS). You can read about how deployments happen on our team wiki, if you have access.

Logging

  • You should configure HTTP access logs in the application config, using Lograge.
  • You should use the LogEventService and EventLogger to create any custom log messages. This is independent of any Lograge configuration.
  • The output format is JSON, using the JsonLogFormatter to enable simpler searching and visbility, especially in Splunk.
  • Do not use log_tags, as it breaks the JSON formatting produced by Lograge.

Updating Docker files

To update the version of Alpine Linux and Ruby used in the Dockerfile, use the update_app_versions.sh script in forms-deploy

Working with pipelines

You can work with the forms-runner pipelines in different environments using Rake tasks

Pause

To pause the pipeline in an environment, run

rake pipeline:ENV:pause

where ENV is the name of the environment you want to work with, for example dev or prod.

Unpause

To unpause the pipeline in an environment, run

rake pipeline:ENV:unpause

where ENV is the name of the environment you want to work with, for example dev or prod.

Find out if a pipeline is paused

To find out if the pipeline in an environment is paused, run

rake pipeline:ENV:status

where ENV is the name of the environment you want to work with, for example dev or prod.

Support

Raise a GitHub issue if you need support.

How to contribute

We welcome contributions - please read CONTRIBUTING.md and the alphagov Code of Conduct before contributing.

License

We use the MIT License.

forms-runner's People

Contributors

0atman avatar alice-carr avatar aliuk2012 avatar ap-hunt avatar c-harry avatar cadmiumcat avatar chao-xian avatar danielburnley avatar danworth avatar davidbiddle avatar dependabot[bot] avatar hannahkc avatar james-sheppard-gov-uk avatar jamie-o-wilkinson avatar lfdebrux avatar rkotyank avatar samjamcul avatar seaemsi avatar stephencdaly avatar thomasiles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forms-runner's Issues

Apache Bench results

❯ ab -n 10000 -c 100 https://submit.staging.forms.service.gov.uk/preview-form/2/apply-for-a-pet-license/2
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking submit.staging.forms.service.gov.uk (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        
Server Hostname:        submit.staging.forms.service.gov.uk
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        X25519 253 bits
TLS Server Name:        submit.staging.forms.service.gov.uk


Concurrency Level:      100
Time taken for tests:   119.771 seconds
Complete requests:      10000
Failed requests:        6096
   (Connect: 0, Receive: 0, Length: 6096, Exceptions: 0)
Non-2xx responses:      6096
Total transferred:      92587914 bytes
HTML transferred:       81758564 bytes
Requests per second:    83.49 [#/sec] (mean)
Time per request:       1197.714 [ms] (mean)
Time per request:       11.977 [ms] (mean, across all concurrent requests)
Transfer rate:          754.92 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        9   86  69.8     75     339
Processing:     2 1095 1310.7     75    3604
Waiting:        2 1090 1314.4     62    3604
Total:         13 1181 1254.4    197    3617

Percentage of the requests served within a certain time (ms)
  50%    197
  66%   2421
  75%   2574
  80%   2674
  90%   2927
  95%   3054
  98%   3179
  99%   3358
 100%   3617 (longest request)
``

Configure Frontend build

This should include anything we're likely to need in both forms-admin and forms-runner, but not anything more specific. We already have a default Rollup build but this may also need a but of configuring.

This should include:

  • babel for transpiling
  • a browserslist configuration (start with a sensible default, we will adjust this later once we have a better idea of our user stats)
  • jest for unit testing
  • cypress for end-to-end testing
  • style and js linting
  • autoprefixer
  • dart-sass instead of ruby-sass
  • install govuk-frontend
  • style and js formatting

Add basic analytics events

Trello card: https://trello.com/c/d9eXIVLO/438-ensure-minimum-user-insight-events-are-being-tracked-in-logs

Add entries to the logs for some core user journey events. To start, log when a user:

  • Visits the root form URL
  • Saves the first page of a form
  • Saves subsequent pages of the form
  • Hits the Change Your Answers page
  • Changes an answer (i.e. saves a page after going back from the Change links on the Change Your Answers page
  • Submits the form

The logged information will be:

  • event name
  • request URL
  • HTTP method
  • form name
  • question text (if saving an answer to a question)
  • user agent string

Add Sentry

We want to use sentry for exception tracking, we will need to set up a sentry account and ensure the service can send exceptions correctly

Allow form completers to check and change their answers

  • The user can see a summary of their answers and the questions they relate to
  • The user can click on the "change" link to the side and be taken to the page
  • Having clicked on the "change" link, the "back" button in the page takes them back to the check your answers page
  • When submitting updated information, they're redirected back to the check your answers page

Add friendly error pages

This should include:
404 for page not found
500 for unexpected errors
Service unavailable (in case we need to take the service down temporarily)
Notify error (special case of the 500 error with some extra text about the submission failing)

Prevent search indexing

We need to prevent search indexing so that users don't accidentally access the form pages directly - see Ensure users start their journey on GOV.UK in the Service Manual. We can either do this with a meta tag in the view or by adding the X-Robots-Tag HTTP header.

We want this to apply to all pages on the runner. Adding the header in AppliccationController will probably make require less maintenance in the long run, as we are marginally more likely to add new layouts than we are to add new controllers that don't inherit from this one.

Fix asset rendering bug

Currently the govuk-frontend assets (most noticeably the GDS Transport font) aren't being compiled by the asset build. This means that the fonts and assets will load correctly on a local machine, but return 404s on the dev server.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.