Skip to content

Commit

Permalink
Reinstate AA test ElasticSearch 6.7
Browse files Browse the repository at this point in the history
We recently ran an AA test for the Search team (#3053).

We are going to run it again, hence reinstating it in this PR!

The purpose of the A/A test is to test the % of allocation of traffic/sample population based on the current version of elastic (6.7) against itself. A (ES 6.7) vs A (ES6.7). The A/A is solely to identify how the approach allocates traffic. This will provide benchmark data to aid analysis in future AA tests.

This time around, the code will stay the same. We will use the same custom dimension and the variant split will still be 50/50. The only difference is that the custom dimension has been scoped as ‘user' as opposed to ‘session’ like it was last time. Scoping the custom dimension has already been done by a performance analyst.

We plan to deploy this on Thursday 17 August for 1 week.
  • Loading branch information
Rosa-Fox committed Aug 16, 2023
1 parent a7d8dd1 commit dde5947
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/controllers/ab_tests/elastic_search_aa_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module AbTests::ElasticSearchAaTestable
def elastic_search_aa_test
GovukAbTesting::AbTest.new(
"EsSixPointSeven",
dimension: 41,
allowed_variants: %w[A B Z],
control_variant: "Z",
)
end

def page_under_test?
request.path.include?("/search/all")
end

def set_requested_variant
@requested_variant = elastic_search_aa_test.requested_variant(request.headers)
@requested_variant.configure_response(response)
end
end
7 changes: 6 additions & 1 deletion app/controllers/finders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FindersController < ApplicationController
layout "finder_layout"
include AbTests::ElasticSearchAaTestable

before_action do
set_expiry(content_item)
Expand All @@ -12,6 +13,10 @@ def show
format.html do
raise UnsupportedContentItem unless content_item.is_finder?

if page_under_test?
set_requested_variant
end

if legacy_params_present?
transform_legacy_announcement_params_and_redirect if content_item.base_path == "/search/news-and-communications"
transform_legacy_publication_params_and_redirect if content_item.base_path == "/search/all"
Expand Down Expand Up @@ -58,7 +63,7 @@ class UnsupportedContentItem < StandardError; end

attr_reader :search_query

helper_method :facet_tags, :i_am_a_topic_page_finder, :result_set_presenter, :content_item, :signup_links, :filter_params, :facets
helper_method :facet_tags, :i_am_a_topic_page_finder, :result_set_presenter, :content_item, :signup_links, :filter_params, :facets, :page_under_test?

def redirect_to_destination
@redirect = content_item.redirect
Expand Down
6 changes: 6 additions & 0 deletions app/views/finders/_show_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<% end %>
</div>

<% if page_under_test? %>
<% content_for :meta_tags do %>
<%= @requested_variant.analytics_meta_tag.html_safe %>
<% end %>
<% end %>
<% if content_item.summary %>
<div class="govuk-grid-column-two-thirds">
<div class="metadata-summary ">
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/finder_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<% end %>
<meta name="govuk:base_title" content="<%= yield :meta_title %> - GOV.UK">
<meta name="govuk:scroll-tracker" content="" data-module="ga4-scroll-tracker"/>
<%= yield :meta_tags %>
</head>

<body class="<%= yield :body_classes %>">
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,52 @@
get :show, params: { slug: "lunch-finder" }
expect(response.status).to eq(406)
end

context "with AA test" do
%w[A B Z].each do |variant|
it "renders the #{variant} variant for /search/all pages" do
stub_content_store_has_item(
"/search/all",
all_content_finder,
)

@request.headers["GOVUK-ABTest-EsSixPointSeven"] = variant

get :show, params: { slug: "search/all" }

expect(response.header["Vary"]).to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).to include("EsSixPointSeven:#{variant}")
end

it "doesn't render the #{variant} for finders" do
stub_content_store_has_item(
"/lunch-finder",
lunch_finder,
)

@request.headers["GOVUK-ABTest-EsSixPointSeven"] = variant

get :show, params: { slug: "lunch-finder" }

expect(response.status).to eq(200)
expect(response.header["Vary"]).not_to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).not_to include("EsSixPointSeven:#{variant}")
end
end

it "should render the page without an AB test variant for search" do
stub_content_store_has_item(
"/search/all",
all_content_finder,
)

get :show, params: { slug: "search/all" }

expect(response.status).to eq(200)
expect(response.header["Vary"]).to eq("GOVUK-ABTest-EsSixPointSeven")
expect(response.body).not_to include("<meta name=\"govuk:ab-test\">")
end
end
end

describe "a finder content item with a default order exists" do
Expand Down

0 comments on commit dde5947

Please sign in to comment.