Skip to content

Commit

Permalink
Statsd/DogStatsD support (#28)
Browse files Browse the repository at this point in the history
* Update to ZIO RC11-1

* Update to latest zio

* Counter with module pattern

*  Compiles

* Dropwizard Counter test working

* Gauges works

* Counters working

* Gauge implemented

* Common API for Gauge is reduced to getValue

* Histogram implemented

* Multi-project compiles

* Dropwizard completed up to Meter

* Basic Dropwizard usage complete

* Basic Prometheus working

* Different names for each jar

* Start labels implementation

* Prometheus Histogram and Summary ready

* Exporters fro dropwizard working

* Renamed ExportersTests to ReportersTEsts for Prometheus module

* Write004 as part of the exporters

* Prometheus exporter test completed

* Small fixes for consistency

* Doc up to prometheus histogram

* Add duration timer histogram test and bump to scala 2.12.9

* Registry helpers finished

* Minor fixes

* Add helpers to docs and tests

* Add histogram buckets examples

* Prometheus documentation ready

* Encapsulate metrics

* Seal the trait, case classes are not necessary

* Prometheus refactored

* Moved helpers to their own module

* Documentation updated

* formatting

* :Encapsulation for Dropwizard metrics

* Dropwizard Tests ready and half documentation

* Server only on Scala 2.12

* Documentation and trying to fix ServerTest

* ServerTest fixed

* Add scala-2.11 back to circle and format

* Dropwizard docs ready

* Format

* Statsd encoder

* DogstatD init

* Event test failing

* Fix events test

* Remove println

* DogStatsD implemented

* Formatting

* Allow custom processor for Client

* StatsD docs, WIP

* StatsD docs completed

* Upgrade Silencer

* Format

* 2.13 classes for dropwizard and try to ignore statsd for 2.11

* Disable 2.11 and enable 2.13

* Use circe instead of argonaut to support scala 2.12 for Dropwizard module

* Use cats Monoid and Foldable
  • Loading branch information
toxicafunk authored Feb 9, 2020
1 parent c0dc166 commit e847279
Show file tree
Hide file tree
Showing 28 changed files with 1,797 additions and 103 deletions.
32 changes: 28 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ scala_211: &scala_211
scala_212: &scala_212
SCALA_VERSION: 2.12.8

scala_213: &scala_213
SCALA_VERSION: 2.13.1

scala_dotty: &scala_dotty
SCALA_VERSION: 0.16.0-RC3

Expand Down Expand Up @@ -220,6 +223,13 @@ jobs:
- <<: *scala_212
- <<: *jdk_8

test_213_jdk8_jvm:
<<: *test
<<: *machine_ubuntu
environment:
- <<: *scala_213
- <<: *jdk_8

test_dotty_jdk8_jvm:
<<: *test
<<: *machine_ubuntu
Expand All @@ -241,6 +251,13 @@ jobs:
- <<: *scala_212
- <<: *jdk_11

test_213_jdk11_jvm:
<<: *test
<<: *machine_ubuntu
environment:
- <<: *scala_213
- <<: *jdk_11

test_dotty_jdk11_jvm:
<<: *test
<<: *machine_ubuntu
Expand All @@ -255,6 +272,13 @@ jobs:
- <<: *scala_211
- <<: *jdk_8

release_213:
<<: *release
<<: *machine_ubuntu
environment:
- <<: *scala_213
- <<: *jdk_8

release:
<<: *release
<<: *machine_ubuntu
Expand Down Expand Up @@ -287,12 +311,12 @@ workflows:
- lint
filters:
<<: *filter_tags
- test_211_jdk8_jvm:
- test_213_jdk8_jvm:
requires:
- lint
filters:
<<: *filter_tags
- test_211_jdk11_jvm:
- test_213_jdk11_jvm:
requires:
- lint
filters:
Expand All @@ -318,8 +342,8 @@ workflows:
- release:
context: Sonatype2
requires:
- test_211_jdk8_jvm
- test_211_jdk11_jvm
- test_213_jdk8_jvm
- test_213_jdk11_jvm
- test_212_jdk8_jvm
- test_212_jdk11_jvm
- mdoc
Expand Down
38 changes: 26 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ val zioVersion = "1.0.0-RC17"
val interopVersion = "2.0.0.0-RC10" // "1.3.1.0-RC3"
val prometheusVersion = "0.7.0"
val dropwizardVersion = "4.0.1"
val circeVersion = "0.12.3"

addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

lazy val root =
(project in file("."))
.aggregate(common, dropwizard, prometheus)
.settings(settings)
lazy val root = (project in file("."))
.aggregate(common, dropwizard, prometheus, statsd)
.settings(settings)

lazy val common = project
.settings(
Expand Down Expand Up @@ -60,6 +60,18 @@ lazy val prometheus = project
)
.dependsOn(common)

lazy val statsd = project
.settings(
name := "statsd",
crossScalaVersions -= "2.11.12",
stdSettings("metrics-statsd") ++ settings,
libraryDependencies ++= commonDependencies ++ (CrossVersion.partialVersion(scalaBinaryVersion.value) match {
case Some((2, 11)) => Seq()
case _ => statsdDependencies
})
)
.dependsOn(common)

lazy val commonDependencies = Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-interop-cats" % interopVersion,
Expand All @@ -81,7 +93,11 @@ lazy val dropwizardDependencies = Seq(
"io.dropwizard.metrics" % "metrics-healthchecks" % dropwizardVersion,
"io.dropwizard.metrics" % "metrics-jmx" % dropwizardVersion,
"io.dropwizard.metrics" % "metrics-graphite" % dropwizardVersion,
"io.argonaut" %% "argonaut" % "6.2.2"
"io.circe" %% "circe-core" % circeVersion
)

lazy val statsdDependencies = Seq(
"dev.zio" %% "zio-nio" % "1.0.0-RC2"
)

lazy val docs = project
Expand All @@ -93,27 +109,25 @@ lazy val docs = project
moduleName := "zio-metrics-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= commonDependencies ++ dropwizardDependencies ++ prometheusDependencies
libraryDependencies ++= commonDependencies ++ statsdDependencies ++ dropwizardDependencies ++ prometheusDependencies
)
.dependsOn(common, prometheus, dropwizard)
.dependsOn(common, prometheus, dropwizard, statsd)
.enablePlugins(MdocPlugin, DocusaurusPlugin)

