diff --git a/.github/workflows/continouos-integration.yml b/.github/workflows/continouos-integration.yml index 37cb4d8d..2920888a 100644 --- a/.github/workflows/continouos-integration.yml +++ b/.github/workflows/continouos-integration.yml @@ -48,12 +48,12 @@ jobs: matrix: distribution: [ 'corretto' ] jdk: [ '8', '11' ] - scala: [ '2.12.16', '2.13.8' ] + scala: [ '2.12.17', '2.13.10' ] experimental: [ false ] include: - jdk: '17' distribution: 'corretto' - scala: '2.13.8' + scala: '2.13.10' experimental: true steps: diff --git a/build.sbt b/build.sbt index 1cf323e5..5d8858bd 100644 --- a/build.sbt +++ b/build.sbt @@ -24,7 +24,7 @@ import Dependencies.scala213 lazy val root = project .in(file(".")) - .aggregate(core) + .aggregate(actuator) .settings( name := "play-actuator-root", crossScalaVersions := Nil, @@ -32,7 +32,17 @@ lazy val root = project ) lazy val core = project + .in(file("play-actuator-core")) + .settings( + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + libraryDependencies ++= Dependencies.core, + publish / skip := true + ) + +lazy val actuator = project .in(file("play-actuator")) + .dependsOn(core) .settings( name := s"$repoName", organization := "io.github.felipebonezi", @@ -51,6 +61,26 @@ lazy val core = project ) .enablePlugins(Common) +lazy val database = project + .in(file("play-actuator-indicators/database")) + .dependsOn(core) + .settings( + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + Dependencies.db, + publish / skip := true + ) + +lazy val redis = project + .in(file("play-actuator-indicators/redis")) + .dependsOn(core) + .settings( + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + Dependencies.redis, + publish / skip := true + ) + addCommandAlias( "validateCode", List( diff --git a/play-actuator/src/main/scala/play/actuator/ActuatorEnum.scala b/play-actuator-core/src/main/scala/play/actuator/ActuatorEnum.scala similarity index 100% rename from play-actuator/src/main/scala/play/actuator/ActuatorEnum.scala rename to play-actuator-core/src/main/scala/play/actuator/ActuatorEnum.scala diff --git a/play-actuator/src/main/scala/play/actuator/health/Health.scala b/play-actuator-core/src/main/scala/play/actuator/health/Health.scala similarity index 88% rename from play-actuator/src/main/scala/play/actuator/health/Health.scala rename to play-actuator-core/src/main/scala/play/actuator/health/Health.scala index b8a54fab..06398abb 100644 --- a/play-actuator/src/main/scala/play/actuator/health/Health.scala +++ b/play-actuator-core/src/main/scala/play/actuator/health/Health.scala @@ -20,13 +20,7 @@ */ package play.actuator.health import play.actuator.ActuatorEnum.Status -import play.api.libs.json.Format -import play.api.libs.json.JsNull -import play.api.libs.json.JsNumber -import play.api.libs.json.JsString -import play.api.libs.json.JsValue -import play.api.libs.json.Json -import play.api.libs.json.Writes +import play.api.libs.json.{JsNull, JsNumber, JsString, Json, Writes} case class Health(name: String, status: Status, details: Map[String, Any]) { override def toString: String = s"Health(status=$status, details=$details)" diff --git a/play-actuator/src/main/scala/play/actuator/health/HealthBuilder.scala b/play-actuator-core/src/main/scala/play/actuator/health/HealthBuilder.scala similarity index 100% rename from play-actuator/src/main/scala/play/actuator/health/HealthBuilder.scala rename to play-actuator-core/src/main/scala/play/actuator/health/HealthBuilder.scala index 8b97452f..d20e541f 100644 --- a/play-actuator/src/main/scala/play/actuator/health/HealthBuilder.scala +++ b/play-actuator-core/src/main/scala/play/actuator/health/HealthBuilder.scala @@ -19,8 +19,8 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package play.actuator.health -import play.actuator.ActuatorEnum.Status import play.actuator.ActuatorEnum.Up +import play.actuator.ActuatorEnum.Status import scala.collection.mutable diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala b/play-actuator-core/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala similarity index 100% rename from play-actuator/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala rename to play-actuator-core/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseIndicator.scala b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala similarity index 92% rename from play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseIndicator.scala rename to play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala index 5830e6f4..47c8623c 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseIndicator.scala +++ b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala @@ -18,6 +18,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package play.actuator.health.indicator +package actuator.health.indicator +import play.actuator.health.indicator.BaseHealthIndicator trait DatabaseIndicator extends BaseHealthIndicator {} diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala similarity index 95% rename from play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala rename to play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala index ac28bb56..0e1ead92 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala +++ b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala @@ -18,10 +18,11 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package play.actuator.health.indicator +package actuator.health.indicator + +import actuator.health.indicator.DatabaseJdbcIndicator.DB_TIMEOUT_SECS import play.actuator.ActuatorEnum import play.actuator.health.HealthBuilder -import play.actuator.health.indicator.DatabaseJdbcIndicator.DB_TIMEOUT_SECS import play.api.db.Database import java.sql.Connection diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala similarity index 90% rename from play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala rename to play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala index f0aa6860..b2eedc27 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala +++ b/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala @@ -18,13 +18,12 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package play.actuator.health.indicator +package actuator.health.indicator +import actuator.health.indicator.DatabaseSlickIndicator.DB_TIMEOUT_SECS import com.typesafe.config.Config -import play.actuator.ActuatorEnum.Down -import play.actuator.ActuatorEnum.Up +import play.actuator.ActuatorEnum import play.actuator.health.HealthBuilder -import play.actuator.health.indicator.DatabaseSlickIndicator.DB_TIMEOUT_SECS import play.api.db.slick.DatabaseConfigProvider import play.api.db.slick.HasDatabaseConfigProvider import slick.jdbc.JdbcProfile @@ -34,7 +33,7 @@ import javax.inject.Inject class DatabaseSlickIndicator @Inject() ( val config: Config, - val dbConfigProvider: DatabaseConfigProvider + protected val dbConfigProvider: DatabaseConfigProvider ) extends DatabaseIndicator with HasDatabaseConfigProvider[JdbcProfile] { @@ -65,14 +64,14 @@ class DatabaseSlickIndicator @Inject() ( try { val metaData = this.getConnection.getMetaData builder - .withStatus(Up) + .withStatus(ActuatorEnum.Up) .withDetail("name", this.dbConfigProvider.get.profileName) .withDetail("url", this.config.getString("slick.dbs.default.db.url")) .withDetail("driver", metaData.getDriverName) } catch { case e: Exception => builder - .withStatus(Down) + .withStatus(ActuatorEnum.Down) .withDetail("name", this.dbConfigProvider.get.profileName) .withDetail("url", this.config.getString("slick.dbs.default.db.url")) .withDetail("exception", e.getMessage) diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/PlayRedisIndicator.scala b/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala similarity index 92% rename from play-actuator/src/main/scala/play/actuator/health/indicator/PlayRedisIndicator.scala rename to play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala index 6ce587af..c96fbf77 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/PlayRedisIndicator.scala +++ b/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala @@ -18,10 +18,10 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package play.actuator.health.indicator +package actuator.health.indicator + import com.typesafe.config.Config -import play.actuator.ActuatorEnum.Down -import play.actuator.ActuatorEnum.Up +import play.actuator.ActuatorEnum import play.actuator.health.HealthBuilder import play.api.cache.redis.RedisConnector @@ -42,12 +42,12 @@ class PlayRedisIndicator @Inject() ( try { Await.result(this.connector.ping(), 3.seconds) builder - .withStatus(Up) + .withStatus(ActuatorEnum.Up) .withDetail("source", this.config.getString("play.cache.redis.source")) } catch { case e: Exception => builder - .withStatus(Down) + .withStatus(ActuatorEnum.Down) .withDetail("message", "Redis connection failed!") .withDetail("exception", e.getMessage) } diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/RedisIndicator.scala b/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala similarity index 92% rename from play-actuator/src/main/scala/play/actuator/health/indicator/RedisIndicator.scala rename to play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala index 876069a1..c4c85d6d 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/RedisIndicator.scala +++ b/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala @@ -18,6 +18,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package play.actuator.health.indicator +package actuator.health.indicator +import play.actuator.health.indicator.BaseHealthIndicator trait RedisIndicator extends BaseHealthIndicator {} diff --git a/play-actuator-sample/project/plugins.sbt b/play-actuator-sample/project/plugins.sbt index 0d4191b0..a7d516a7 100644 --- a/play-actuator-sample/project/plugins.sbt +++ b/play-actuator-sample/project/plugins.sbt @@ -19,3 +19,4 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18") diff --git a/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala b/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala index 10913eaa..40c21be6 100644 --- a/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala +++ b/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala @@ -20,55 +20,47 @@ */ package play.actuator import com.google.inject.AbstractModule -import com.google.inject.name.Names -import play.actuator.ActuatorEnum.Up -import play.actuator.health.HealthBuilder -import play.actuator.health.indicator.DatabaseIndicator -import play.actuator.health.indicator.DatabaseJdbcIndicator -import play.actuator.health.indicator.DatabaseSlickIndicator -import play.actuator.health.indicator.PlayRedisIndicator -import play.actuator.health.indicator.RedisIndicator -import play.api.Configuration import play.api.Environment +import play.api.Configuration class ActuatorModule(environment: Environment, config: Configuration) extends AbstractModule { override def configure(): Unit = { - if (config.has("db")) { - bind(classOf[DatabaseIndicator]) - .annotatedWith(Names.named("jdbcIndicator")) - .to(classOf[DatabaseJdbcIndicator]) - } else { - bind(classOf[DatabaseIndicator]) - .annotatedWith(Names.named("jdbcIndicator")) - .toInstance((builder: HealthBuilder) => { - builder - .withStatus(Up) - .withDetail("message", "Application without database connection.") - }) - } - if (config.has("slick")) { - bind(classOf[DatabaseIndicator]) - .annotatedWith(Names.named("slickIndicator")) - .to(classOf[DatabaseSlickIndicator]) - } else { - bind(classOf[DatabaseIndicator]) - .annotatedWith(Names.named("slickIndicator")) - .toInstance((builder: HealthBuilder) => { - builder - .withStatus(Up) - .withDetail("message", "Application without Slick connection.") - }) - } - if (config.has("play.cache.redis")) { - bind(classOf[RedisIndicator]).to(classOf[PlayRedisIndicator]) - } else { - bind(classOf[RedisIndicator]).toInstance((builder: HealthBuilder) => { - builder - .withStatus(Up) - .withDetail("message", "Application without Redis connection.") - }) - } +// if (config.has("db")) { +// bind(classOf[DatabaseIndicator]) +// .annotatedWith(Names.named("jdbcIndicator")) +// .to(classOf[DatabaseJdbcIndicator]) +// } else { +// bind(classOf[DatabaseIndicator]) +// .annotatedWith(Names.named("jdbcIndicator")) +// .toInstance((builder: HealthBuilder) => { +// builder +// .withStatus(Up) +// .withDetail("message", "Application without database connection.") +// }) +// } +// if (config.has("slick")) { +// bind(classOf[DatabaseIndicator]) +// .annotatedWith(Names.named("slickIndicator")) +// .to(classOf[DatabaseSlickIndicator]) +// } else { +// bind(classOf[DatabaseIndicator]) +// .annotatedWith(Names.named("slickIndicator")) +// .toInstance((builder: HealthBuilder) => { +// builder +// .withStatus(Up) +// .withDetail("message", "Application without Slick connection.") +// }) +// } +// if (config.has("play.cache.redis")) { +// bind(classOf[RedisIndicator]).to(classOf[PlayRedisIndicator]) +// } else { +// bind(classOf[RedisIndicator]).toInstance((builder: HealthBuilder) => { +// builder +// .withStatus(Up) +// .withDetail("message", "Application without Redis connection.") +// }) +// } } } diff --git a/play-actuator/src/main/scala/play/actuator/health/HealthService.scala b/play-actuator/src/main/scala/play/actuator/health/HealthService.scala index bafd2661..e63105d9 100644 --- a/play-actuator/src/main/scala/play/actuator/health/HealthService.scala +++ b/play-actuator/src/main/scala/play/actuator/health/HealthService.scala @@ -20,26 +20,24 @@ */ package play.actuator.health -import play.actuator.ActuatorEnum.Down import play.actuator.ActuatorEnum.Status import play.actuator.ActuatorEnum.Up -import play.actuator.health.indicator.DatabaseIndicator +import play.actuator.ActuatorEnum.Down import play.actuator.health.indicator.DiskSpaceIndicator -import play.actuator.health.indicator.RedisIndicator import play.api.Configuration -import javax.inject.Inject -import javax.inject.Named import javax.inject.Singleton +import javax.inject.Named +import javax.inject.Inject import scala.collection.mutable @Singleton class HealthService @Inject() ( config: Configuration, - diskSpaceIndicator: DiskSpaceIndicator, - @Named("jdbcIndicator") jdbcIndicator: DatabaseIndicator, - @Named("slickIndicator") slickIndicator: DatabaseIndicator, - redisIndicator: RedisIndicator + diskSpaceIndicator: DiskSpaceIndicator +// @Named("jdbcIndicator") jdbcIndicator: DatabaseIndicator, +// @Named("slickIndicator") slickIndicator: DatabaseIndicator, +// redisIndicator: RedisIndicator ) { def globalStatus: Status = @@ -57,23 +55,23 @@ class HealthService @Inject() ( indicators.append(builder.build) } - if (isIndicatorActive("jdbc")) { - val builder = new HealthBuilder("jdbc") - this.jdbcIndicator.info(builder) - indicators.append(builder.build) - } - - if (isIndicatorActive("slick")) { - val builder = new HealthBuilder("slick") - this.slickIndicator.info(builder) - indicators.append(builder.build) - } - - if (isIndicatorActive("redis")) { - val builder = new HealthBuilder("redis") - this.redisIndicator.info(builder) - indicators.append(builder.build) - } +// if (isIndicatorActive("jdbc")) { +// val builder = new HealthBuilder("jdbc") +// this.jdbcIndicator.info(builder) +// indicators.append(builder.build) +// } +// +// if (isIndicatorActive("slick")) { +// val builder = new HealthBuilder("slick") +// this.slickIndicator.info(builder) +// indicators.append(builder.build) +// } +// +// if (isIndicatorActive("redis")) { +// val builder = new HealthBuilder("redis") +// this.redisIndicator.info(builder) +// indicators.append(builder.build) +// } indicators.toSeq } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 0d898661..3f2f3192 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -32,18 +32,23 @@ object Dependencies { val playRedisVersion: String = "2.7.0" val typesafeConfigVersion: String = "1.4.2" - val actuator = libraryDependencies ++= Seq( - "com.typesafe.play" %% "play-jdbc" % playVersion, - "com.typesafe.play" %% "play-slick" % playSlickVersion, - "com.typesafe.play" %% "play-guice" % playVersion, - "com.typesafe.play" %% "play-json" % playJsonVersion, - "com.typesafe.play" %% "play-test" % playVersion % Test, - "com.github.karelcemus" %% "play-redis" % playRedisVersion - ) - - val plugin = libraryDependencies ++= Seq( + val core: Seq[ModuleID] = Seq( "com.typesafe.play" %% "play-guice" % playVersion, "com.typesafe.play" %% "play-test" % playVersion % Test, - "com.typesafe" % "config" % typesafeConfigVersion, + "com.typesafe" % "config" % typesafeConfigVersion ) + + val actuator = libraryDependencies ++= core ++ Seq( + "com.typesafe.play" %% "play-json" % playJsonVersion + ) + + val db = libraryDependencies ++= core ++ Seq( + "com.typesafe.play" %% "play-jdbc" % playVersion, + "com.typesafe.play" %% "play-slick" % playSlickVersion + ) + + val redis = libraryDependencies ++= core ++ Seq( + "com.github.karelcemus" %% "play-redis" % playRedisVersion + ) + }