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

Enable more MongoDB Micrometer metrics #44999

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid producing empty AdditionalIndexedClassesBuildItem
Even if it doesn't complain right now,
that's certainly something that could break later
  • Loading branch information
vkn committed Dec 17, 2024
commit be1fa4096d3b856f2080caee5c38439d87ace108
5 changes: 5 additions & 0 deletions extensions/mongodb-client/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -91,6 +91,11 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Original file line number Diff line number Diff line change
@@ -126,18 +126,18 @@ AdditionalIndexedClassesBuildItem includeMongoCommandListener(MongoClientBuildTi
}

@BuildStep
AdditionalIndexedClassesBuildItem includeMongoCommandMetricListener(
void includeMongoCommandMetricListener(
BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses,
MongoClientBuildTimeConfig buildTimeConfig,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
if (!buildTimeConfig.metricsEnabled) {
return new AdditionalIndexedClassesBuildItem();
return;
}
boolean withMicrometer = metricsCapability.map(cap -> cap.metricsSupported(MetricsFactory.MICROMETER))
.orElse(false);
if (withMicrometer) {
return new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName());
additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName()));
}
return new AdditionalIndexedClassesBuildItem();
}

@BuildStep
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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
@@ -25,13 +30,16 @@ void testIncludeMongoCommandMetricListener(boolean metricsEnabled, boolean micro
MongoClientBuildTimeConfig config = config(metricsEnabled);
Optional<MetricsCapabilityBuildItem> capability = capability(metricsEnabled, micrometerSupported);

AdditionalIndexedClassesBuildItem result = buildStep.includeMongoCommandMetricListener(config, capability);
BuildProducer<AdditionalIndexedClassesBuildItem> buildProducer = mock(BuildProducer.class);
buildStep.includeMongoCommandMetricListener(buildProducer, config, capability);

if (expectedResult) {
assertThat(result.getClassesToIndex())
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 {
assertThat(result.getClassesToIndex()).isEmpty();
verify(buildProducer, never()).produce(any(AdditionalIndexedClassesBuildItem.class));
}
}

Loading