This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from diversit/feature/register-default-exporters
Added setting for automatic loading of default hotspot collectors
- Loading branch information
Showing
6 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
play.modules.enabled += com.github.stijndehaes.playprometheusfilters.PrometheusModule | ||
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 = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/com/github/stijndehaes/playprometheusfilters/PrometheusModuleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.github.stijndehaes.playprometheusfilters | ||
|
||
import io.prometheus.client.CollectorRegistry | ||
import org.scalatest.{BeforeAndAfter, MustMatchers, WordSpec} | ||
import play.api.inject.guice.GuiceApplicationBuilder | ||
|
||
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() | ||
.configure(PrometheusModule.defaultExportsKey -> true) | ||
.build() | ||
|
||
val collector = app.injector.instanceOf[CollectorRegistry] | ||
collector.getExporterNames.size must be > 0 | ||
} | ||
|
||
"not register default exporters when disabled" in { | ||
// disable default exporters | ||
val app = new GuiceApplicationBuilder() | ||
.configure(PrometheusModule.defaultExportsKey -> false) | ||
.build() | ||
|
||
val collector = app.injector.instanceOf[CollectorRegistry] | ||
collector.getExporterNames.size must be (0) | ||
} | ||
} | ||
|
||
/** | ||
* Utility to expose exporter names for test on [[CollectorRegistry]]. | ||
*/ | ||
implicit class CollectorRegistryExtention(val registry: CollectorRegistry) { | ||
/** | ||
* @return Registered exporter names. | ||
*/ | ||
def getExporterNames: Seq[String] = { | ||
val exportNames = collection.mutable.Buffer.empty[String] | ||
val mfs = registry.metricFamilySamples() | ||
while(mfs.hasMoreElements) { | ||
exportNames += mfs.nextElement().name | ||
} | ||
exportNames | ||
} | ||
} | ||
} |