Skip to content

Commit f096a0f

Browse files
committed
Exclude internal organisations from form count metrics
Internal orgs are used for GOV.UK Forms testing and should not appear in CloudWatch form count metrics published for reporting.
1 parent fa34024 commit f096a0f

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

app/services/metrics/form_count_service.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def form_counts_by_org_and_state
3030
counts_by_org_and_state = Form
3131
.where.not(state: :deleted)
3232
.left_joins(group_form: { group: :organisation })
33-
.group(Organisation.arel_table[:name], Form.arel_table[:state])
33+
.group(Organisation.arel_table[:name], Form.arel_table[:state], Organisation.arel_table[:internal])
3434
.count
3535

36-
counts_by_org_and_state.each_with_object(Hash.new(0)) do |((org_name, state), count), totals|
36+
counts_by_org_and_state.each_with_object(Hash.new(0)) do |((org_name, state, internal), count), totals|
37+
next if internal == true # Skip internal organisations for metrics
38+
3739
totals[[org_name || UNKNOWN_ORG, metric_state(state)]] += count
3840
end
3941
end

spec/services/metrics/form_count_service_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@
4747
service.publish_form_counts
4848
end
4949

50+
context "when an organisation is internal" do
51+
let(:internal_organisation) { create(:organisation, name: "Internal Org", slug: "internal-org", internal: true) }
52+
let(:internal_group) { create(:group, organisation: internal_organisation) }
53+
54+
before do
55+
create(:form, :with_group, group: internal_group, state: :draft)
56+
create(:form, :with_group, group: internal_group, state: :live, pages: [])
57+
end
58+
59+
it "excludes forms belonging to internal organisations" do
60+
expect(cloud_watch_client).to receive(:put_metric_data).with(
61+
namespace: "Forms",
62+
metric_data: contain_exactly(
63+
metric_datum(org: organisation.name, state: "draft", count: 1),
64+
metric_datum(org: organisation.name, state: "live", count: 2),
65+
metric_datum(org: organisation.name, state: "archived", count: 2),
66+
metric_datum(org: "Unknown", state: "draft", count: 1),
67+
),
68+
)
69+
70+
service.publish_form_counts
71+
end
72+
end
73+
5074
context "when CloudWatch returns an error" do
5175
before do
5276
allow(cloud_watch_client).to receive(:put_metric_data)

0 commit comments

Comments
 (0)