Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added examples of Apache Commons Pool #4570

Merged
merged 1 commit into from
Jan 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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