Skip to content

Commit a962c98

Browse files
authored
Polish MongoDB binder changes (#3099)
1 parent 3eb5072 commit a962c98

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

micrometer-binders/src/main/java/io/micrometer/binder/mongodb/DefaultMongoCommandTagsProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public class DefaultMongoCommandTagsProvider implements MongoCommandTagsProvider
3636

3737
private static final WarnThenDebugLogger WARN_THEN_DEBUG_LOGGER = new WarnThenDebugLogger(DefaultMongoCommandTagsProvider.class);
3838

39-
private final ConcurrentMap<Integer, MongoCommandStartedEventTags> inFlightCommandStartedEventTags = new ConcurrentHashMap<>();
39+
private final ConcurrentMap<Integer, MongoCommandStartedEventTags> inFlightCommandStartedEventTagsByRequestId = new ConcurrentHashMap<>();
4040

4141
@Override
4242
public Iterable<Tag> commandTags(CommandEvent event) {
43-
Optional<MongoCommandStartedEventTags> mongoCommandStartedEventTags = Optional.ofNullable(inFlightCommandStartedEventTags.remove(event.getRequestId()));
43+
Optional<MongoCommandStartedEventTags> mongoCommandStartedEventTags = Optional.ofNullable(inFlightCommandStartedEventTagsByRequestId.remove(event.getRequestId()));
4444
return Tags.of(
4545
Tag.of("command", event.getCommandName()),
4646
Tag.of("database", mongoCommandStartedEventTags.map(MongoCommandStartedEventTags::getDatabase).orElse("unknown")),
@@ -53,12 +53,12 @@ public Iterable<Tag> commandTags(CommandEvent event) {
5353
@Override
5454
public void commandStarted(CommandStartedEvent event) {
5555
MongoCommandStartedEventTags tags = new MongoCommandStartedEventTags(event);
56-
addTagsForStartedCommandEvent(event, tags);
56+
addTagsForCommandStartedEvent(event, tags);
5757
}
5858

59-
private void addTagsForStartedCommandEvent(CommandEvent event, MongoCommandStartedEventTags tags) {
60-
if (inFlightCommandStartedEventTags.size() < 1000) {
61-
inFlightCommandStartedEventTags.put(event.getRequestId(), tags);
59+
private void addTagsForCommandStartedEvent(CommandEvent event, MongoCommandStartedEventTags tags) {
60+
if (inFlightCommandStartedEventTagsByRequestId.size() < 1000) {
61+
inFlightCommandStartedEventTagsByRequestId.put(event.getRequestId(), tags);
6262
return;
6363
}
6464
// Cache over capacity

micrometer-binders/src/main/java/io/micrometer/binder/mongodb/MongoCommandStartedEventTags.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 VMware, Inc.
2+
* Copyright 2022 VMware, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,22 +33,22 @@ class MongoCommandStartedEventTags {
3333
"aggregate", "count", "distinct", "mapReduce", "geoSearch", "delete", "find", "findAndModify",
3434
"insert", "update", "collMod", "compact", "convertToCapped", "create", "createIndexes", "drop",
3535
"dropIndexes", "killCursors", "listIndexes", "reIndex"));
36-
public static final String UNKNOWN = "unknown";
36+
private static final String UNKNOWN = "unknown";
3737

38-
public MongoCommandStartedEventTags(CommandStartedEvent event) {
38+
private final String collection;
39+
private final String database;
40+
41+
MongoCommandStartedEventTags(CommandStartedEvent event) {
3942
this.database = event.getDatabaseName();
40-
this.collection = this.determineCollectionName(event.getCommandName(), event.getCommand())
43+
this.collection = determineCollectionName(event.getCommandName(), event.getCommand())
4144
.orElse(UNKNOWN);
4245
}
4346

44-
private final String collection;
45-
private final String database;
46-
47-
public String getDatabase() {
47+
String getDatabase() {
4848
return database;
4949
}
5050

51-
public String getCollection() {
51+
String getCollection() {
5252
return collection;
5353
}
5454

micrometer-binders/src/test/java/io/micrometer/binder/mongodb/MongoCommandStartedEventTagsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 VMware, Inc.
2+
* Copyright 2022 VMware, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)