From eba8f5fca60978f157160bc11a71f08447daf53b Mon Sep 17 00:00:00 2001 From: Charlotte Date: Tue, 16 Jan 2024 17:10:18 +0000 Subject: [PATCH 1/2] feat: add split rendering switch and start sending traffic to article-rendering app for /Article endpoints --- common/app/common/configuration.scala | 1 + .../app/conf/switches/FeatureSwitches.scala | 11 +++++++++++ .../renderers/DotcomRenderingService.scala | 19 ++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/common/app/common/configuration.scala b/common/app/common/configuration.scala index bdb27ffa5d56..84a05a4a1ec5 100644 --- a/common/app/common/configuration.scala +++ b/common/app/common/configuration.scala @@ -150,6 +150,7 @@ class GuardianConfiguration extends GuLogging { object rendering { lazy val baseURL = configuration.getMandatoryStringProperty("rendering.baseURL") + lazy val articleBaseURL = configuration.getMandatoryStringProperty("article-rendering.baseURL") lazy val sentryHost = configuration.getMandatoryStringProperty("rendering.sentryHost") lazy val sentryPublicApiKey = configuration.getMandatoryStringProperty("rendering.sentryPublicApiKey") lazy val timeout = 2.seconds diff --git a/common/app/conf/switches/FeatureSwitches.scala b/common/app/conf/switches/FeatureSwitches.scala index bcd8f340a857..dd396e48504e 100644 --- a/common/app/conf/switches/FeatureSwitches.scala +++ b/common/app/conf/switches/FeatureSwitches.scala @@ -542,4 +542,15 @@ trait FeatureSwitches { sellByDate = Some(LocalDate.of(2024, 6, 5)), exposeClientSide = true, ) + + val SplitRenderingStack = Switch( + SwitchGroup.Feature, + "split-rendering-stack", + "If this switch is on, we will split DCR traffic between rendering stacks", + owners = Seq(Owner.withEmail("dotcom.platform@theguardian.com")), + safeState = Off, + // This is a random date in the future but this switch should be removed far before then + sellByDate = Some(LocalDate.of(2024, 6, 5)), + exposeClientSide = false, + ) } diff --git a/common/app/renderers/DotcomRenderingService.scala b/common/app/renderers/DotcomRenderingService.scala index 0ebf88a7137e..aabfb94807a0 100644 --- a/common/app/renderers/DotcomRenderingService.scala +++ b/common/app/renderers/DotcomRenderingService.scala @@ -5,7 +5,7 @@ import com.gu.contentapi.client.model.v1.{Block, Blocks, Content} import common.{DCRMetrics, GuLogging} import concurrent.CircuitBreakerRegistry import conf.Configuration -import conf.switches.Switches.CircuitBreakerSwitch +import conf.switches.Switches.{CircuitBreakerSwitch, SplitRenderingStack} import http.{HttpPreconnections, ResultWithPreconnectPreload} import model.Cached.{RevalidatableResult, WithoutRevalidationResult} import model.dotcomrendering._ @@ -55,6 +55,9 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload resetTimeout = Configuration.rendering.timeout * 4, ) + private val articleBaseURL = + if (SplitRenderingStack.isSwitchedOn) Configuration.rendering.articleBaseURL else Configuration.rendering.baseURL; + private[this] def postWithoutHandler( ws: WSClient, payload: String, @@ -232,7 +235,13 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload } val json = DotcomRenderingDataModel.toJson(dataModel) - post(ws, json, Configuration.rendering.baseURL + path, page.metadata.cacheTime) + + val baseURL = page match { + case _: LiveBlogPage => Configuration.rendering.baseURL + case _ => articleBaseURL + } + + post(ws, json, baseURL + path, page.metadata.cacheTime) } def getBlocks( @@ -355,7 +364,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload )(implicit request: RequestHeader): Future[Result] = { val dataModel = DotcomRenderingDataModel.forImageContent(imageContent, request, pageType, mainBlock) val json = DotcomRenderingDataModel.toJson(dataModel) - post(ws, json, Configuration.rendering.baseURL + "/Article", CacheTime.Facia) + post(ws, json, articleBaseURL + "/Article", CacheTime.Facia) } def getAppsImageContent( @@ -378,7 +387,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload val dataModel = DotcomRenderingDataModel.forMedia(mediaPage, request, pageType, blocks) val json = DotcomRenderingDataModel.toJson(dataModel) - post(ws, json, Configuration.rendering.baseURL + "/Article", CacheTime.Facia) + post(ws, json, articleBaseURL + "/Article", CacheTime.Facia) } def getGallery( @@ -390,7 +399,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload val dataModel = DotcomRenderingDataModel.forGallery(gallery, request, pageType, blocks) val json = DotcomRenderingDataModel.toJson(dataModel) - post(ws, json, Configuration.rendering.baseURL + "/Article", CacheTime.Facia) + post(ws, json, articleBaseURL + "/Article", CacheTime.Facia) } } From be5e3bfbe24c2e0f422ee773b3b015b917406010 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Wed, 17 Jan 2024 17:07:45 +0000 Subject: [PATCH 2/2] try expose switch to client side --- common/app/conf/switches/FeatureSwitches.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/app/conf/switches/FeatureSwitches.scala b/common/app/conf/switches/FeatureSwitches.scala index dd396e48504e..437ef0eb52c3 100644 --- a/common/app/conf/switches/FeatureSwitches.scala +++ b/common/app/conf/switches/FeatureSwitches.scala @@ -551,6 +551,6 @@ trait FeatureSwitches { safeState = Off, // This is a random date in the future but this switch should be removed far before then sellByDate = Some(LocalDate.of(2024, 6, 5)), - exposeClientSide = false, + exposeClientSide = true, ) }