lazy val settings = Seq(
scalacOptions ++= (CrossVersion.partialVersion(scalaBinaryVersion.value) match {
case Some((2, 11)) => Seq("-Ypartial-unification", "-Ywarn-value-discard", "-target:jvm-1.8")
case Some((2, 13)) => Seq("-Ywarn-value-discard", "-target:jvm-1.8")
case _ => Seq("-Ypartial-unification", "-Ywarn-value-discard")
})
)

lazy val http4s = Seq(
"org.http4s" %% "http4s-argonaut" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.typelevel" %% "cats-effect" % "2.0.0", //% Optional,
"io.argonaut" %% "argonaut-cats" % "6.2.2"
"org.typelevel" %% "cats-effect" % "2.0.0" //% Optional,
)

addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")

// TODO: enforce scalazzi dialect through the scalaz-plugin
// addCompilerPlugin("org.scalaz" % "scalaz-plugin_2.12.4" % "0.0.7")
2 changes: 1 addition & 1 deletion docs/essentials/dropwizard.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: essentials_sockets
id: essentials_dropwizard
title: "Dropwizard ZIO WSrapper"
---

Expand Down
19 changes: 15 additions & 4 deletions docs/essentials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@ id: essentials_index
title: "Overview"
---

ZIO-Metrics is a thin wrapper over both Prometheus and Dropwizard intrumentation
ZIO-Metrics is both:
1. a thin wrapper over both Prometheus and Dropwizard intrumentation
libraries allowing you to measure the behaviour of your application in a
performant purely functional manner.
2. a pure ZIO StatsD/DogStatsD client heavily inspired on [Censorinus](https://github.com/gphat/censorinus)

`If it can affect your code's business value, measure it.` -- Coda Hale

`In order to know how well our *code* is generating *business value*, we need *metrics*` -- also Coda Hale


ZIO-Metrics follows [the module pattern in
ZIO](https://zio.dev/docs/howto/howto_use_module_pattern) to provide modules for Prometheus and Dropwizard metrics.
ZIO](https://zio.dev/docs/howto/howto_use_module_pattern) to provide modules for
Prometheus and Dropwizard metrics as well as modules for StatsD and DogStatsdD
Encoders and Clients.

- **[Prometheus](prometheus.md)** — Prometheus ZIO Wrapper.
- **[Dropwizard](dropwizard.md)** — Dropwizard ZIO Wrapper.
- **[StatsD](statsd.md)** — StatsD/DogStatsD Pure ZIO client.

## Installation

`ZIO-Metrics` is available via Maven, thus an import in `build.sbt` is enough:

```scala
// Prometheus
libraryDependencies += "dev.zio" %% "zio-metrics-prometheus" % "0.0.9"
libraryDependencies += "dev.zio" %% "zio-metrics-prometheus" % "0.1.0"

// Dropwizard
libraryDependencies += "dev.zio" %% "zio-metrics-dropwizard" % "0.0.9"
libraryDependencies += "dev.zio" %% "zio-metrics-dropwizard" % "0.1.0"

// StatsD/DogStatsD
libraryDependencies += "dev.zio" %% "zio-metrics-statsd" % "0.1.0"
```

## References

- [ZIO github page](http://github.com/zio/zio)
- [Prometheus Java Client](https://github.com/prometheus/client_java)
- [Dropwizard Metrics Core](https://metrics.dropwizard.io/4.0.0/manual/core.html)
- [Censorinus](https://github.com/gphat/censorinus)
- [StatsD Metric Types](https://github.com/statsd/statsd/blob/master/docs/metric_types.md)
- [DogStatsD Datagram Format](https://docs.datadoghq.com/developers/dogstatsd/datagram_shell)
2 changes: 1 addition & 1 deletion docs/essentials/prometheus.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: essentials_files
id: essentials_prometheus
title: "Prometheus ZIO Wrapper"
---

Expand Down
Loading

0 comments on commit e847279

Please sign in to comment.