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

Upgrade/play 2.6 #205

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .travis-jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is used to configure the sbt instance that Travis launches

-XX:MaxMetaspaceSize=512M
-XX:+UseG1GC
-XX:+UseCompressedOops
-XX:+UseStringDeduplication
-Xss2M
-Xms1536M
-Xmx1536M
27 changes: 18 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: scala

sudo: false

jdk:
- oraclejdk8

scala:
- 2.11.8
env:
- SBT_OPTS="-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:PermSize=256m -XX:MaxPermSize=512m -Xms128m -Xmx512m" JAVA_OPTS="-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1024m"
- 2.11.11

addons:
postgresql: "9.3"
Expand All @@ -17,16 +17,25 @@ before_script:
- psql -c "GRANT ALL PRIVILEGES ON DATABASE octoparts_test to octoparts_app;" -U postgres

script:
- sbt clean compile test:compile
- sbt coverage test
- find $HOME/.sbt -name "*.lock" -type f -delete && find $HOME/.ivy2/cache -name "*[\[\]\(\)]*.properties" -type f -delete
- sbt -jvm-opts .travis-jvmopts test:compile
- sbt -jvm-opts .travis-jvmopts coverage test

after_success:
- sbt coverageReport coverageAggregate coveralls

sudo: false

cache:
directories:
- $HOME/.sbt
- $HOME/.sbt/0.13
- $HOME/.sbt/boot/scala*
- $HOME/.sbt/cache
- $HOME/.sbt/launchers
- $HOME/.ivy2
- $HOME/.coursier

before_cache:
- du -h -d 1 $HOME/.ivy2/
- du -h -d 2 $HOME/.sbt/
- du -h -d 4 $HOME/.coursier/
- find $HOME/.sbt -name "*.lock" -type f -delete
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete
- find $HOME/.coursier/cache -name "*.lock" -type f -delete
4 changes: 2 additions & 2 deletions app/com/m3/octoparts/future/RichFutureWithTimeout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ object RichFutureWithTimeout {
private val timeoutEC = try {
actorSystem.dispatchers.lookup("contexts.future-timeout")
} catch {
// for tests
case NonFatal(e) if Play.maybeApplication.fold(false)(_.mode == Mode.Test) => actorSystem.dispatcher
// Fallback to actor system dispatcher
case NonFatal(e) => actorSystem.dispatcher
}

implicit class RichFutureWithTimeoutOps[A](
Expand Down
2 changes: 1 addition & 1 deletion app/com/m3/octoparts/hystrix/HystrixMetricsLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object HystrixMetricsLogger
m.getExecutionTimePercentile(50),
m.getExecutionTimePercentile(95),
m.getExecutionTimePercentile(99),
m.getExecutionTimePercentile(99.8)
m.getExecutionTimePercentile(99.9)
)
}

Expand Down
7 changes: 7 additions & 0 deletions app/com/m3/octoparts/util/ConfigMode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.m3.octoparts.util

final case class ConfigMode(value: String) extends AnyVal {

def isProd: Boolean = value.toLowerCase.startsWith("prod")

}
5 changes: 3 additions & 2 deletions app/com/m3/octoparts/wiring/AggregatorHandlersModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.m3.octoparts.wiring

import com.m3.octoparts.aggregator.handler.SimpleHttpHandlerFactory
import com.softwaremill.macwire._
import play.api.BuiltInComponents

