Skip to content

Commit

Permalink
Encapsulation (#15)
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
  • Loading branch information
toxicafunk authored Dec 4, 2019
1 parent 20d411d commit 4a0e6b3
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 505 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ lazy val prometheus = project
.settings(
name := "prometheus",
stdSettings("metrics-prometheus") ++ settings,
libraryDependencies ++= commonDependencies ++ prometheusDependencies
libraryDependencies ++= commonDependencies ++ prometheusDependencies ++ dropwizardDependencies
)
.dependsOn(common)

Expand Down
2 changes: 1 addition & 1 deletion docs/essentials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ both Prometheus and Dropwizard library.
`ZIO-Metrics` is available via maven repo so import in `build.sbt` is sufficient:

```scala
libraryDependencies += "dev.zio" %% "zio-metrics" % "0.0.4"
libraryDependencies += "dev.zio" %% "zio-metrics" % "0.0.5"
```

## References
Expand Down
227 changes: 110 additions & 117 deletions docs/essentials/prometheus.md

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions prometheus/src/main/scala/zio/metrics/Counter.scala

This file was deleted.

28 changes: 0 additions & 28 deletions prometheus/src/main/scala/zio/metrics/Gauge.scala

This file was deleted.

19 changes: 0 additions & 19 deletions prometheus/src/main/scala/zio/metrics/Histogram.scala

This file was deleted.

19 changes: 0 additions & 19 deletions prometheus/src/main/scala/zio/metrics/Summary.scala

This file was deleted.

116 changes: 26 additions & 90 deletions prometheus/src/main/scala/zio/metrics/prometheus/Helpers.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zio.metrics.prometheus
package zio.metrics.prometheus.helpers

import zio.RIO

Expand All @@ -8,6 +8,7 @@ import io.prometheus.client.CollectorRegistry
import io.prometheus.client.exporter.HTTPServer
import io.prometheus.client.exporter.HttpConnectionFactory
import zio.metrics.{ Buckets, DefaultBuckets, Label }
import zio.metrics.prometheus._
import zio.metrics.prometheus.PrometheusRegistry.{ Percentile, Tolerance }

object registry {
Expand Down Expand Up @@ -96,112 +97,47 @@ object registry {
}

object counter {
def inc(pCounter: PCounter): RIO[PrometheusCounter, Unit] = RIO.accessM(_.counter.inc(pCounter, Array.empty[String]))
def register(name: String) =
Counter(name, Array.empty[String])

def inc(pCounter: PCounter, amount: Double): RIO[PrometheusCounter, Unit] =
RIO.accessM(_.counter.inc(pCounter, amount, Array.empty[String]))

def inc(pCounter: PCounter, labelNames: Array[String]): RIO[PrometheusCounter, Unit] =
RIO.accessM(_.counter.inc(pCounter, labelNames))

def inc(pCounter: PCounter, amount: Double, labelNames: Array[String]): RIO[PrometheusCounter, Unit] =
RIO.accessM(_.counter.inc(pCounter, amount, labelNames))
def register(name: String, labels: Array[String]) =
Counter(name, labels)
}

object gauge {
def getValue(g: PGauge): RIO[PrometheusGauge, Double] =
RIO.accessM(_.gauge.getValue(g, Array.empty[String]))

def inc(g: PGauge): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, Array.empty[String]))

def dec(g: PGauge): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.dec(g, Array.empty[String]))

def inc(g: PGauge, amount: Double): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, Array.empty[String]))

def dec(g: PGauge, amount: Double): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, Array.empty[String]))

def set(g: PGauge, amount: Double): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, Array.empty[String]))

def setToCurrentTime(g: PGauge): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.setToCurrentTime(g, Array.empty[String]))

def setToTime(g: PGauge, f: () => Unit): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.setToTime(g, f, Array.empty[String]))

def getValue(g: PGauge, labelNames: Array[String]): RIO[PrometheusGauge, Double] =
RIO.accessM(_.gauge.getValue(g, labelNames))

def inc(g: PGauge, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, labelNames))
def register(name: String) =
Gauge(name, Array.empty[String])

def dec(g: PGauge, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.dec(g, labelNames))

