Skip to content

Commit

Permalink
[backport to 0.x] expose library version in logs and as metric (#631) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-git authored Sep 16, 2024
1 parent 2176e5a commit 1ed038c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Dependencies._
import Dependencies.*
import sbt.Package.ManifestAttributes

lazy val commonSettings = Seq(
organization := "com.evolutiongaming",
Expand All @@ -18,7 +19,15 @@ lazy val commonSettings = Seq(
libraryDependencySchemes ++= Seq(
"org.scala-lang.modules" %% "scala-java8-compat" % "always",
"org.scala-lang.modules" %% "scala-xml" % "always"),
versionScheme := Some("early-semver"))
versionScheme := Some("early-semver"),
packageOptions := {
Seq(
ManifestAttributes(
("Implementation-Version", (ThisProject / version).value),
),
)
},
)


lazy val root = (project in file(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ object EventualCassandra {
schema <- SetupSchema[F](schemaConfig, origin, consistencyConfig)
segmentNrsOf = SegmentNrsOf[F](first = Segments.default, second = Segments.old)
statements <- Statements.of(schema, segmentNrsOf, Segments.default, consistencyConfig.read)
_ <- log.info(s"kafka-journal version: ${Version.current.value}")
} yield {
val journal = apply[F](statements).withLog(log)
metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object ReplicatedCassandra {
statements <- Statements.of[F](schema, config.consistencyConfig)
log <- LogOf[F].apply(ReplicatedCassandra.getClass)
expiryService <- ExpiryService.of[F]
_ <- log.info(s"kafka-journal version: ${Version.current.value}")
} yield {
val segmentOf = SegmentNrsOf[F](first = Segments.default, second = Segments.old)
val journal = apply[F](config.segmentSize, segmentOf, statements, expiryService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final case class Version(value: String) {

object Version {

val current: Version = Version("0.3.4")
val current: Version = Version(Option(Version.getClass.getPackage.getImplementationVersion).getOrElse("unknown"))


implicit val eqVersion: Eq[Version] = Eq.fromUniversalEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats._
import cats.arrow.FunctionK
import cats.effect.Resource
import cats.syntax.all._
import com.evolutiongaming.catshelper.CatsHelper.OpsCatsHelper
import com.evolutiongaming.catshelper.{Log, MeasureDuration, MonadThrowable}
import com.evolutiongaming.kafka.journal._
import com.evolutiongaming.kafka.journal.util.StreamHelper._
Expand Down Expand Up @@ -84,6 +85,12 @@ object EventualJournal {
prefix: String = "eventual_journal"
): Resource[F, Metrics[F]] = {

val versionGauge = registry.gauge(
name = s"${prefix}_info",
help = "Journal version information",
labels = LabelNames("version"),
)

val latencySummary = registry.summary(
name = s"${ prefix }_topic_latency",
help = "Journal call latency in seconds",
Expand All @@ -97,6 +104,8 @@ object EventualJournal {
labels = LabelNames("topic"))

for {
versionGauge <- versionGauge
_ <- versionGauge.labels(Version.current.value).set(1).toResource
latencySummary <- latencySummary
eventsSummary <- eventsSummary
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ object ReplicatedJournal {
prefix: String = "replicated_journal"
): Resource[F, Metrics[F]] = {

val versionGauge = registry.gauge(
name = s"${prefix}_info",
help = "Journal version information",
labels = LabelNames("version"),
)

val latencySummary = registry.summary(
name = s"${ prefix }_latency",
help = "Journal call latency in seconds",
Expand All @@ -207,6 +213,8 @@ object ReplicatedJournal {
labels = LabelNames("topic"))

for {
versionGauge <- versionGauge
_ <- versionGauge.labels(Version.current.value).set(1).toResource
latencySummary <- latencySummary
topicLatencySummary <- topicLatencySummary
eventsSummary <- eventsSummary
Expand Down

0 comments on commit 1ed038c

Please sign in to comment.