Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to forward DCR article traffic to new article-rendering app #26816

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/app/common/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions common/app/conf/switches/FeatureSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]")),
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 = true,
)
}
19 changes: 14 additions & 5 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
}
}

Expand Down
Loading