trait AggregatorHandlersModule extends HttpClientPoolModule {
trait AggregatorHandlersModule extends HttpClientPoolModule { this: BuiltInComponents =>

private implicit val glueContext = play.api.libs.concurrent.Execution.Implicits.defaultContext
private lazy implicit val glueContext = actorSystem.dispatcher

lazy val httpHandlerFactory = wire[SimpleHttpHandlerFactory]

Expand Down
5 changes: 3 additions & 2 deletions app/com/m3/octoparts/wiring/AggregatorServicesModule.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.m3.octoparts.wiring

import scala.concurrent.duration._
import com.m3.octoparts.aggregator.service.{ PartsService, PartResponseLocalContentSupport, PartRequestService }
import com.m3.octoparts.aggregator.service.{ PartRequestService, PartResponseLocalContentSupport, PartsService }
import com.m3.octoparts.cache.PartResponseCachingSupport
import play.api.BuiltInComponents

trait AggregatorServicesModule
extends RepositoriesModule
with AggregatorHandlersModule
with ExecutionContextsModule { module =>
with ExecutionContextsModule { module: BuiltInComponents =>

private implicit lazy val ec = partsServiceContext

Expand Down
36 changes: 18 additions & 18 deletions app/com/m3/octoparts/wiring/CacheModule.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.m3.octoparts.wiring

import java.util.concurrent.{ TimeUnit, ThreadPoolExecutor, ArrayBlockingQueue, BlockingQueue }
import java.util.concurrent.{ ArrayBlockingQueue, BlockingQueue, ThreadPoolExecutor, TimeUnit }

import com.google.common.util.concurrent.ThreadFactoryBuilder
import com.m3.octoparts.cache.dummy.{ DummyCacheOps, DummyCache, DummyRawCache, DummyLatestVersionCache }
import com.m3.octoparts.cache.dummy.{ DummyCache, DummyCacheOps, DummyLatestVersionCache, DummyRawCache }
import com.m3.octoparts.cache.key.MemcachedKeyGenerator
import com.m3.octoparts.cache.memcached.{ MemcachedCacheOps, MemcachedCache, InMemoryRawCache, MemcachedRawCache }
import com.m3.octoparts.cache.versioning.InMemoryLatestVersionCache
import com.m3.octoparts.cache.LoggingRawCache
import shade.memcached.{ Configuration => ShadeConfig, FailureMode, AuthConfiguration, Memcached, Protocol }
import com.m3.octoparts.cache.memcached.{ InMemoryRawCache, MemcachedCache, MemcachedCacheOps, MemcachedRawCache }
import com.m3.octoparts.cache.versioning.{ InMemoryLatestVersionCache, LatestVersionCache }
import com.m3.octoparts.cache.{ LoggingRawCache, RawCache }
import shade.memcached.{ AuthConfiguration, FailureMode, Memcached, Protocol, Configuration => ShadeConfig }

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
Expand All @@ -19,37 +19,37 @@ trait CacheModule extends UtilsModule {
private implicit lazy val cacheExecutor: ExecutionContext = {

val namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("cache-%d").build()
val poolSize = typesafeConfig.getInt("caching.pool.size")
val queueSize = typesafeConfig.getInt("caching.queue.size")
val poolSize = configuration.get[Int]("caching.pool.size")
val queueSize = configuration.get[Int]("caching.queue.size")
val queue: BlockingQueue[Runnable] = new ArrayBlockingQueue[Runnable](queueSize)

ExecutionContext.fromExecutor(
new ThreadPoolExecutor(0, poolSize, 1L, TimeUnit.MINUTES, queue, namedThreadFactory)
)
}

lazy val latestVersionCache = {
lazy val latestVersionCache: LatestVersionCache = {
if (cachingDisabled) {
DummyLatestVersionCache
} else {
val maxInMemoryLVCKeys = configuration.getLong("caching.versionCachingSize").getOrElse(100000L)
val maxInMemoryLVCKeys = configuration.getOptional[Long]("caching.versionCachingSize").getOrElse(100000L)
new InMemoryLatestVersionCache(maxInMemoryLVCKeys)
}
}

lazy val rawCache = if (cachingDisabled) {
lazy val rawCache: RawCache = if (cachingDisabled) {
DummyRawCache
} else {
val cache = if (useInMemoryCache) {
new InMemoryRawCache(zipkinService)(cacheExecutor)
} else {
val hostPort = typesafeConfig.getString("memcached.host")
val timeout = typesafeConfig.getInt("memcached.timeout").millis
val hostPort = configuration.get[String]("memcached.host")
val timeout = configuration.get[Int]("memcached.timeout").millis
// should be one of "Text" or "Binary"
val protocol = typesafeConfig.getString("memcached.protocol")
val protocol = configuration.get[String]("memcached.protocol")
val auth = for {
user <- configuration.getString("memcached.user")
password <- configuration.getString("memcached.password")
user <- configuration.getOptional[String]("memcached.user")
password <- configuration.getOptional[String]("memcached.password")
} yield AuthConfiguration(user, password)

val shade = Memcached(
Expand Down Expand Up @@ -88,8 +88,8 @@ trait CacheModule extends UtilsModule {
}
}

lazy val cachingDisabled = configuration.getBoolean("caching.disabled").getOrElse(false)
lazy val cachingDisabled = configuration.getOptional[Boolean]("caching.disabled").getOrElse(false)

lazy val useInMemoryCache = configuration.getBoolean("caching.inmemory").getOrElse(false)
lazy val useInMemoryCache = configuration.getOptional[Boolean]("caching.inmemory").getOrElse(false)

}
38 changes: 25 additions & 13 deletions app/com/m3/octoparts/wiring/ControllersModule.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package com.m3.octoparts.wiring

import com.kenshoo.play.metrics.MetricsController
import com.m3.octoparts.util.ConfigMode
import com.m3.octoparts.wiring.assembling.ApplicationComponents
import controllers.hystrix.HystrixController
import controllers.system._
import controllers._
import pl.matisoft.swagger.ApiHelpController
import _root_.controllers.ApiHelpController
import play.api.i18n.I18nComponents
import presentation.NavbarLinks

import scala.concurrent.duration._
import com.softwaremill.macwire._
import controllers.support.HttpPartConfigChecks
import play.api.mvc.ControllerComponents

trait ControllersModule
extends AggregatorServicesModule
with HystrixModule
with AuthHandlerModule
with I18nComponents
with FiltersModule { this: ApplicationComponents.Essentials =>
with FiltersModule {
this: ApplicationComponents.Essentials =>

def controllerComponents: ControllerComponents

implicit lazy val configMode: ConfigMode = ConfigMode(configuration.get[String]("application.env"))

lazy val configChecks: HttpPartConfigChecks = new HttpPartConfigChecks(configMode)

lazy val partsController = {
val requestTimeout = typesafeConfig.getInt("timeouts.asyncRequestTimeout").millis
Expand All @@ -31,30 +42,31 @@ trait ControllersModule

lazy val adminController = {
implicit val navbarLinks = NavbarLinks(
kibana = configuration.getString("urls.kibana"),
hystrixDashboard = configuration.getString("urls.hystrixDashboard"),
swaggerUI = configuration.getString("urls.swaggerUI"),
wiki = configuration.getString("urls.wiki")
kibana = configuration.getOptional[String]("urls.kibana"),
hystrixDashboard = configuration.getOptional[String]("urls.hystrixDashboard"),
swaggerUI = configuration.getOptional[String]("urls.swaggerUI"),
wiki = configuration.getOptional[String]("urls.wiki")
)
wire[AdminController]
}

lazy val memcachedKeysToCheck = typesafeConfig.getInt("memcached.monitoring.randomChecks") match {
case 0 => SingleMemcachedCacheKeyToCheck
case n => RandomMemcachedCacheKeysToCheck(n)
}
lazy val memcachedKeysToCheck =
typesafeConfig.getInt("memcached.monitoring.randomChecks") match {
case 0 => SingleMemcachedCacheKeyToCheck
case n => RandomMemcachedCacheKeysToCheck(n)
}

lazy val healthcheckController = wire[HealthcheckController]

lazy val systemConfigController = wire[SystemConfigController]

lazy val hystrixController = new HystrixController(actorSystem = actorSystem)
lazy val hystrixController = wire[HystrixController]

lazy val authController = wire[AuthController]

lazy val apiHelpController = new ApiHelpController
lazy val apiHelpController = wire[ApiHelpController]

lazy val buildInfoController = new BuildInfoController
lazy val buildInfoController = wire[BuildInfoController]

lazy val defaultController = new Default

Expand Down
3 changes: 2 additions & 1 deletion app/com/m3/octoparts/wiring/FiltersModule.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.m3.octoparts.wiring

import com.beachape.zipkin.ZipkinHeaderFilter
import play.api.BuiltInComponents

trait FiltersModule extends UtilsModule {
trait FiltersModule extends UtilsModule { this: BuiltInComponents =>

lazy val zipkinTracingFilter = ZipkinHeaderFilter(zipkinService)

Expand Down
3 changes: 3 additions & 0 deletions app/com/m3/octoparts/wiring/HystrixModule.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.m3.octoparts.wiring

import com.m3.octoparts.hystrix.HystrixHealthReporter
import com.netflix.hystrix.metric.consumer.HystrixDashboardStream
import controllers.hystrix.Streamer

trait HystrixModule {

lazy val hystrixReporter = HystrixHealthReporter
lazy val hystrixStreamer = new Streamer(HystrixDashboardStream.getInstance())

}
6 changes: 5 additions & 1 deletion app/com/m3/octoparts/wiring/OctopartsApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import com.m3.octoparts.wiring.assembling.{ ApplicationComponents, BeforeStartup
import play.api.ApplicationLoader.Context
import play.api._

import scala.concurrent.ExecutionContext

class OctopartsApplicationLoader
extends ApplicationLoader
with BeforeStartupSupport {

implicit def eCtx: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global

def load(context: Context): Application = {
val appComponents = components(context)
appComponents.application
Expand All @@ -20,7 +24,7 @@ class OctopartsApplicationLoader
* startup procedures.
*/
def components(context: Context): ApplicationComponents = {
Logger.configure(context.environment)
Logger.setApplicationMode(context.environment.mode)
val appComponents = new ApplicationComponents(context)
beforeStart(appComponents)
appComponents
Expand Down
2 changes: 1 addition & 1 deletion app/com/m3/octoparts/wiring/RepositoriesModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait RepositoriesModule
private implicit lazy val ec = dbFetchExecutionContext

lazy val configsRepository = {
val localBuffer = configuration.getInt("memcached.configLocalBuffer")
val localBuffer = configuration.getOptional[Int]("memcached.configLocalBuffer")

val mutableRepoCache = localBuffer match {
case Some(localBufferDuration) if localBufferDuration > 0 => {
Expand Down
20 changes: 11 additions & 9 deletions app/com/m3/octoparts/wiring/UtilsModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import java.net.InetAddress

import com.beachape.zipkin.services.{ BraveZipkinService, NoopZipkinService, ZipkinServiceLike }
import com.github.kristofa.brave.zipkin.ZipkinSpanCollector

import com.m3.octoparts.logging.PartRequestLogger
import com.m3.octoparts.util.OctoMetricsImpl
import play.api.Mode.Mode
import play.api.Mode
import play.api._
import play.api.inject.ApplicationLifecycle

import scala.util.{ Failure, Success, Try }

import com.softwaremill.macwire._

import scala.concurrent.ExecutionContext

/*
Random common stuff that doesn't belong in other modules
*/
Expand All @@ -26,6 +26,8 @@ trait UtilsModule {

def applicationLifecycle: ApplicationLifecycle

def executionContext: ExecutionContext

implicit lazy val metrics = wire[OctoMetricsImpl]

/*
Expand All @@ -36,21 +38,21 @@ trait UtilsModule {
lazy val partsReqLogger: PartRequestLogger = PartRequestLogger

implicit lazy val zipkinService: ZipkinServiceLike = {
import play.api.libs.concurrent.Execution.Implicits._
implicit def eCtx = executionContext
if (mode == Mode.Test) {
NoopZipkinService
} else {
val maybeService = for {
zipkinHost <- configuration.getString("zipkin.host")
zipkinPort <- configuration.getInt("zipkin.port")
zipkinRate <- configuration.getDouble("zipkin.sampleRate")
env <- configuration.getString("application.env")
zipkinHost <- configuration.getOptional[String]("zipkin.host")
zipkinPort <- configuration.getOptional[Int]("zipkin.port")
zipkinRate <- configuration.getOptional[Double]("zipkin.sampleRate")
env <- configuration.getOptional[String]("application.env")
} yield {
Try {
val zipkinSpanCollector = new ZipkinSpanCollector(zipkinHost, zipkinPort)
sys.addShutdownHook(zipkinSpanCollector.close())
val currentHostName = InetAddress.getLocalHost.getHostName
val currentRunningPort = configuration.getInt("http.port").getOrElse(9000)
val currentRunningPort = configuration.getOptional[Int]("http.port").getOrElse(9000)
new BraveZipkinService(
hostIp = currentHostName,
hostPort = currentRunningPort,
Expand Down
Loading