Skip to content

Commit

Permalink
Added examples of Apache Commons Pool to docs (#4570)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jan 16, 2024
1 parent 22e2b61 commit ea7431b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ asciidoc:
chomp: 'all'
include-java: 'example$docs-src/test/java/io/micrometer/docs'
include-resources: 'example$docs-src/test/resources'
include-core-test-java: 'example$core-test'
1 change: 1 addition & 0 deletions docs/modules/ROOT/examples/core-test
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
** xref:implementations/statsD.adoc[statsD]
** xref:implementations/wavefront.adoc[Wavefront]
* xref:reference.adoc[Reference Instrumentations]
** xref:reference/commons-pool.adoc[Apache Commons Pool]
** xref:reference/jvm.adoc[JVM]
** xref:reference/cache.adoc[Cache]
** xref:reference/okhttpclient.adoc[OkHttpClient]
Expand Down
18 changes: 18 additions & 0 deletions docs/modules/ROOT/pages/reference/commons-pool.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[overview]]
= Apache Commons Pool Instrumentation

https://commons.apache.org/proper/commons-pool/[Apache Commons Pool] is an open source software library provides an object-pooling API and a number of object pool implementations.

Below you can find an example of how to instrument Apache Commons Pool with Micrometer.

[source,java,subs=+attributes]
-----
// Setting up instrumentation
include::{include-core-test-java}/io/micrometer/core/instrument/binder/commonspool2/CommonsObjectPool2MetricsTest.java[tags=setup, indent=0]
// Generic Pool instrumentation (with examples of created meters)
include::{include-core-test-java}/io/micrometer/core/instrument/binder/commonspool2/CommonsObjectPool2MetricsTest.java[tags=generic_pool, indent=0]
// Generic Keyed Pool instrumentation (with examples of created meters)
include::{include-core-test-java}/io/micrometer/core/instrument/binder/commonspool2/CommonsObjectPool2MetricsTest.java[tags=generic_keyed_pool, indent=0]
-----
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ class CommonsObjectPool2MetricsTest {

private final MeterRegistry registry = new SimpleMeterRegistry();

// tag::setup[]
private final CommonsObjectPool2Metrics commonsObjectPool2Metrics = new CommonsObjectPool2Metrics(tags);

// end::setup[]

@AfterEach
void afterEach() {
commonsObjectPool2Metrics.close();
}

@Test
void verifyMetricsWithExpectedTags() {
// tag::generic_pool[]
try (GenericObjectPool<Object> p = createGenericObjectPool()) {
MeterRegistry registry = new SimpleMeterRegistry();
commonsObjectPool2Metrics.bindTo(registry);
Expand All @@ -72,10 +76,12 @@ void verifyMetricsWithExpectedTags() {
"commons.pool2.mean.borrow.wait")
.forEach(name -> registry.get(name).tags(tags).timeGauge());
}
// end::generic_pool[]
}

@Test
void verifyGenericKeyedObjectPoolMetricsWithExpectedTags() {
// tag::generic_keyed_pool[]
try (GenericKeyedObjectPool<Object, Object> p = createGenericKeyedObjectPool()) {
Tags tagsToMatch = tags.and("type", "GenericKeyedObjectPool");
commonsObjectPool2Metrics.bindTo(registry);
Expand All @@ -94,6 +100,7 @@ void verifyGenericKeyedObjectPoolMetricsWithExpectedTags() {
"commons.pool2.mean.borrow.wait")
.forEach(name -> registry.get(name).tags(tagsToMatch).timeGauge());
}
// end::generic_keyed_pool[]
}

@Test
Expand Down

0 comments on commit ea7431b

Please sign in to comment.