Skip to content

Record submission counts#2147

Open
theseanything wants to merge 5 commits into
mainfrom
theseanything/submission-number-metrics
Open

Record submission counts#2147
theseanything wants to merge 5 commits into
mainfrom
theseanything/submission-number-metrics

Conversation

@theseanything

@theseanything theseanything commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Records a SubmissionCount metric using an OpenTelemetry counter, incremented as each submission is created and exported through the OTel collector (metrics support enabled in govuk-forms/forms-deploy#2182).

This allows as to track platform usage over time without manual reporting and is one of our key KPIs used to drive product development. We get stats exported every minute.

We are using Otel instead of standard CloudWatch Metrics as it's significantly cheaper. Allows us to have high cardinality and get granular submission counts per form.

Submissions to automated test forms (capybara, smoke test and s3 test forms) are labelled with mode test, so dashboards can exclude them without repeating name-based filters in every query.

Trello card: https://trello.com/c/b3cNvzu5/3136-record-kpis-in-cloudwatch

tested in dev.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot stopped reviewing on behalf of theseanything due to an error June 4, 2026 19:38
private

def submission_counts_by_form_id
Submission.where(mode: "form").group(:form_id).count

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I think the submission counts collected by Anne exclude submissions to test forms by our end to end tests and smoke tests. Ought we do the same here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's okay - submissions are grouped by form id, so we can filter them out after.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end-to-end tests create a form, submit it and then delete it. I don't know if we'll easily have the form ids to exclude and including known form ids would be tricky too, i think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I agree with what Tom says, it feels like it will be easier to filter out before sending to CloudWatch, we can use the same criteria Anne uses currently in Splunk:

form_name!=capybara* form_name!=*smoke* form_name!=s3*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this PR to now use OTel, and subsequently label these forms as mode "test" - so they can easily be filtered out.

@theseanything theseanything force-pushed the theseanything/submission-number-metrics branch from 82471a3 to 70c1c91 Compare June 18, 2026 14:21
@theseanything theseanything force-pushed the theseanything/submission-number-metrics branch from 70c1c91 to f5c3ea3 Compare July 2, 2026 15:03
@theseanything theseanything changed the title Publish submission counts metrics to CloudWatch Publish submission counts metrics Jul 3, 2026
@theseanything theseanything force-pushed the theseanything/submission-number-metrics branch 3 times, most recently from 1a4b8c2 to 26b26d0 Compare July 6, 2026 10:26
@theseanything theseanything changed the title Publish submission counts metrics Record submission counts Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Comment thread app/services/form_submission_service.rb Outdated
Record counts with an incrementing counter at submission creation
time, exported via PeriodicMetricReader, instead of periodically
aggregating submission counts from the database.
Submissions to forms used for automated platform testing (capybara,
smoke test and s3 test forms) were counted with their real mode,
mixing them in with genuine user submissions. Label them as "test"
so dashboards can exclude them without name-based filters.
The submission count metric was incremented when the submission record
was created, before the delivery job was enqueued. If enqueueing failed
the submission was destroyed but the counter had already been bumped,
inflating the KPI. Move the metric call to after the enqueue block so it
only counts submissions that were successfully queued for delivery.
Use OpenTelemetry semantic conventions for the counter name,
unit and attribute keys so the metric is consistent with other
instrumented services and standard dashboards.
The deployment.environment.name attribute is upserted by the OTel
collector, so we don't need to manually add an environment label to
every metric we record.
@theseanything theseanything force-pushed the theseanything/submission-number-metrics branch from ace0f57 to 760424f Compare July 6, 2026 13:53
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2147.submit.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants