Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add docs on testing MetricRegistry implementation #62

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ lazy val docs = project
),
scalacOptions := Seq()
)
.dependsOn(core, java)
.dependsOn(core, java, testing)
.enablePlugins(TypelevelSitePlugin)

lazy val unidocs = project
Expand Down
34 changes: 34 additions & 0 deletions docs/implementations/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Testing Registry

There exists a testing `MetricRegistry` implementation which allows you to check the value
history of any created metrics. For `Histogram` and `Summary` this is a `Chain` of all
the values that have been `observe`d for that metric. For `Counter` and `Gauge` this is
the history of the current value of the metric over time.

```scala mdoc:silent
import cats.syntax.all._
import cats.data.Chain
import cats.effect._
import prometheus4cats._
import prometheus4cats.testing._

TestingMetricRegistry[IO].flatMap { reg =>
val factory = MetricFactory.builder.build(reg)
factory
.counter("counter_total")
.ofDouble
.help("Describe what this metric does")
.build
.use { counter =>
counter.inc >> counter.inc(2.0)
reg.counterHistory(
Counter.Name("counter_total"),
Metric.CommonLabels.empty
).flatMap { hist =>
IO(hist === Some(Chain(0.0, 1.0, 3.0)))
}
}
}
```


7 changes: 4 additions & 3 deletions docs/interface/metric-factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ MetricFactory.WithCallbacks.noop[IO]
MetricFactory.builder.noop[IO]
```

### Constructing from a `MetricRegitry`
### Constructing from a `MetricRegistry`

`MetricRegitry` provides a builder with a fluent API that allows you to create an instance that adds an optional
`MetricRegistry` provides a builder with a fluent API that allows you to create an instance that adds an optional
prefix and/or common label set to all metrics.

```scala mdoc
Expand All @@ -65,6 +65,7 @@ MetricFactory
```

Common labels are a set of labels that are checked at runtime so that the label names conform to the [OpenMetrics]

format and no more than ten are defined at any one time, which helps to reduce cardinality.

There is no compile time checking of these labels as it is assumed they will come from the runtime environment.
Expand Down Expand Up @@ -159,7 +160,7 @@ val factoryWithCallbacksG = factoryWithCallbacksF.imapK(fk, gk)

It is also possible to construct a `MetricsFactory.WithCallbacks` from a `MetricsFactory` and [`CallbackRegistry`]:

```scala
```scala mdoc
val callbackRegistryG: CallbackRegistry[G] = CallbackRegistry.noop[G]

MetricFactory.builder.build(factoryG, callbackRegistryG)
Expand Down