def inc(g: PGauge, amount: Double, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, labelNames))

def dec(g: PGauge, amount: Double, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, labelNames))

def set(g: PGauge, amount: Double, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.inc(g, amount, labelNames))

def setToCurrentTime(g: PGauge, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.setToCurrentTime(g, labelNames))

def setToTime(g: PGauge, labelNames: Array[String]): RIO[PrometheusGauge, Unit] =
RIO.accessM(_.gauge.setToTime(g, () => Thread.sleep(1000), labelNames))
def register(name: String, labels: Array[String]) =
Gauge(name, labels)
}

object histogram {
def observe(h: PHistogram, amount: Double): RIO[PrometheusHistogram, Unit] =
RIO.accessM(_.histogram.observe(h, amount, Array.empty[String]))

def startTimer(h: PHistogram): RIO[PrometheusHistogram, PHistogram.Timer] =
RIO.accessM(_.histogram.startTimer(h, Array.empty[String]))
def register(name: String) =
Histogram(name, Array.empty[String], DefaultBuckets(Seq.empty[Double]))

def observeDuration(timer: PHistogram.Timer): RIO[PrometheusHistogram, Double] =
RIO.accessM(_.histogram.observeDuration(timer))
def register(name: String, labels: Array[String]) =
Histogram(name, labels, DefaultBuckets(Seq.empty[Double]))

def time(h: PHistogram, f: () => Unit): RIO[PrometheusHistogram, Double] =
RIO.accessM(_.histogram.time(h, f, Array.empty[String]))
def register(name: String, buckets: Buckets) =
Histogram(name, Array.empty[String], buckets)

def observe(h: PHistogram, amount: Double, labelNames: Array[String]): RIO[PrometheusHistogram, Unit] =
RIO.accessM(_.histogram.observe(h, amount, labelNames))

def startTimer(h: PHistogram, labelNames: Array[String]): RIO[PrometheusHistogram, PHistogram.Timer] =
RIO.accessM(_.histogram.startTimer(h, labelNames))

def time(h: PHistogram, f: () => Unit, labelNames: Array[String]): RIO[PrometheusHistogram, Double] =
RIO.accessM(_.histogram.time(h, f, labelNames))
def register(name: String, labels: Array[String], buckets: Buckets) =
Histogram(name, labels, buckets)
}

object summary {
def observe(s: PSummary, amount: Double): RIO[PrometheusSummary, Unit] =
RIO.accessM(_.summary.observe(s, amount, Array.empty[String]))

def startTimer(s: PSummary): RIO[PrometheusSummary, PSummary.Timer] =
RIO.accessM(_.summary.startTimer(s, Array.empty[String]))

def observeDuration(timer: PSummary.Timer): RIO[PrometheusSummary, Double] =
RIO.accessM(_.summary.observeDuration(timer))

def time(s: PSummary, f: () => Unit): RIO[PrometheusSummary, Double] =
RIO.accessM(_.summary.time(s, f, Array.empty[String]))
def register(name: String) =
Summary(name, Array.empty[String], List.empty[(Double, Double)])

def observe(s: PSummary, amount: Double, labelNames: Array[String]): RIO[PrometheusSummary, Unit] =
RIO.accessM(_.summary.observe(s, amount, labelNames))
def register(name: String, labels: Array[String]) =
Summary(name, labels, List.empty[(Percentile, Tolerance)])

def startTimer(s: PSummary, labelNames: Array[String]): RIO[PrometheusSummary, PSummary.Timer] =
RIO.accessM(_.summary.startTimer(s, labelNames))
def register(name: String, percentiles: List[(Percentile, Tolerance)]) =
Summary(name, Array.empty[String], percentiles)

def time(s: PSummary, f: () => Unit, labelNames: Array[String]): RIO[PrometheusSummary, Double] =
RIO.accessM(_.summary.time(s, f, labelNames))
def register(name: String, labels: Array[String], percentiles: List[(Percentile, Tolerance)]) =
Summary(name, labels, percentiles)
}

object exporters {
Expand Down
Loading

0 comments on commit 4a0e6b3

Please sign in to comment.