Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Switched back to using default registry cause it causes problems with…
Browse files Browse the repository at this point in the history
… other metrics like Hikari metric.

In test clearing registry before each test. Had to change default to 'false' otherwise could not get test working when running all test. Disabling parallel test execution also did not help. No idea why.
Updated Readme.
  • Loading branch information
Joost den Boer committed Sep 13, 2018
1 parent 9726075 commit f4610aa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ You should be able to immediately get the metrics

The [Prometheus Hotspot library](https://github.com/prometheus/client_java#included-collectors) provides some default collectors
for garbage collection, memory pool, etc.
Default these collectors are registered. This can be changed by setting the configuration property to `false`.
Default these collectors are _not_ registered. This can be changed by setting the configuration property to `true`.

```
play-prometheus-filters.register-default-hotspot-collectors = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,15 @@ object PrometheusModule {
class PrometheusModule extends Module {
import PrometheusModule._

/**
* Registering default exporters. See [[DefaultExports.initialize()]]
*
* Not using DefaultExports.initialize since that makes it impossible to test.
* Guice guarantees this is only run once for an application.
*/
def registerDefaultExporters(registry: CollectorRegistry): Unit = {
registry.register(new StandardExports)
registry.register(new MemoryPoolsExports)
registry.register(new BufferPoolsExports)
registry.register(new GarbageCollectorExports)
registry.register(new ThreadExports)
registry.register(new ClassLoadingExports)
registry.register(new VersionInfoExports)
}

override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
val registry = new CollectorRegistry(true)

configuration.getOptional[Boolean](defaultExportsKey).foreach { enabled =>
if (enabled) {
registerDefaultExporters(registry)
DefaultExports.initialize()
}
}

Seq(
bind[CollectorRegistry].to(registry)
bind[CollectorRegistry].to(CollectorRegistry.defaultRegistry)
)
}
}
2 changes: 1 addition & 1 deletion conf/reference.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
play.modules.enabled += com.github.stijndehaes.playprometheusfilters.PrometheusModule

# Registers some default collectors for jvm metrics. See DefaultExports class.
play-prometheus-filters.register-default-hotspot-collectors = true
play-prometheus-filters.register-default-hotspot-collectors = false
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.github.stijndehaes.playprometheusfilters

import io.prometheus.client.CollectorRegistry
import org.scalatest.{MustMatchers, WordSpec}
import org.scalatest.{BeforeAndAfter, MustMatchers, WordSpec}
import play.api.inject.guice.GuiceApplicationBuilder

class PrometheusModuleSpec extends WordSpec with MustMatchers {
class PrometheusModuleSpec extends WordSpec with MustMatchers with BeforeAndAfter {

before {
// clearing registry before each test
CollectorRegistry.defaultRegistry.clear()
}

"PrometheusModule" should {
"register default exporters when enabled" in {
// default enabled
val app = new GuiceApplicationBuilder().build()
val app = new GuiceApplicationBuilder()
.configure(PrometheusModule.defaultExportsKey -> true)
.build()

val collector = app.injector.instanceOf[CollectorRegistry]
collector.getExporterNames.size must be > 0
Expand Down

0 comments on commit f4610aa

Please sign in to comment.