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 search #26056

Closed
wants to merge 3 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
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ val rss = application("rss")
.dependsOn(commonWithTests)
.aggregate(common)

val search = application("search")
.dependsOn(commonWithTests)
.aggregate(common)

val main = root()
// This evicts the version of
// "com.fasterxml.jackson.core:jackson-databind"
Expand All @@ -235,6 +239,7 @@ val main = root()
archive,
preview,
rss,
search,
)
.settings(
riffRaffUploadArtifactBucket := Some(
Expand Down
2 changes: 2 additions & 0 deletions riff-raff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ deployments:
template: frontend
sport:
template: frontend
search:
template: frontend
frontend-static:
type: aws-s3
parameters:
Expand Down
70 changes: 70 additions & 0 deletions search/app/AppLoader.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import akka.actor.ActorSystem
import http.{CommonFilters, CorsHttpErrorHandler}
import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents}
import com.softwaremill.macwire._
import common._
import common.Logback.{LogbackOperationsPool, LogstashLifecycle}
import contentapi.{CapiHttpClient, ContentApiClient, HttpClient}
import controllers.{HealthCheck, SearchController}
import dev.{DevAssetsController, DevParametersHttpRequestHandler}
import model.{ApplicationContext, ApplicationIdentity}
import play.api.ApplicationLoader.Context
import play.api.http.{HttpErrorHandler, HttpRequestHandler}
import play.api.{BuiltInComponentsFromContext, Environment}
import play.api.mvc.{ControllerComponents, EssentialFilter}
import play.api.routing.Router
import play.api.libs.ws.WSClient
import router.Routes

import scala.concurrent.ExecutionContext

class AppLoader extends FrontendApplicationLoader {
override def buildComponents(context: Context): FrontendComponents =
new BuiltInComponentsFromContext(context) with AppComponents
}

trait SearchControllers {
def contentApiClient: ContentApiClient
def wsClient: WSClient
def controllerComponents: ControllerComponents
implicit def appContext: ApplicationContext
lazy val searchController = wire[SearchController]
}

trait SearchServices {
def wsClient: WSClient
def environment: Environment
def actorSystem: ActorSystem
implicit def appContext: ApplicationContext
implicit val executionContext: ExecutionContext
lazy val capiHttpClient: HttpClient = wire[CapiHttpClient]
lazy val contentApiClient = wire[ContentApiClient]
}

trait AppComponents extends FrontendComponents with SearchControllers with SearchServices {

lazy val healthCheck = wire[HealthCheck]
lazy val devAssetsController = wire[DevAssetsController]
lazy val logbackOperationsPool = wire[LogbackOperationsPool]

override lazy val lifecycleComponents = List(
wire[LogstashLifecycle],
)

lazy val router: Router = wire[Routes]

lazy val appIdentity = ApplicationIdentity("search")

val applicationMetrics = ApplicationMetrics(
ContentApiMetrics.HttpTimeoutCountMetric,
ContentApiMetrics.ContentApiErrorMetric,
ContentApiMetrics.ContentApiRequestsMetric,
)

val frontendBuildInfo: FrontendBuildInfo = frontend.search.BuildInfo
override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters
override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler]
override lazy val httpErrorHandler: HttpErrorHandler = wire[CorsHttpErrorHandler]

def actorSystem: ActorSystem
}
13 changes: 13 additions & 0 deletions search/app/controllers/HealthCheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package controllers

import conf.{AllGoodCachedHealthCheck, NeverExpiresSingleHealthCheck}
import play.api.libs.ws.WSClient
import play.api.mvc.ControllerComponents

import scala.concurrent.ExecutionContext

class HealthCheck(wsClient: WSClient, val controllerComponents: ControllerComponents)(implicit
executionContext: ExecutionContext,
) extends AllGoodCachedHealthCheck(
NeverExpiresSingleHealthCheck("/search"),
)(wsClient, executionContext)
23 changes: 23 additions & 0 deletions search/app/controllers/SearchController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package controllers

import common.{GuLogging, ImplicitControllerExecutionContext}
import contentapi.ContentApiClient
import model.ApplicationContext
import play.api.libs.ws.WSClient
import play.api.mvc.{BaseController, ControllerComponents}

import scala.concurrent.Future

class SearchController(
contentApiClient: ContentApiClient,
ws: WSClient,
val controllerComponents: ControllerComponents,
)(implicit context: ApplicationContext)
extends BaseController
with GuLogging
with ImplicitControllerExecutionContext {

def search() = {
Action.async(Future.successful(Ok("ok")))
}
}
52 changes: 52 additions & 0 deletions search/conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

akka {
loggers = ["akka.event.Logging$DefaultLogger", "akka.event.slf4j.Slf4jLogger"]
loglevel = WARNING
actor {
default-dispatcher = {
fork-join-executor {
parallelism-factor = 1.0
parallelism-max = 24
}
}
java-futures = {
fork-join-executor {
parallelism-factor = 1.0
parallelism-max = 1
}
}
}
}

play {

http {
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
secret.key: ${APP_SECRET}
forwarded.trustedProxies = [ "0.0.0.0/0" ]
}

il8n {
langs: "en"
}

ws {
compressionEnabled: true

timeout {
#The maximum time to wait when connecting to the remote host (default is 120 seconds).
connection: 1000ms
#The maximum time the request can stay idle (connection is established but waiting for more data) (default is 120 seconds).
idle: 2000ms
#The total time you accept a request to take (it will be interrupted even if the remote host is still sending data) (default is 120 seconds).
request: 2000ms
}
}

application.loader = AppLoader
}

guardian: {
projectName: search
}
22 changes: 22 additions & 0 deletions search/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<configuration>

<contextName>frontend-onward</contextName>

<appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/frontend-onward.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/frontend-onward.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxHistory>7</maxHistory><totalSizeCap>512MB</totalSizeCap><maxFileSize>256MB</maxFileSize>
</rollingPolicy>

<encoder>
<pattern>%date [%thread] %-5level %logger{36} - %msg%n%xException</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="LOGFILE"/>
</root>

</configuration>
2 changes: 2 additions & 0 deletions search/conf/routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET /healthcheck controllers.HealthCheck.healthCheck()
GET /search controllers.SearchController.search()