diff --git a/README.md b/README.md index 0246f1b4..ac3de975 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Below we have all project endpoints available on this project. | Endpoint ID | Description | Path | Ready to use? | |-------------|----------------------------------------------|---------------------|---------------| | health | Displays your application’s health status. | `/actuator/health` | ✔️ | -| info | Displays information about your application. | `/actuator/info` | ✖️ | +| info | Displays information about your application. | `/actuator/info` | ✔️ | | logfile | Returns the contents of the log file. | `/actuator/logfile` | ✖️ | ## Health endpoint details @@ -80,6 +80,13 @@ Show to you information about your Redis connection. libraryDependencies ++= "io.github.felipebonezi" %% "play-actuator-redis-indicator" % "(version)" ``` +## Info endpoint details + +You can enable to get all operational system info +inside the JSON return by `/actuator/info` route. Default is disabled. + +`play.actuator.info.system.enabled = true` + ## Scala compatibility This project is compatible with Scala `2.12` and `2.13`, so you need to use the right version. diff --git a/build.sbt b/build.sbt index e9fbea8e..0948ab49 100644 --- a/build.sbt +++ b/build.sbt @@ -53,6 +53,7 @@ lazy val core = project lazy val actuator = project .in(file("play-actuator")) .dependsOn(core) + .enablePlugins(Common, BuildInfoPlugin) .settings( name := s"$repoName", organization := "io.github.felipebonezi", @@ -67,9 +68,11 @@ lazy val actuator = project s"scm:git:git@github.com:felipebonezi/$repoName.git" ) ), - Dependencies.actuator + Dependencies.actuator, + buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion), + buildInfoPackage := "play.actuator.build", + buildInfoOptions += BuildInfoOption.ToJson ) - .enablePlugins(Common) lazy val jdbc = project .in(file("play-actuator-indicators/database/jdbc")) diff --git a/play-actuator-sample/build.sbt b/play-actuator-sample/build.sbt index 2c36f558..33dc9c8e 100644 --- a/play-actuator-sample/build.sbt +++ b/play-actuator-sample/build.sbt @@ -34,7 +34,7 @@ libraryDependencies += guice libraryDependencies += "org.postgresql" % "postgresql" % "42.5.1" libraryDependencies += "com.github.karelcemus" %% "play-redis" % "2.7.0" -lazy val actuatorVersion = "0.2.0" +lazy val actuatorVersion = "0.2.0+8-0577a9db+20221209-1830-SNAPSHOT" 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 diff --git a/play-actuator-sample/conf/application.conf b/play-actuator-sample/conf/application.conf index db60b7ba..34d315fc 100644 --- a/play-actuator-sample/conf/application.conf +++ b/play-actuator-sample/conf/application.conf @@ -4,6 +4,7 @@ play { http.secret.key = "KQ87XDCc^NxJ1529v[v6vee8Xd49LE/DhxprrDzU + * + * 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.info + +import play.actuator.build.BuildInfo +import play.api.Configuration +import play.api.libs.json.JsObject +import play.api.libs.json.JsString +import play.api.libs.json.JsValue +import play.api.libs.json.Json + +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter.ISO_DATE_TIME +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class InfoService @Inject() (config: Configuration) { + + import scala.collection.JavaConverters._ + + def getBuildInfos: JsValue = { + var buildInfos = Json.parse(BuildInfo.toJson).as[JsObject] + buildInfos = buildInfos + ("dateTime" -> JsString(LocalDateTime.now().format(ISO_DATE_TIME))) + + if (isSystemInfoActive) { + import scala.collection.immutable.ListMap + + val systemInfos = System.getProperties.asScala.map(p => (p._1, JsString(p._2))) + val sortedSystemInfos = ListMap(systemInfos.toSeq.sortBy(_._1): _*) + buildInfos = buildInfos + ("system" -> JsObject(sortedSystemInfos)) + } + + buildInfos + } + + private def isSystemInfoActive: Boolean = + this.config + .getOptional[Boolean](s"play.actuator.info.system.enabled") + .orElse(Some(false)) + .get + +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 7039bd59..75693839 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -21,6 +21,10 @@ addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.9.0") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") +// Build Info +// See more: https://github.com/sbt/sbt-buildinfo +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") + // Code formatter for Scala. // See more: https://github.com/scalameta/sbt-scalafmt // Oficial Website: https://scalameta.org/scalafmt/