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

Support "collection" tag in "mongodb.driver.commands" metric #1799

Closed
netme opened this issue Jan 15, 2020 · 2 comments · Fixed by #2337
Closed

Support "collection" tag in "mongodb.driver.commands" metric #1799

netme opened this issue Jan 15, 2020 · 2 comments · Fixed by #2337
Assignees
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Milestone

Comments

@netme
Copy link

netme commented Jan 15, 2020

Currently, mongodb.driver.commands metric exposes the following tags:

  • command
  • cluster.id
  • server.address
  • status

https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/mongodb/MongoMetricsCommandListener.java#L62

It would be great to make it more verbose and additionally expose MongoDB collection names.

@chrgue
Copy link

chrgue commented Jun 30, 2020

We were very happy when we found out there is a way to get such metrics.

But for services which are interacting with more than one collection the "collection" tag is mandatory to generate useful insights.

@netme
Copy link
Author

netme commented Jul 13, 2020

Thanks, @chrgue for taking a look at this ticket

I have tried to mock a possible solution:

public class MongoMetricsCommandListener implements CommandListener {

    private final ConcurrentHashMap<Integer, String> collectionsCache;
    
    // ... 

    @Override
    public void commandStarted(final CommandStartedEvent event) {
        extractCollectionName(event)
                .ifPresent(it -> collectionsCache.put(event.getRequestId(), it));
    }

    @Override
    public void commandSucceeded(final CommandSucceededEvent event) {
        timeCommand(event, getCollectionNameOrUnknown(event), "SUCCESS", event.getElapsedTime(TimeUnit.NANOSECONDS));
    }

    @Override
    public void commandFailed(final CommandFailedEvent event) {
        timeCommand(event, getCollectionNameOrUnknown(event), "FAILED", event.getElapsedTime(TimeUnit.NANOSECONDS));
    }
    // ...
}

MongoDB driver does expose the collection name, however, it is only available in commandStarted. We can try to use some cache to get this data accessible in both commandSucceeded and commandFailed. What do you think about this approach?

@jonatan-ivanov jonatan-ivanov self-assigned this Jun 28, 2021
@jonatan-ivanov jonatan-ivanov added enhancement A general enhancement module: micrometer-core An issue that is related to our core module labels Jun 28, 2021
@jonatan-ivanov jonatan-ivanov added this to the 1.8.0-M1 milestone Jun 28, 2021
onobc added a commit to onobc/micrometer that referenced this issue Jun 29, 2021
jonatan-ivanov pushed a commit that referenced this issue Jul 2, 2021
* Adds collection name tag to MongoMetricsCommandListener

Fixes gh-1799

* Fix checkstyle issue.

* Code review suggestions.

* Collapsed MongoCommandUtil into DefaultMongoCommandTagsProvider (same for its unit tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants