forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 quarkusio#44999 from vkn/mongodb-micrometer-metrics
Enable more MongoDB Micrometer metrics
- Loading branch information
Showing
7 changed files
with
135 additions
and
58 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
59 changes: 59 additions & 0 deletions
59
...ient/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java
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,59 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem; | ||
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; | ||
import io.quarkus.runtime.metrics.MetricsFactory; | ||
|
||
class MongoClientProcessorTest { | ||
private final MongoClientProcessor buildStep = new MongoClientProcessor(); | ||
|
||
@SuppressWarnings("unchecked") | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"true, true, true", // Metrics enabled and Micrometer supported | ||
"true, false, false", // Metrics enabled but Micrometer not supported | ||
"false, true, false", // Metrics disabled and Micrometer supported | ||
"false, false, false" // Metrics disabled and Micrometer not supported | ||
}) | ||
void testIncludeMongoCommandMetricListener(boolean metricsEnabled, boolean micrometerSupported, boolean expectedResult) { | ||
MongoClientBuildTimeConfig config = config(metricsEnabled); | ||
Optional<MetricsCapabilityBuildItem> capability = capability(metricsEnabled, micrometerSupported); | ||
|
||
BuildProducer<AdditionalIndexedClassesBuildItem> buildProducer = mock(BuildProducer.class); | ||
buildStep.includeMongoCommandMetricListener(buildProducer, config, capability); | ||
|
||
if (expectedResult) { | ||
var captor = ArgumentCaptor.forClass(AdditionalIndexedClassesBuildItem.class); | ||
verify(buildProducer, times(1)).produce(captor.capture()); | ||
assertThat(captor.getAllValues().get(0).getClassesToIndex()) | ||
.containsExactly("io.quarkus.mongodb.metrics.MicrometerCommandListener"); | ||
} else { | ||
verify(buildProducer, never()).produce(any(AdditionalIndexedClassesBuildItem.class)); | ||
} | ||
} | ||
|
||
private static Optional<MetricsCapabilityBuildItem> capability(boolean metricsEnabled, boolean micrometerSupported) { | ||
MetricsCapabilityBuildItem capability = metricsEnabled | ||
? new MetricsCapabilityBuildItem(factory -> MetricsFactory.MICROMETER.equals(factory) && micrometerSupported) | ||
: null; | ||
return Optional.ofNullable(capability); | ||
} | ||
|
||
private static MongoClientBuildTimeConfig config(boolean metricsEnabled) { | ||
MongoClientBuildTimeConfig buildTimeConfig = new MongoClientBuildTimeConfig(); | ||
buildTimeConfig.metricsEnabled = metricsEnabled; | ||
return buildTimeConfig; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...db-client/runtime/src/main/java/io/quarkus/mongodb/metrics/MicrometerCommandListener.java
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,14 @@ | ||
package io.quarkus.mongodb.metrics; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener; | ||
|
||
public class MicrometerCommandListener extends MongoMetricsCommandListener { | ||
@Inject | ||
public MicrometerCommandListener(MeterRegistry registry) { | ||
super(registry); | ||
} | ||
|
||
} |
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