@@ -33,6 +33,7 @@ import com.mongodb.event.CommandStartedEvent;
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Mark Paluch
|
||||
* @author Michal Domagala
|
||||
* @since 4.0
|
||||
*/
|
||||
class DefaultMongoHandlerObservationConvention implements MongoHandlerObservationConvention {
|
||||
@@ -54,21 +55,16 @@ class DefaultMongoHandlerObservationConvention implements MongoHandlerObservatio
|
||||
if (!ObjectUtils.isEmpty(user)) {
|
||||
keyValues = keyValues.and(LowCardinalityCommandKeyNames.DB_USER.withValue(user));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(context.getDatabaseName())) {
|
||||
keyValues = keyValues.and(LowCardinalityCommandKeyNames.DB_NAME.withValue(context.getDatabaseName()));
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(context.getCollectionName())) {
|
||||
keyValues = keyValues
|
||||
.and(LowCardinalityCommandKeyNames.MONGODB_COLLECTION.withValue(context.getCollectionName()));
|
||||
} else {
|
||||
keyValues = keyValues.and(LowCardinalityCommandKeyNames.MONGODB_COLLECTION.withValue(KeyValue.NONE_VALUE));
|
||||
}
|
||||
keyValues = keyValues.and(LowCardinalityCommandKeyNames.MONGODB_COLLECTION.withValue(
|
||||
ObjectUtils.isEmpty(context.getCollectionName()) ? KeyValue.NONE_VALUE : context.getCollectionName()));
|
||||
|
||||
if(context.getCommandStartedEvent() == null) {
|
||||
if (context.getCommandStartedEvent() == null) {
|
||||
throw new IllegalStateException("not command started event present");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.mongodb.event.CommandSucceededEvent;
|
||||
* @author Greg Turnquist
|
||||
* @author Mark Paluch
|
||||
* @author François Kha
|
||||
* @author Michal Domagala
|
||||
*/
|
||||
class MongoObservationCommandListenerTests {
|
||||
|
||||
@@ -99,8 +100,8 @@ class MongoObservationCommandListenerTests {
|
||||
assertThat(meterRegistry).hasMeterWithName("spring.data.mongodb.command.active");
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandStartedShouldIncludeCollectionIfMissing() {
|
||||
@Test // GH-4994
|
||||
void commandStartedShouldAlwaysIncludeCollection() {
|
||||
|
||||
// when
|
||||
listener.commandStarted(new CommandStartedEvent(new MapRequestContext(), 0, 0, null, "some name", "hello", null));
|
||||
@@ -110,7 +111,6 @@ class MongoObservationCommandListenerTests {
|
||||
assertThat(meterRegistry).hasMeterWithNameAndTags(
|
||||
"spring.data.mongodb.command.active",
|
||||
Tags.of("db.mongodb.collection", "none"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user