From e8e27524c5ee9ca9921e80092d9e938c44467f24 Mon Sep 17 00:00:00 2001 From: Ronald Wang Date: Wed, 17 Aug 2022 16:58:48 -0400 Subject: [PATCH 1/8] initial commit -- updated documentation && added SimpleZioExample code into the example directory --- .gitignore | 1 + build.sbt | 24 +++++++++- docs/getting-started.md | 11 +++++ docs/intro.md | 27 +++++++++++ docs/supported-metrics.md | 45 +++++++++++++++++++ example/README.md | 8 +++- .../scala/example/SimpleStreamExample.scala | 8 ++-- .../main/scala/example/SimpleZioExample.scala | 18 ++++++++ .../src/main/scala/example/ZioProgram.scala | 26 +++++++++++ 9 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 example/src/main/scala/example/SimpleZioExample.scala create mode 100644 example/src/main/scala/example/ZioProgram.scala diff --git a/.gitignore b/.gitignore index 88d65d079..ab0902b20 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ target/ project/project project/target project/metals.sbt +.DS_Store !opentelemetry-javaagent110.jar diff --git a/build.sbt b/build.sbt index 58e6f7611..35d6aa3d2 100644 --- a/build.sbt +++ b/build.sbt @@ -150,7 +150,8 @@ lazy val example = (project in file("example")) akkaTestkit.map(_ % "test") ++ akkaPersistance ++ logback ++ - exampleDependencies + exampleDependencies ++ + zio }, assemblyMergeStrategySettings, mainClass := Some("example.Boot"), @@ -168,7 +169,8 @@ lazy val example = (project in file("example")) keys }, commands += runExampleWithOtelAgent, - commands += runStreamExampleWithOtelAgent + commands += runStreamExampleWithOtelAgent, + commands += runZioExampleWithOtelAgent ) .dependsOn(extension) @@ -243,3 +245,21 @@ def runStreamExampleWithOtelAgent = Command.command("runStreamExampleWithOtelAge Project.extract(newState).runInputTask(Compile / runMain, " example.SimpleStreamExample", newState) s } + +def runZioExampleWithOtelAgent = Command.command("runZioExampleWithOtelAgent") { state => + val extracted = Project extract state + val newState = extracted.appendWithSession( + Seq( + run / javaOptions ++= Seq( + s"-javaagent:$projectRootDir/opentelemetry-javaagent-$OpentelemetryLatestVersion.jar", + s"-Dotel.service.name=mesmer-stream-example", + s"-Dotel.metric.export.interval=1000", + s"-Dotel.javaagent.extensions=${(otelExtension / assembly).value.absolutePath}" + ) + ), + state + ) + val (s, _) = + Project.extract(newState).runInputTask(Compile / runMain, " example.SimpleZioExample", newState) + s +} diff --git a/docs/getting-started.md b/docs/getting-started.md index ea915a0ca..ddd54615f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -64,3 +64,14 @@ Both parts need to be included in the application for Mesmer to work. ```sh curl -i http://localhost:9464 ``` + +## How to collect JVM Metrics from ZIO (for Mesmer): + +In your ZIO Application, you will need to add the following lines of code: + +- `Runtime.enableRuntimeMetrics` +- `DefaultJvmMetrics.live.unit` + +For reference, please follow this ZIO 2.0 SampleApp code: + +https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 diff --git a/docs/intro.md b/docs/intro.md index c79d7b275..73297e3d1 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -11,3 +11,30 @@ Auto-instrumentation means it will automatically detect the libraries you use an OpenTelemetry is a set of tools, APIs and SDKs that provide standardized approach to telemetry including: instrumenting, generating, collecting and exporting telemetry data. Mesmer is designed as an extension for the OpenTelemetry Java agent. This way you will benefit from both the general Java APIs metrics that are still useful in Scala (like JDBC or Netty) and the specific Scala instrumentation provided by Mesmer (like Akka or ZIO). + +# Links to get started: + +## ByteBuddy +This is the tool that we use to instrument java bytecode. It provides a declarative API and allows to register transformation on loaded classes. +main page tutorial, provides a good overview, but we don't use many features from here (and not all features that we use are there described) - https://bytebuddy.net/#/tutorial +https://www.youtube.com/watch?v=OF3YFGZcQkg - talk by the creator. Provides good introduction to Advice - tool that we heavily use in mesmer + + +## OpenTelemetry +Initiative that goal is to create spec for observable systems and provide tools to implement it for different languages. +java SDK - https://github.com/open-telemetry/opentelemetry-java +tool for manual instrumentation +java autoinstrumentation - https://github.com/open-telemetry/opentelemetry-java-instrumentation +depends on the former +collection of auto instruments that integrates with an application seemlessly +our goal is to make mesmer a plugin for this +I recommend that check out the repository, but it's huge and requires a lot of time to index by IDE +conceptual introduction to OT https://www.youtube.com/watch?v=DbaO0Xxv34c + + +## Mesmer +https://github.com/ScalaConsultants/mesmer/blob/main/CONTRIBUTORS.md + +https://scalac.io/blog/the-opentelemetry-mesmer-duo-state-of-the-mesmer-project/ + +https://scalac.io/mesmer-opentelemetry-extension/ diff --git a/docs/supported-metrics.md b/docs/supported-metrics.md index 15ff98b48..90e7bbf0f 100644 --- a/docs/supported-metrics.md +++ b/docs/supported-metrics.md @@ -54,3 +54,48 @@ In Mesmer we support 3 types of metrics: | Stream throughput | counter | | Operator throughput | counter | | Operator processing time | counter | + +## ZIO (both Default-JVM-Metrics and others) + +| Metric | Type | +|---------------------------------------|---------| +| Executor Capacity | gauge | +| Executor Concurrency | gauge | +| Executor Dequeued Count | | +| Executor Enqueued Count | | +| Executor Size | gauge | +| Executor Worker Count | | +| JVM Buffer Pool Capacity Bytes | gauge | +| JVM Buffer Pool Used Buffers | gauge | +| JVM Buffer Pool Used Bytes | gauge | +| JVM Classes Loaded | gauge | +| JVM Classes Loaded Total | gauge | +| JVM Classes Unloaded Total | gauge | +| JVM GC Collection Seconds Count | | +| JVM GC Collection Seconds Sum | | +| JVM Info | gauge | +| JVM Memory Bytes Committed | gauge | +| JVM Memory Bytes Init | gauge | +| JVM Memory Bytes Max | gauge | +| JVM Memory Bytes Used | gauge | +| JVM Memory Pool Allocated Bytes Total | counter | +| JVM Memory Pool Bytes Committed | gauge | +| JVM Memory Pool Bytes Init | gauge | +| JVM Memory Pool Bytes Max | gauge | +| JVM Memory Pool Bytes Used | gauge | +| JVM Threads Current | gauge | +| JVM Threads Daemon | gauge | +| JVM Threads Deadlocked | gauge | +| JVM Threads Deadlocked Monitor | gauge | +| JVM Threads Peak | gauge | +| JVM Threads Started Total | gauge | +| Null | counter | +| Process CPU Seconds Total | gauge | +| Process Max FDS | gauge | +| Process Open FDS | gauge | +| Process Resident Memory Bytes | gauge | +| Process Start Time Seconds | gauge | +| Process Virtual Memory Bytes | gauge | +| ZIO Fiber Failures | counter | +| ZIO Fiber Started | counter | +| ZIO Fiber Successes | counter | diff --git a/example/README.md b/example/README.md index 297208573..afa1c1f63 100644 --- a/example/README.md +++ b/example/README.md @@ -13,7 +13,7 @@ This will set up everything needed by the application: data (Averages, Requests per second etc). It shows graphs based both on Mesmer-provided (Akka Persistence + Actor Metrics) and OpenTelemetry-provided metrics (Akka Http). -## Run the application +## Run the application (both Akka and ZIO examples) ``` sbt "project example" runExampleWithOtelAgent @@ -25,6 +25,12 @@ or (for Akka Streaming example) sbt "project example" runStreamExampleWithOtelAgent ``` +or (for ZIO 2.0.0 example) + +``` +sbt "project example" runZioExampleWithOtelAgent +``` + ## In case you are running the non-streaming example: call the endpoints You can now interact with the application to generate some traffic and metrics: diff --git a/example/src/main/scala/example/SimpleStreamExample.scala b/example/src/main/scala/example/SimpleStreamExample.scala index 46ea19209..67eb0683d 100644 --- a/example/src/main/scala/example/SimpleStreamExample.scala +++ b/example/src/main/scala/example/SimpleStreamExample.scala @@ -13,9 +13,11 @@ import org.slf4j.LoggerFactory import scala.concurrent.duration._ /** - * Another example useful to testing if stream instrumentation work. It's a simple example that prints amount of process - * elements roughly in 5 seconds intervals and after shutdown. Data should be compared with information that can be - * found in prometheus. + * Another example useful to testing if stream instrumentation work. + * It's a simple example that prints amount of process elements roughly in 5 seconds intervals + * and after shutdown. + * + * Data should be compared with information that can be found in prometheus. */ object SimpleStreamExample extends App { diff --git a/example/src/main/scala/example/SimpleZioExample.scala b/example/src/main/scala/example/SimpleZioExample.scala new file mode 100644 index 000000000..78485f885 --- /dev/null +++ b/example/src/main/scala/example/SimpleZioExample.scala @@ -0,0 +1,18 @@ +package example + +import zio._ +import zio.metrics.jvm.DefaultJvmMetrics + +//NOTE: code originally written by Łukasz Gajowy +object SimpleZioExample extends ZIOAppDefault { + + override def run: ZIO[Any, Throwable, Boolean] = { + ZioProgram + .findTheMeaningOfLife(3, Int.MinValue, Int.MaxValue) + .provide( + Runtime.enableRuntimeMetrics, // NOTE: refactored by following this zio-metrics-connectors example ( https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 ) + DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters + ) + } + +} diff --git a/example/src/main/scala/example/ZioProgram.scala b/example/src/main/scala/example/ZioProgram.scala new file mode 100644 index 000000000..f7f0c7f54 --- /dev/null +++ b/example/src/main/scala/example/ZioProgram.scala @@ -0,0 +1,26 @@ +package example + +import zio.{Console, durationInt, Random, Schedule, ZIO} + +//NOTE: code originally written by Łukasz Gajowy +object ZioProgram { + + def findTheMeaningOfLife(parallelism: Int, lowerBound: Int, upperBound: Int): ZIO[Any, Nothing, Boolean] = { + val numberToGuess = 42 + + val task: ZIO[Any, Nothing, Boolean] = { + val recurringTask = (for { + _ <- Console.printLine("Looking for the meaning of life...") + guessedNumber <- Random.nextIntBetween(lowerBound, upperBound) + _ <- Console.printLine(s"Found some number: $guessedNumber") *> ZIO.sleep(100.milliseconds) + result = guessedNumber == numberToGuess + } yield result).orDie + + recurringTask.repeat(Schedule.recurUntilEquals(true)) + } + + val tasks = (0 until parallelism).map(_ => task).toList + ZIO.raceAll(tasks.head, tasks.tail) + } + +} From e6c1032f851d5a6417ae561dc425260092ad3413 Mon Sep 17 00:00:00 2001 From: Ronald Wang Date: Wed, 17 Aug 2022 17:38:52 -0400 Subject: [PATCH 2/8] resolve Scala Lint error && ScalaFmt errors --- example/src/main/scala/example/SimpleStreamExample.scala | 5 ++--- example/src/main/scala/example/SimpleZioExample.scala | 5 ++--- example/src/main/scala/example/ZioProgram.scala | 6 +++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example/src/main/scala/example/SimpleStreamExample.scala b/example/src/main/scala/example/SimpleStreamExample.scala index 67eb0683d..77d1bf934 100644 --- a/example/src/main/scala/example/SimpleStreamExample.scala +++ b/example/src/main/scala/example/SimpleStreamExample.scala @@ -13,9 +13,8 @@ import org.slf4j.LoggerFactory import scala.concurrent.duration._ /** - * Another example useful to testing if stream instrumentation work. - * It's a simple example that prints amount of process elements roughly in 5 seconds intervals - * and after shutdown. + * Another example useful to testing if stream instrumentation work. It's a simple example that prints amount of process + * elements roughly in 5 seconds intervals and after shutdown. * * Data should be compared with information that can be found in prometheus. */ diff --git a/example/src/main/scala/example/SimpleZioExample.scala b/example/src/main/scala/example/SimpleZioExample.scala index 78485f885..67db85595 100644 --- a/example/src/main/scala/example/SimpleZioExample.scala +++ b/example/src/main/scala/example/SimpleZioExample.scala @@ -6,13 +6,12 @@ import zio.metrics.jvm.DefaultJvmMetrics //NOTE: code originally written by Łukasz Gajowy object SimpleZioExample extends ZIOAppDefault { - override def run: ZIO[Any, Throwable, Boolean] = { + override def run: ZIO[Any, Throwable, Boolean] = ZioProgram .findTheMeaningOfLife(3, Int.MinValue, Int.MaxValue) .provide( Runtime.enableRuntimeMetrics, // NOTE: refactored by following this zio-metrics-connectors example ( https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 ) - DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters + DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters ) - } } diff --git a/example/src/main/scala/example/ZioProgram.scala b/example/src/main/scala/example/ZioProgram.scala index f7f0c7f54..01068d0bf 100644 --- a/example/src/main/scala/example/ZioProgram.scala +++ b/example/src/main/scala/example/ZioProgram.scala @@ -1,6 +1,10 @@ package example -import zio.{Console, durationInt, Random, Schedule, ZIO} +import zio.Console +import zio.Random +import zio.Schedule +import zio.ZIO +import zio.durationInt //NOTE: code originally written by Łukasz Gajowy object ZioProgram { From 4cee5073bbd4490da319f6d80594c1f66bf01c20 Mon Sep 17 00:00:00 2001 From: Ronald Wang Date: Wed, 17 Aug 2022 16:58:48 -0400 Subject: [PATCH 3/8] initial commit -- updated documentation && added SimpleZioExample code into the example directory --- .gitignore | 1 + build.sbt | 24 +++++++++- docs/getting-started.md | 11 +++++ docs/intro.md | 27 +++++++++++ docs/supported-metrics.md | 45 +++++++++++++++++++ example/README.md | 8 +++- .../scala/example/SimpleStreamExample.scala | 8 ++-- .../main/scala/example/SimpleZioExample.scala | 18 ++++++++ .../src/main/scala/example/ZioProgram.scala | 26 +++++++++++ 9 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 example/src/main/scala/example/SimpleZioExample.scala create mode 100644 example/src/main/scala/example/ZioProgram.scala diff --git a/.gitignore b/.gitignore index 88d65d079..ab0902b20 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ target/ project/project project/target project/metals.sbt +.DS_Store !opentelemetry-javaagent110.jar diff --git a/build.sbt b/build.sbt index 58e6f7611..35d6aa3d2 100644 --- a/build.sbt +++ b/build.sbt @@ -150,7 +150,8 @@ lazy val example = (project in file("example")) akkaTestkit.map(_ % "test") ++ akkaPersistance ++ logback ++ - exampleDependencies + exampleDependencies ++ + zio }, assemblyMergeStrategySettings, mainClass := Some("example.Boot"), @@ -168,7 +169,8 @@ lazy val example = (project in file("example")) keys }, commands += runExampleWithOtelAgent, - commands += runStreamExampleWithOtelAgent + commands += runStreamExampleWithOtelAgent, + commands += runZioExampleWithOtelAgent ) .dependsOn(extension) @@ -243,3 +245,21 @@ def runStreamExampleWithOtelAgent = Command.command("runStreamExampleWithOtelAge Project.extract(newState).runInputTask(Compile / runMain, " example.SimpleStreamExample", newState) s } + +def runZioExampleWithOtelAgent = Command.command("runZioExampleWithOtelAgent") { state => + val extracted = Project extract state + val newState = extracted.appendWithSession( + Seq( + run / javaOptions ++= Seq( + s"-javaagent:$projectRootDir/opentelemetry-javaagent-$OpentelemetryLatestVersion.jar", + s"-Dotel.service.name=mesmer-stream-example", + s"-Dotel.metric.export.interval=1000", + s"-Dotel.javaagent.extensions=${(otelExtension / assembly).value.absolutePath}" + ) + ), + state + ) + val (s, _) = + Project.extract(newState).runInputTask(Compile / runMain, " example.SimpleZioExample", newState) + s +} diff --git a/docs/getting-started.md b/docs/getting-started.md index ea915a0ca..ddd54615f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -64,3 +64,14 @@ Both parts need to be included in the application for Mesmer to work. ```sh curl -i http://localhost:9464 ``` + +## How to collect JVM Metrics from ZIO (for Mesmer): + +In your ZIO Application, you will need to add the following lines of code: + +- `Runtime.enableRuntimeMetrics` +- `DefaultJvmMetrics.live.unit` + +For reference, please follow this ZIO 2.0 SampleApp code: + +https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 diff --git a/docs/intro.md b/docs/intro.md index c79d7b275..73297e3d1 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -11,3 +11,30 @@ Auto-instrumentation means it will automatically detect the libraries you use an OpenTelemetry is a set of tools, APIs and SDKs that provide standardized approach to telemetry including: instrumenting, generating, collecting and exporting telemetry data. Mesmer is designed as an extension for the OpenTelemetry Java agent. This way you will benefit from both the general Java APIs metrics that are still useful in Scala (like JDBC or Netty) and the specific Scala instrumentation provided by Mesmer (like Akka or ZIO). + +# Links to get started: + +## ByteBuddy +This is the tool that we use to instrument java bytecode. It provides a declarative API and allows to register transformation on loaded classes. +main page tutorial, provides a good overview, but we don't use many features from here (and not all features that we use are there described) - https://bytebuddy.net/#/tutorial +https://www.youtube.com/watch?v=OF3YFGZcQkg - talk by the creator. Provides good introduction to Advice - tool that we heavily use in mesmer + + +## OpenTelemetry +Initiative that goal is to create spec for observable systems and provide tools to implement it for different languages. +java SDK - https://github.com/open-telemetry/opentelemetry-java +tool for manual instrumentation +java autoinstrumentation - https://github.com/open-telemetry/opentelemetry-java-instrumentation +depends on the former +collection of auto instruments that integrates with an application seemlessly +our goal is to make mesmer a plugin for this +I recommend that check out the repository, but it's huge and requires a lot of time to index by IDE +conceptual introduction to OT https://www.youtube.com/watch?v=DbaO0Xxv34c + + +## Mesmer +https://github.com/ScalaConsultants/mesmer/blob/main/CONTRIBUTORS.md + +https://scalac.io/blog/the-opentelemetry-mesmer-duo-state-of-the-mesmer-project/ + +https://scalac.io/mesmer-opentelemetry-extension/ diff --git a/docs/supported-metrics.md b/docs/supported-metrics.md index 15ff98b48..90e7bbf0f 100644 --- a/docs/supported-metrics.md +++ b/docs/supported-metrics.md @@ -54,3 +54,48 @@ In Mesmer we support 3 types of metrics: | Stream throughput | counter | | Operator throughput | counter | | Operator processing time | counter | + +## ZIO (both Default-JVM-Metrics and others) + +| Metric | Type | +|---------------------------------------|---------| +| Executor Capacity | gauge | +| Executor Concurrency | gauge | +| Executor Dequeued Count | | +| Executor Enqueued Count | | +| Executor Size | gauge | +| Executor Worker Count | | +| JVM Buffer Pool Capacity Bytes | gauge | +| JVM Buffer Pool Used Buffers | gauge | +| JVM Buffer Pool Used Bytes | gauge | +| JVM Classes Loaded | gauge | +| JVM Classes Loaded Total | gauge | +| JVM Classes Unloaded Total | gauge | +| JVM GC Collection Seconds Count | | +| JVM GC Collection Seconds Sum | | +| JVM Info | gauge | +| JVM Memory Bytes Committed | gauge | +| JVM Memory Bytes Init | gauge | +| JVM Memory Bytes Max | gauge | +| JVM Memory Bytes Used | gauge | +| JVM Memory Pool Allocated Bytes Total | counter | +| JVM Memory Pool Bytes Committed | gauge | +| JVM Memory Pool Bytes Init | gauge | +| JVM Memory Pool Bytes Max | gauge | +| JVM Memory Pool Bytes Used | gauge | +| JVM Threads Current | gauge | +| JVM Threads Daemon | gauge | +| JVM Threads Deadlocked | gauge | +| JVM Threads Deadlocked Monitor | gauge | +| JVM Threads Peak | gauge | +| JVM Threads Started Total | gauge | +| Null | counter | +| Process CPU Seconds Total | gauge | +| Process Max FDS | gauge | +| Process Open FDS | gauge | +| Process Resident Memory Bytes | gauge | +| Process Start Time Seconds | gauge | +| Process Virtual Memory Bytes | gauge | +| ZIO Fiber Failures | counter | +| ZIO Fiber Started | counter | +| ZIO Fiber Successes | counter | diff --git a/example/README.md b/example/README.md index 297208573..afa1c1f63 100644 --- a/example/README.md +++ b/example/README.md @@ -13,7 +13,7 @@ This will set up everything needed by the application: data (Averages, Requests per second etc). It shows graphs based both on Mesmer-provided (Akka Persistence + Actor Metrics) and OpenTelemetry-provided metrics (Akka Http). -## Run the application +## Run the application (both Akka and ZIO examples) ``` sbt "project example" runExampleWithOtelAgent @@ -25,6 +25,12 @@ or (for Akka Streaming example) sbt "project example" runStreamExampleWithOtelAgent ``` +or (for ZIO 2.0.0 example) + +``` +sbt "project example" runZioExampleWithOtelAgent +``` + ## In case you are running the non-streaming example: call the endpoints You can now interact with the application to generate some traffic and metrics: diff --git a/example/src/main/scala/example/SimpleStreamExample.scala b/example/src/main/scala/example/SimpleStreamExample.scala index 46ea19209..67eb0683d 100644 --- a/example/src/main/scala/example/SimpleStreamExample.scala +++ b/example/src/main/scala/example/SimpleStreamExample.scala @@ -13,9 +13,11 @@ import org.slf4j.LoggerFactory import scala.concurrent.duration._ /** - * Another example useful to testing if stream instrumentation work. It's a simple example that prints amount of process - * elements roughly in 5 seconds intervals and after shutdown. Data should be compared with information that can be - * found in prometheus. + * Another example useful to testing if stream instrumentation work. + * It's a simple example that prints amount of process elements roughly in 5 seconds intervals + * and after shutdown. + * + * Data should be compared with information that can be found in prometheus. */ object SimpleStreamExample extends App { diff --git a/example/src/main/scala/example/SimpleZioExample.scala b/example/src/main/scala/example/SimpleZioExample.scala new file mode 100644 index 000000000..78485f885 --- /dev/null +++ b/example/src/main/scala/example/SimpleZioExample.scala @@ -0,0 +1,18 @@ +package example + +import zio._ +import zio.metrics.jvm.DefaultJvmMetrics + +//NOTE: code originally written by Łukasz Gajowy +object SimpleZioExample extends ZIOAppDefault { + + override def run: ZIO[Any, Throwable, Boolean] = { + ZioProgram + .findTheMeaningOfLife(3, Int.MinValue, Int.MaxValue) + .provide( + Runtime.enableRuntimeMetrics, // NOTE: refactored by following this zio-metrics-connectors example ( https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 ) + DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters + ) + } + +} diff --git a/example/src/main/scala/example/ZioProgram.scala b/example/src/main/scala/example/ZioProgram.scala new file mode 100644 index 000000000..f7f0c7f54 --- /dev/null +++ b/example/src/main/scala/example/ZioProgram.scala @@ -0,0 +1,26 @@ +package example + +import zio.{Console, durationInt, Random, Schedule, ZIO} + +//NOTE: code originally written by Łukasz Gajowy +object ZioProgram { + + def findTheMeaningOfLife(parallelism: Int, lowerBound: Int, upperBound: Int): ZIO[Any, Nothing, Boolean] = { + val numberToGuess = 42 + + val task: ZIO[Any, Nothing, Boolean] = { + val recurringTask = (for { + _ <- Console.printLine("Looking for the meaning of life...") + guessedNumber <- Random.nextIntBetween(lowerBound, upperBound) + _ <- Console.printLine(s"Found some number: $guessedNumber") *> ZIO.sleep(100.milliseconds) + result = guessedNumber == numberToGuess + } yield result).orDie + + recurringTask.repeat(Schedule.recurUntilEquals(true)) + } + + val tasks = (0 until parallelism).map(_ => task).toList + ZIO.raceAll(tasks.head, tasks.tail) + } + +} From b36917294d7b2b09c57e42e5020ea6b536909273 Mon Sep 17 00:00:00 2001 From: Ronald Wang Date: Wed, 17 Aug 2022 17:38:52 -0400 Subject: [PATCH 4/8] resolve Scala Lint error && ScalaFmt errors --- example/src/main/scala/example/SimpleStreamExample.scala | 5 ++--- example/src/main/scala/example/SimpleZioExample.scala | 5 ++--- example/src/main/scala/example/ZioProgram.scala | 6 +++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example/src/main/scala/example/SimpleStreamExample.scala b/example/src/main/scala/example/SimpleStreamExample.scala index 67eb0683d..77d1bf934 100644 --- a/example/src/main/scala/example/SimpleStreamExample.scala +++ b/example/src/main/scala/example/SimpleStreamExample.scala @@ -13,9 +13,8 @@ import org.slf4j.LoggerFactory import scala.concurrent.duration._ /** - * Another example useful to testing if stream instrumentation work. - * It's a simple example that prints amount of process elements roughly in 5 seconds intervals - * and after shutdown. + * Another example useful to testing if stream instrumentation work. It's a simple example that prints amount of process + * elements roughly in 5 seconds intervals and after shutdown. * * Data should be compared with information that can be found in prometheus. */ diff --git a/example/src/main/scala/example/SimpleZioExample.scala b/example/src/main/scala/example/SimpleZioExample.scala index 78485f885..67db85595 100644 --- a/example/src/main/scala/example/SimpleZioExample.scala +++ b/example/src/main/scala/example/SimpleZioExample.scala @@ -6,13 +6,12 @@ import zio.metrics.jvm.DefaultJvmMetrics //NOTE: code originally written by Łukasz Gajowy object SimpleZioExample extends ZIOAppDefault { - override def run: ZIO[Any, Throwable, Boolean] = { + override def run: ZIO[Any, Throwable, Boolean] = ZioProgram .findTheMeaningOfLife(3, Int.MinValue, Int.MaxValue) .provide( Runtime.enableRuntimeMetrics, // NOTE: refactored by following this zio-metrics-connectors example ( https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 ) - DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters + DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters ) - } } diff --git a/example/src/main/scala/example/ZioProgram.scala b/example/src/main/scala/example/ZioProgram.scala index f7f0c7f54..01068d0bf 100644 --- a/example/src/main/scala/example/ZioProgram.scala +++ b/example/src/main/scala/example/ZioProgram.scala @@ -1,6 +1,10 @@ package example -import zio.{Console, durationInt, Random, Schedule, ZIO} +import zio.Console +import zio.Random +import zio.Schedule +import zio.ZIO +import zio.durationInt //NOTE: code originally written by Łukasz Gajowy object ZioProgram { From 0c6af131000ff936f71dadbb42a780fe03ccbd65 Mon Sep 17 00:00:00 2001 From: Ronald W <109540973+ronaldSC-2022@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:20:19 -0400 Subject: [PATCH 5/8] Update docs/getting-started.md commit from Lucasz Gajowy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Gajowy --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index ddd54615f..02a87ef40 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -67,7 +67,7 @@ Both parts need to be included in the application for Mesmer to work. ## How to collect JVM Metrics from ZIO (for Mesmer): -In your ZIO Application, you will need to add the following lines of code: +In your ZIO Application, you will need to add the following layers: - `Runtime.enableRuntimeMetrics` - `DefaultJvmMetrics.live.unit` From 61e0e762593ad56749962174237b58f6ec8a06c5 Mon Sep 17 00:00:00 2001 From: Ronald W <109540973+ronaldSC-2022@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:20:49 -0400 Subject: [PATCH 6/8] Update docs/intro.md commit from Lukasz Gajowy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Gajowy --- docs/intro.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/intro.md b/docs/intro.md index 73297e3d1..a3d6341fd 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -21,7 +21,7 @@ https://www.youtube.com/watch?v=OF3YFGZcQkg - talk by the creator. Provides good ## OpenTelemetry -Initiative that goal is to create spec for observable systems and provide tools to implement it for different languages. +Initiative that's goal is to create a spec for observable systems and provide tools to implement it for different languages. java SDK - https://github.com/open-telemetry/opentelemetry-java tool for manual instrumentation java autoinstrumentation - https://github.com/open-telemetry/opentelemetry-java-instrumentation From f1e11540560f7222bfc45469081834f95575d9f4 Mon Sep 17 00:00:00 2001 From: Ronald W <109540973+ronaldSC-2022@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:22:14 -0400 Subject: [PATCH 7/8] Update example/src/main/scala/example/SimpleZioExample.scala commit from Lukasz Gajowy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Gajowy --- example/src/main/scala/example/SimpleZioExample.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/example/src/main/scala/example/SimpleZioExample.scala b/example/src/main/scala/example/SimpleZioExample.scala index 67db85595..048c39412 100644 --- a/example/src/main/scala/example/SimpleZioExample.scala +++ b/example/src/main/scala/example/SimpleZioExample.scala @@ -3,7 +3,6 @@ package example import zio._ import zio.metrics.jvm.DefaultJvmMetrics -//NOTE: code originally written by Łukasz Gajowy object SimpleZioExample extends ZIOAppDefault { override def run: ZIO[Any, Throwable, Boolean] = From 377f11eab460818b07249fe0b5c759f214d45413 Mon Sep 17 00:00:00 2001 From: Ronald Wang Date: Thu, 18 Aug 2022 13:31:36 -0400 Subject: [PATCH 8/8] PR refactoring per Jakub Czuchnowski PR comments --- docs/supported-metrics.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/supported-metrics.md b/docs/supported-metrics.md index 161dff630..17c9617fa 100644 --- a/docs/supported-metrics.md +++ b/docs/supported-metrics.md @@ -55,7 +55,7 @@ In Mesmer we support 3 types of metrics: | Operator throughput | counter | | Operator processing time | counter | -## ZIO (both Default-JVM-Metrics and others) +## ZIO Executor Metrics | Metric | Type | |---------------------------------------|-----------| @@ -65,6 +65,11 @@ In Mesmer we support 3 types of metrics: | Executor Enqueued Count | counter | | Executor Size | gauge | | Executor Worker Count | counter | + +## ZIO JVM Metrics + +| Metric | Type | +|---------------------------------------|-----------| | JVM Buffer Pool Capacity Bytes | gauge | | JVM Buffer Pool Used Buffers | gauge | | JVM Buffer Pool Used Bytes | gauge | @@ -89,7 +94,12 @@ In Mesmer we support 3 types of metrics: | JVM Threads Deadlocked Monitor | gauge | | JVM Threads Peak | gauge | | JVM Threads Started Total | gauge | -| Null | counter | + +## ZIO Runtime Metrics + +| Metric | Type | +|---------------------------------------|-----------| +| Forwarded Null | counter | | Process CPU Seconds Total | gauge | | Process Max FDS | gauge | | Process Open FDS | gauge |