From 4fc46d3fbfbd3aff387b9502a3f5aa093ba74324 Mon Sep 17 00:00:00 2001 From: Felipe Bonezi Date: Sat, 22 Oct 2022 17:52:13 -0300 Subject: [PATCH] feat(sbt): :hammer: refactor project structure Signed-off-by: Felipe Bonezi --- .DS_Store | Bin 0 -> 8196 bytes .github/workflows/continouos-integration.yml | 38 +++++++- build.sbt | 89 ++++++++++++++---- .../scala/play/actuator/health/Health.scala | 6 +- ...hIndicator.scala => HealthIndicator.scala} | 2 +- .../jdbc/src/main/resources/reference.conf | 11 +++ .../play/actuator/ActuatorJdbcModule.scala} | 23 ++++- .../indicator/DatabaseJdbcIndicator.scala | 6 +- .../redis/src/main/resources/reference.conf | 11 +++ .../play/actuator/ActuatorRedisModule.scala | 43 +++++++++ .../indicator/RedisHealthIndicator.scala} | 6 +- .../slick/src/main/resources/reference.conf | 11 +++ .../play/actuator/ActuatorSlickModule.scala} | 23 ++++- .../indicator/DatabaseSlickIndicator.scala | 6 +- play-actuator-sample/.DS_Store | Bin 0 -> 6148 bytes play-actuator-sample/build.sbt | 11 ++- play-actuator-sample/conf/application.conf | 3 +- play-actuator-sample/project/.DS_Store | Bin 0 -> 6148 bytes play-actuator-sample/project/plugins.sbt | 1 - .../project/project/.DS_Store | Bin 0 -> 6148 bytes play-actuator/.DS_Store | Bin 0 -> 6148 bytes .../src/main/resources/reference.conf | 6 +- .../scala/play/actuator/ActuatorModule.scala | 65 ++++++------- .../play/actuator/health/HealthService.scala | 45 +++++---- .../health/indicator/DiskSpaceIndicator.scala | 2 +- project/.DS_Store | Bin 0 -> 6148 bytes project/Common.scala | 5 +- project/Dependencies.scala | 7 +- project/project/.DS_Store | Bin 0 -> 6148 bytes 29 files changed, 310 insertions(+), 110 deletions(-) create mode 100644 .DS_Store rename play-actuator-core/src/main/scala/play/actuator/health/indicator/{BaseHealthIndicator.scala => HealthIndicator.scala} (97%) create mode 100644 play-actuator-indicators/database/jdbc/src/main/resources/reference.conf rename play-actuator-indicators/database/{src/main/scala/actuator/health/indicator/DatabaseIndicator.scala => jdbc/src/main/scala/play/actuator/ActuatorJdbcModule.scala} (62%) rename play-actuator-indicators/database/{src/main/scala => jdbc/src/main/scala/play}/actuator/health/indicator/DatabaseJdbcIndicator.scala (95%) create mode 100644 play-actuator-indicators/database/redis/src/main/resources/reference.conf create mode 100644 play-actuator-indicators/database/redis/src/main/scala/play/actuator/ActuatorRedisModule.scala rename play-actuator-indicators/{redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala => database/redis/src/main/scala/play/actuator/health/indicator/RedisHealthIndicator.scala} (95%) create mode 100644 play-actuator-indicators/database/slick/src/main/resources/reference.conf rename play-actuator-indicators/{redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala => database/slick/src/main/scala/play/actuator/ActuatorSlickModule.scala} (62%) rename play-actuator-indicators/database/{src/main/scala => slick/src/main/scala/play}/actuator/health/indicator/DatabaseSlickIndicator.scala (95%) create mode 100644 play-actuator-sample/.DS_Store create mode 100644 play-actuator-sample/project/.DS_Store create mode 100644 play-actuator-sample/project/project/.DS_Store create mode 100644 play-actuator/.DS_Store create mode 100644 project/.DS_Store create mode 100644 project/project/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5ac980c6feb676f30fb30ac0fdfa1b71e3477e39 GIT binary patch literal 8196 zcmeHMO>fgc5S>i}aa2X*&`P-=S>jqsC=mj2G5HXR#D`QDH~NdJH#`D}( ztdQ)f00sC&1KOvET$*q&mE1(t73TOqi0$PE;K>@7UY{rIlU(M=XE1(tlFBRbT zgNepyB^WD|uMTvw1OOJXTN=iw10=^x&`K~?D5;34st1u!MN(o2MaR6!?m#QSSfQem zP;?T>kwsFW2zhkyOzBR-QmA{afL35t0j}N4sMu#TBtKohhke%%UCeSq-9_8~Dh(r| zOVpxA^pK9|kh;{Q#~5|7eGm2jhz4Ch!~U3Km*_scThsx=rcTydT+Vq{XpA#+=!~wS z@6#0L>Yxv4l4HKlF?TjI5i3HJk@WC#alZU+9Csd#6V*PsV}BS;>-Eo~uvNTpv1F8t zZR3UgI-J{6XF7|T&g2LxpwEU_r@Ou;X7O#OeC*S z;`^UA*6^owJGCc)9|p(ZaJ&-KoZ!BkkjM8at7?J0($7%N`ybIRcU3us%E*@vvZ+lE zfa`LFGwnkv(<)HZqX4R&%BS7~>jckkNI_O#;w(!ucj46shjS-FzMNs?;koZKmtG;? zj}hxFa=_0Io?LyS$hGRI0VR){??{UJcg LpgXO=A64KRUWFWC literal 0 HcmV?d00001 diff --git a/.github/workflows/continouos-integration.yml b/.github/workflows/continouos-integration.yml index 2920888a..4b062ff6 100644 --- a/.github/workflows/continouos-integration.yml +++ b/.github/workflows/continouos-integration.yml @@ -37,7 +37,34 @@ jobs: path: ${{github.workspace}}/target/scalastyle-report/ build: - name: Build & Analyze + name: Build + if: "(github.event.release || github.event.release.prerelease) == false" + needs: [ validate ] + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + distribution: [ 'corretto' ] + jdk: [ '8' ] + scala: [ '2.12.17', '2.13.10' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup JDK + uses: actions/setup-java@v3 + with: + distribution: ${{ matrix.distribution }} + java-version: ${{ matrix.jdk }} + cache: 'sbt' + + - name: Perform Build / Test + run: sbt ++${{ matrix.scala }} compile test + + optional-build: + name: Build (Optional) if: "(github.event.release || github.event.release.prerelease) == false" continue-on-error: ${{ matrix.experimental }} needs: [ validate ] @@ -47,7 +74,7 @@ jobs: fail-fast: true matrix: distribution: [ 'corretto' ] - jdk: [ '8', '11' ] + jdk: [ '11' ] scala: [ '2.12.17', '2.13.10' ] experimental: [ false ] include: @@ -70,6 +97,13 @@ jobs: - name: Perform Build / Test run: sbt ++${{ matrix.scala }} compile test + ready: + name: Ready to Merge + needs: [ build ] + runs-on: ubuntu-latest + steps: + - run: echo "Ready to merge!" + publish: name: Publish to Sonatype if: "github.event.release || github.event.release.prerelease" diff --git a/build.sbt b/build.sbt index 5d8858bd..e9fbea8e 100644 --- a/build.sbt +++ b/build.sbt @@ -18,13 +18,13 @@ * 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. */ -import Common.repoName +import Common._ import Dependencies.scala212 import Dependencies.scala213 lazy val root = project .in(file(".")) - .aggregate(actuator) + .aggregate(core, actuator, jdbc, slick, redis) .settings( name := "play-actuator-root", crossScalaVersions := Nil, @@ -34,10 +34,20 @@ 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 + name := s"$repoName-core", + organization := "io.github.felipebonezi", + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + versionScheme := Some("early-semver"), + ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org", + ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local", + scmInfo := Some( + ScmInfo( + url(s"https://github.com/felipebonezi/$repoName/play-actuator-core"), + s"scm:git:git@github.com:felipebonezi/$repoName.git" + ) + ), + libraryDependencies ++= Dependencies.core ) lazy val actuator = project @@ -57,29 +67,72 @@ lazy val actuator = project s"scm:git:git@github.com:felipebonezi/$repoName.git" ) ), - Dependencies.actuator, + Dependencies.actuator ) .enablePlugins(Common) -lazy val database = project - .in(file("play-actuator-indicators/database")) +lazy val jdbc = project + .in(file("play-actuator-indicators/database/jdbc")) .dependsOn(core) .settings( - scalaVersion := scala213, - crossScalaVersions := Seq(scala212, scala213), - Dependencies.db, - publish / skip := true + name := s"$jdbcIndicatorName", + organization := "io.github.felipebonezi", + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + versionScheme := Some("early-semver"), + ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org", + ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local", + scmInfo := Some( + ScmInfo( + url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/jdbc"), + s"scm:git:git@github.com:felipebonezi/$repoName.git" + ) + ), + Dependencies.jdbc ) + .enablePlugins(Common) + +lazy val slick = project + .in(file("play-actuator-indicators/database/slick")) + .dependsOn(core) + .settings( + name := s"$slickIndicatorName", + organization := "io.github.felipebonezi", + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + versionScheme := Some("early-semver"), + ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org", + ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local", + scmInfo := Some( + ScmInfo( + url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/slick"), + s"scm:git:git@github.com:felipebonezi/$repoName.git" + ) + ), + Dependencies.slick + ) + .enablePlugins(Common) lazy val redis = project - .in(file("play-actuator-indicators/redis")) + .in(file("play-actuator-indicators/database/redis")) .dependsOn(core) .settings( - scalaVersion := scala213, - crossScalaVersions := Seq(scala212, scala213), - Dependencies.redis, - publish / skip := true + name := s"$redisIndicatorName", + organization := "io.github.felipebonezi", + scalaVersion := scala213, + crossScalaVersions := Seq(scala212, scala213), + versionScheme := Some("early-semver"), + ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org", + ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local", + scmInfo := Some( + ScmInfo( + url(s"https://github.com/felipebonezi/$repoName/play-actuator-indicators/database/redis"), + s"scm:git:git@github.com:felipebonezi/$repoName.git" + ) + ), + Dependencies.redis ) + .enablePlugins(Common) addCommandAlias( "validateCode", diff --git a/play-actuator-core/src/main/scala/play/actuator/health/Health.scala b/play-actuator-core/src/main/scala/play/actuator/health/Health.scala index 06398abb..be219d70 100644 --- a/play-actuator-core/src/main/scala/play/actuator/health/Health.scala +++ b/play-actuator-core/src/main/scala/play/actuator/health/Health.scala @@ -20,7 +20,11 @@ */ package play.actuator.health import play.actuator.ActuatorEnum.Status -import play.api.libs.json.{JsNull, JsNumber, JsString, Json, Writes} +import play.api.libs.json.JsNull +import play.api.libs.json.JsNumber +import play.api.libs.json.JsString +import play.api.libs.json.Json +import play.api.libs.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-core/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala b/play-actuator-core/src/main/scala/play/actuator/health/indicator/HealthIndicator.scala similarity index 97% rename from play-actuator-core/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala rename to play-actuator-core/src/main/scala/play/actuator/health/indicator/HealthIndicator.scala index 14f20b93..5f0a1c5a 100644 --- a/play-actuator-core/src/main/scala/play/actuator/health/indicator/BaseHealthIndicator.scala +++ b/play-actuator-core/src/main/scala/play/actuator/health/indicator/HealthIndicator.scala @@ -21,7 +21,7 @@ package play.actuator.health.indicator import play.actuator.health.HealthBuilder -abstract class BaseHealthIndicator { +trait HealthIndicator { def info(builder: HealthBuilder): Unit diff --git a/play-actuator-indicators/database/jdbc/src/main/resources/reference.conf b/play-actuator-indicators/database/jdbc/src/main/resources/reference.conf new file mode 100644 index 00000000..f3929735 --- /dev/null +++ b/play-actuator-indicators/database/jdbc/src/main/resources/reference.conf @@ -0,0 +1,11 @@ +play { + actuator { + indicator { + health { + database = true + } + } + } +} + +play.modules.enabled += "play.actuator.ActuatorJdbcModule" \ No newline at end of file diff --git a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala b/play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/ActuatorJdbcModule.scala similarity index 62% rename from play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala rename to play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/ActuatorJdbcModule.scala index 47c8623c..ae74794f 100644 --- a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseIndicator.scala +++ b/play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/ActuatorJdbcModule.scala @@ -18,7 +18,24 @@ * 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 actuator.health.indicator -import play.actuator.health.indicator.BaseHealthIndicator +package play.actuator -trait DatabaseIndicator extends BaseHealthIndicator {} +import com.google.inject.AbstractModule +import com.google.inject.name.Names +import play.actuator.health.indicator.DatabaseJdbcIndicator +import play.actuator.health.indicator.HealthIndicator +import play.api.Configuration +import play.api.Environment + +class ActuatorJdbcModule(environment: Environment, config: Configuration) extends AbstractModule { + + override def configure(): Unit = { + val confKey = "play.actuator.health.indicators.database" + if (config.getOptional[Boolean](confKey).getOrElse(false)) { + bind(classOf[HealthIndicator]) + .annotatedWith(Names.named("databaseIndicator")) + .to(classOf[DatabaseJdbcIndicator]) + } + } + +} diff --git a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala b/play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala similarity index 95% rename from play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala rename to play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala index 0e1ead92..5aeb53d9 100644 --- a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseJdbcIndicator.scala +++ b/play-actuator-indicators/database/jdbc/src/main/scala/play/actuator/health/indicator/DatabaseJdbcIndicator.scala @@ -18,17 +18,17 @@ * 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 actuator.health.indicator +package play.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 import javax.inject.Inject -class DatabaseJdbcIndicator @Inject() (database: Database) extends DatabaseIndicator { +class DatabaseJdbcIndicator @Inject() (database: Database) extends HealthIndicator { private var connectionRef: Option[Connection] = None diff --git a/play-actuator-indicators/database/redis/src/main/resources/reference.conf b/play-actuator-indicators/database/redis/src/main/resources/reference.conf new file mode 100644 index 00000000..d2fbe6f9 --- /dev/null +++ b/play-actuator-indicators/database/redis/src/main/resources/reference.conf @@ -0,0 +1,11 @@ +play { + actuator { + indicator { + health { + redis = true + } + } + } +} + +play.modules.enabled += "play.actuator.ActuatorRedisModule" \ No newline at end of file diff --git a/play-actuator-indicators/database/redis/src/main/scala/play/actuator/ActuatorRedisModule.scala b/play-actuator-indicators/database/redis/src/main/scala/play/actuator/ActuatorRedisModule.scala new file mode 100644 index 00000000..2ec874b6 --- /dev/null +++ b/play-actuator-indicators/database/redis/src/main/scala/play/actuator/ActuatorRedisModule.scala @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Felipe Bonezi + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * 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 + +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.HealthIndicator +import play.actuator.health.indicator.RedisHealthIndicator +import play.api.Configuration +import play.api.Environment + +class ActuatorRedisModule(environment: Environment, config: Configuration) extends AbstractModule { + + override def configure(): Unit = { + val confKey = "play.actuator.health.indicators.redis" + if (config.getOptional[Boolean](confKey).getOrElse(false)) { + bind(classOf[HealthIndicator]) + .annotatedWith(Names.named("redisIndicator")) + .to(classOf[RedisHealthIndicator]) + } + } + +} diff --git a/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala b/play-actuator-indicators/database/redis/src/main/scala/play/actuator/health/indicator/RedisHealthIndicator.scala similarity index 95% rename from play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala rename to play-actuator-indicators/database/redis/src/main/scala/play/actuator/health/indicator/RedisHealthIndicator.scala index c96fbf77..cd6df87f 100644 --- a/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/PlayRedisIndicator.scala +++ b/play-actuator-indicators/database/redis/src/main/scala/play/actuator/health/indicator/RedisHealthIndicator.scala @@ -18,7 +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 actuator.health.indicator +package play.actuator.health.indicator import com.typesafe.config.Config import play.actuator.ActuatorEnum @@ -29,10 +29,10 @@ import javax.inject.Inject import scala.concurrent.Await import scala.concurrent.duration.DurationInt -class PlayRedisIndicator @Inject() ( +class RedisHealthIndicator @Inject() ( config: Config, connector: RedisConnector -) extends RedisIndicator { +) extends HealthIndicator { override def info(builder: HealthBuilder): Unit = { if (this.config.getString("play.cache.redis.recovery") != "log-and-fail") { diff --git a/play-actuator-indicators/database/slick/src/main/resources/reference.conf b/play-actuator-indicators/database/slick/src/main/resources/reference.conf new file mode 100644 index 00000000..1daeb92f --- /dev/null +++ b/play-actuator-indicators/database/slick/src/main/resources/reference.conf @@ -0,0 +1,11 @@ +play { + actuator { + indicator { + health { + database = true + } + } + } +} + +play.modules.enabled += "play.actuator.ActuatorSlickModule" \ No newline at end of file diff --git a/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala b/play-actuator-indicators/database/slick/src/main/scala/play/actuator/ActuatorSlickModule.scala similarity index 62% rename from play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala rename to play-actuator-indicators/database/slick/src/main/scala/play/actuator/ActuatorSlickModule.scala index c4c85d6d..a5f30c0b 100644 --- a/play-actuator-indicators/redis/src/main/scala/actuator/health/indicator/RedisIndicator.scala +++ b/play-actuator-indicators/database/slick/src/main/scala/play/actuator/ActuatorSlickModule.scala @@ -18,7 +18,24 @@ * 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 actuator.health.indicator -import play.actuator.health.indicator.BaseHealthIndicator +package play.actuator -trait RedisIndicator extends BaseHealthIndicator {} +import com.google.inject.AbstractModule +import com.google.inject.name.Names +import play.actuator.health.indicator.DatabaseSlickIndicator +import play.actuator.health.indicator.HealthIndicator +import play.api.Configuration +import play.api.Environment + +class ActuatorSlickModule(environment: Environment, config: Configuration) extends AbstractModule { + + override def configure(): Unit = { + val confKey = "play.actuator.health.indicators.database" + if (config.getOptional[Boolean](confKey).getOrElse(false)) { + bind(classOf[HealthIndicator]) + .annotatedWith(Names.named("databaseIndicator")) + .to(classOf[DatabaseSlickIndicator]) + } + } + +} diff --git a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala b/play-actuator-indicators/database/slick/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala similarity index 95% rename from play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala rename to play-actuator-indicators/database/slick/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala index b2eedc27..9b91f5d4 100644 --- a/play-actuator-indicators/database/src/main/scala/actuator/health/indicator/DatabaseSlickIndicator.scala +++ b/play-actuator-indicators/database/slick/src/main/scala/play/actuator/health/indicator/DatabaseSlickIndicator.scala @@ -18,12 +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 actuator.health.indicator +package play.actuator.health.indicator -import actuator.health.indicator.DatabaseSlickIndicator.DB_TIMEOUT_SECS import com.typesafe.config.Config 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 +34,7 @@ import javax.inject.Inject class DatabaseSlickIndicator @Inject() ( val config: Config, protected val dbConfigProvider: DatabaseConfigProvider -) extends DatabaseIndicator +) extends HealthIndicator with HasDatabaseConfigProvider[JdbcProfile] { private var connectionRef: Option[Connection] = None diff --git a/play-actuator-sample/.DS_Store b/play-actuator-sample/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..94e197342321fa492e8d37b71441884efac881f5 GIT binary patch literal 6148 zcmeHK!A{#i5S>lj#uloS1C_WSS>lRlN+Sf~;s$!?6<2VeRchlD+!}8bJIx`AZ+u4~}XWu%z9wHLGaq^m|O++q~vEiY4K-kZ^APqCZ zPQi1?lQ@$xES}EFV_<;yu1OIMY4|>y+rPK)Y}_hQ3-KtXF{PAILK{@TDr*@(YZ(rm zkffZx%*Tnw}b8eAkcS!*np|x0m;1UPfs?7^#Fb86f22QJN=m z(v#ynDO7H#9j@nk{r1Xq+U<1L{qFYWY~7#kYf8|T<&WR?5~dZ)fMwuGGhogccj-y9U>9#0 zunauJ0G|&&lrb<^X;eoC8dU-S9Skc$Uw!-oeI5V?1}lvife4)n)TzRh7{b&JLZ`zY znD|PgPA8$BjCstHg{e@4DLsU*!bt=gZEG2@49qjo)MlIS|95|`|L2peWf`yx{8tPJ zXFuHUVM*q0U0597wLbJSl!fCejrS?&sH+&Ud=;-im0;ZG4lpoSX~YP`eh4TUY-1Vt Hrwsf8O4O6z literal 0 HcmV?d00001 diff --git a/play-actuator-sample/build.sbt b/play-actuator-sample/build.sbt index b14ede8b..a9364eb4 100644 --- a/play-actuator-sample/build.sbt +++ b/play-actuator-sample/build.sbt @@ -29,11 +29,16 @@ scalaVersion := "2.13.9" resolvers ++= DefaultOptions.resolvers(snapshot = true) libraryDependencies += javaJdbc -libraryDependencies += "org.postgresql" % "postgresql" % "42.5.0" libraryDependencies += cacheApi -libraryDependencies += "com.github.karelcemus" %% "play-redis" % "2.7.0" libraryDependencies += guice -libraryDependencies += "io.github.felipebonezi" %% "play-actuator" % "0.1.0+3-9876626a+20220723-2349-SNAPSHOT" +libraryDependencies += "org.postgresql" % "postgresql" % "42.5.0" +libraryDependencies += "com.github.karelcemus" %% "play-redis" % "2.7.0" + +lazy val actuatorVersion = "0.2.0" +libraryDependencies += "io.github.felipebonezi" %% "play-actuator" % actuatorVersion +libraryDependencies += "io.github.felipebonezi" %% "play-actuator-redis-indicator" % actuatorVersion +libraryDependencies += "io.github.felipebonezi" %% "play-actuator-jdbc-indicator" % actuatorVersion + libraryDependencies += specs2 % Test libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test diff --git a/play-actuator-sample/conf/application.conf b/play-actuator-sample/conf/application.conf index a1c30dc3..db60b7ba 100644 --- a/play-actuator-sample/conf/application.conf +++ b/play-actuator-sample/conf/application.conf @@ -8,7 +8,7 @@ play { indicators { # Check disk space details. diskSpace = true - jdbc = true + database = true redis = true } } @@ -38,5 +38,4 @@ play.cache.redis { recovery: log-and-fail } -play.modules.enabled += "play.actuator.ActuatorModule" play.modules.enabled += "play.api.cache.redis.RedisCacheModule" diff --git a/play-actuator-sample/project/.DS_Store b/play-actuator-sample/project/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1c4bf4a93bf6d011e1f30293605a0e64f2e37c0e GIT binary patch literal 6148 zcmeHKO>fgc5S>lZ#!-aiLo4-C$r9Hn4JATFTud4cz19d0fI=Kw!C<^m?2tng$>;XR zaOIcqciOifK_sD^A|#?2Y4*+T&dkPd?cEF!iQX)FLgW&W165dQp!tKSd8J!Yu_FgS zp>sskrU^|+qGkCX7*KoXQb;pOD5c-`FUCF=7>y~vO64d_WvG3LUIN>9TJ$3}vD+y! zjNzS8j&~qO#$qGt`$kmVzA2xv!f4Z5oc`TAoaYn!i++TYG|7uj=clMtYX^sQr|vYJ z55Xrn4~k(i%X`D=JJowFWg4#RVfZGA=L7fXQf9?4$>OOFNTL`n@82d_Bf>j(WF9?9OVTMwu1S`YdWszmvf n27iUX&{r{h)m3}~)q-(P89?7+X%Hh2{v)7i;D#CarwrT!lI?bW literal 0 HcmV?d00001 diff --git a/play-actuator-sample/project/plugins.sbt b/play-actuator-sample/project/plugins.sbt index a7d516a7..0d4191b0 100644 --- a/play-actuator-sample/project/plugins.sbt +++ b/play-actuator-sample/project/plugins.sbt @@ -19,4 +19,3 @@ * 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-sample/project/project/.DS_Store b/play-actuator-sample/project/project/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T03Z5S>vG!N$@uSMUZw^aOhW1;s`bM6I{-TprCgpGH?ZZR8D1UNV`NkXP*N zh=|TFo0-T&L`HB!x!KS)+c)o6FCz+si0p zwti-h{ zq5pp-aYY5Fz+Wk#gGIBL<4IXtJCCzkTi`3W<=o+Bm^%f7mt&xpV=Sy3PdzE}ip{ZK V6Wc(iBkpt{e+En!8Ws4p0uNe26{i3I literal 0 HcmV?d00001 diff --git a/play-actuator/src/main/resources/reference.conf b/play-actuator/src/main/resources/reference.conf index 5b04450c..94734982 100644 --- a/play-actuator/src/main/resources/reference.conf +++ b/play-actuator/src/main/resources/reference.conf @@ -3,13 +3,11 @@ play { indicator { health { diskspace = false - jdbc = false - slick = false + database = false redis = false } } } } -play.modules.enabled += "play.actuator.ActuatorModule" -play.modules.enabled += "play.api.cache.redis.RedisCacheModule" \ No newline at end of file +play.modules.enabled += "play.actuator.ActuatorModule" \ No newline at end of file diff --git a/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala b/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala index 40c21be6..3ffaf5a0 100644 --- a/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala +++ b/play-actuator/src/main/scala/play/actuator/ActuatorModule.scala @@ -20,47 +20,42 @@ */ 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.DiskSpaceIndicator +import play.actuator.health.indicator.HealthIndicator 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.") -// }) -// } + bind(classOf[HealthIndicator]) + .annotatedWith(Names.named("diskSpaceIndicator")) + .toInstance(new DiskSpaceIndicator()) + + if (isInactive("play.actuator.health.indicators.database")) { + bindMissingHealthIndicator("databaseIndicator", "Application without database connection.") + } + + if (isInactive("play.actuator.health.indicators.redis")) { + bindMissingHealthIndicator("redisIndicator", "Application without Redis connection.") + } + } + + private def isInactive(key: String): Boolean = { + !config.getOptional[Boolean](key).getOrElse(false) + } + + private def bindMissingHealthIndicator(name: String, msg: String): Unit = { + bind(classOf[HealthIndicator]) + .annotatedWith(Names.named(name)) + .toInstance((builder: HealthBuilder) => { + builder + .withStatus(Up) + .withDetail("message", msg) + }) } } 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 e63105d9..cce0ca55 100644 --- a/play-actuator/src/main/scala/play/actuator/health/HealthService.scala +++ b/play-actuator/src/main/scala/play/actuator/health/HealthService.scala @@ -19,25 +19,28 @@ * 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.Down import play.actuator.health.indicator.DiskSpaceIndicator +import play.actuator.health.indicator.HealthIndicator import play.api.Configuration -import javax.inject.Singleton -import javax.inject.Named +import javax.annotation.Nullable import javax.inject.Inject +import javax.inject.Named +import javax.inject.Singleton import scala.collection.mutable @Singleton class HealthService @Inject() ( config: Configuration, - diskSpaceIndicator: DiskSpaceIndicator -// @Named("jdbcIndicator") jdbcIndicator: DatabaseIndicator, -// @Named("slickIndicator") slickIndicator: DatabaseIndicator, -// redisIndicator: RedisIndicator + @Nullable @Named("diskSpaceIndicator") + diskSpaceIndicator: HealthIndicator, + @Nullable @Named("databaseIndicator") + databaseIndicator: HealthIndicator, + @Nullable @Named("redisIndicator") + redisIndicator: HealthIndicator ) { def globalStatus: Status = @@ -55,23 +58,17 @@ 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("database") && databaseIndicator != null) { + val builder = new HealthBuilder("database") + this.databaseIndicator.info(builder) + indicators.append(builder.build) + } + + if (isIndicatorActive("redis") && redisIndicator != null) { + val builder = new HealthBuilder("redis") + this.redisIndicator.info(builder) + indicators.append(builder.build) + } indicators.toSeq } diff --git a/play-actuator/src/main/scala/play/actuator/health/indicator/DiskSpaceIndicator.scala b/play-actuator/src/main/scala/play/actuator/health/indicator/DiskSpaceIndicator.scala index ae8c56ab..3087aa81 100644 --- a/play-actuator/src/main/scala/play/actuator/health/indicator/DiskSpaceIndicator.scala +++ b/play-actuator/src/main/scala/play/actuator/health/indicator/DiskSpaceIndicator.scala @@ -29,7 +29,7 @@ import java.io.File import javax.inject.Singleton @Singleton -class DiskSpaceIndicator extends BaseHealthIndicator { +class DiskSpaceIndicator extends HealthIndicator { private val folder = new File("/") diff --git a/project/.DS_Store b/project/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..09514b65497f5cb1d8a7250d39b157e556f07d0d GIT binary patch literal 6148 zcmeHK&u`N(6n@?cO({qbV$v>?B5|EY85II?$+~jjx*#|JDoGQKKxS7>N)J_~oZ*k* z%3reoWheNa?MgIdT#yi|{3^fCKi=n8f0gZ;h{Rx)J|yyq$U|Xl-Gcj#@i>^DB{~5f{m`bD zcbiVJ<1g@0Byj?iG^QA{#SPxK2JbEnG5Z8XA~XB3$#?x6;-E1{7yJU>{v1q+%$z-; zYCW^~+F-TqDfJOq#~aaCe~wP(<;1G-J((1FS@n9CVrRE?<7V4ydtL8c^g+#|Dz0Yb zAfCSA)=Q;|WL1xoS9vxc`S(thtm0f|Q%%Uz3?Xk{=Q36Eftty*)ZEAncpa}Z^7j{u zey@KR^q(9r4}-742|46|ldv*WJ$Lxm7s@oC1HL0G|&53S(%oHmHvdIQ;|ww$QB&b$&}QC$Jb= ztPNrWCJYs5sKP!mgrTE9uyLWq+MuD6u#XR6GYk7d5js2O4|F(*(4g~90jI#a0=uT^ z^Zoz)`uG1j$+esUPJyjbK(vO@aDXM*yLDr6eAfmj?@`z|t~RJCaP~UZ6~2o1QM6$! Y;0iFbSQ|tS%>5D2GC1cH_@@f|1ax|qdH?_b literal 0 HcmV?d00001 diff --git a/project/Common.scala b/project/Common.scala index 3d9be2ad..a3685bab 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -32,7 +32,10 @@ object Common extends AutoPlugin { override def requires: Plugins = JvmPlugin && HeaderPlugin - val repoName = "play-actuator" + val repoName = "play-actuator" + val jdbcIndicatorName = "play-actuator-jdbc-indicator" + val slickIndicatorName = "play-actuator-slick-indicator" + val redisIndicatorName = "play-actuator-redis-indicator" override def globalSettings: Seq[Setting[_]] = Seq( diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 3f2f3192..baf6bee5 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -42,8 +42,11 @@ object Dependencies { "com.typesafe.play" %% "play-json" % playJsonVersion ) - val db = libraryDependencies ++= core ++ Seq( - "com.typesafe.play" %% "play-jdbc" % playVersion, + val jdbc = libraryDependencies ++= core ++ Seq( + "com.typesafe.play" %% "play-jdbc" % playVersion + ) + + val slick = libraryDependencies ++= core ++ Seq( "com.typesafe.play" %% "play-slick" % playSlickVersion ) diff --git a/project/project/.DS_Store b/project/project/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0