The metric introduced on SB2.5 for Spring Data invocations, better described in #22217, is really handy. I would like to propose just a small improvement to it - I think it would be good to add an additional tag that states which is the type of the repository. The tag could be named something like type or repositoryType and then have for values the interface names like MongoRepository, JpaRepository, RedisRepository, etc

I think this can be an important addition for someone assessing performance, to be able to segregate metrics by the type of datasource being targetted.

Comment From: wilkinsona

Thanks for the suggestion, but I am not sure that this is possible.

We implement Spring Data's RepositoryMethodInvocationListener which is called with a RepositoryMethodInvocation. This gives us access to the Class for the repository interface but that isn't sufficient to identify that type of store that's being targeted. For example, in Boot's own smoke tests we have a CityRepository that extends Repository<City, Long> – it's used with JPA but it doesn't extend JpaRepository. Furthermore, not all stores have a store-specific interface. For example, there's no RedisRepository interface AFAIK.

If you have a convention in your application that allows you to map from a Repository sub-interface to a particular store type, you could define your own org.springframework.boot.actuate.metrics.data.RepositoryTagsProvider bean that provides the desired type or repositoryType tag. Beyond that, to do something more generally, I think we'd need a way of mapping from an interface to the store type or we'd need more information to be available on the RepositoryMethodInvocation.

@mp911de is there anything already in Spring Data that would let Boot's or a user's own RepositoryTagsProvider map from the repository interface to the type of store that's backing the interface?

Comment From: nhmarujo

If you have access to the Class, maybe something like:

String type = Arrays.stream(repositoryClass.getInterfaces())
                        .filter(Repository.class::isAssignableFrom)
                        .findFirst()
                        .map(Class::getSimpleName)
                        .orElse("Unknown");

Not sure if good enough, is just an idea 😅

But I agree that, if something can be explicitly obtained from Spring Data, it would be a better and cleaner solution.

Comment From: mp911de

Spring Data isn't integrating with Micrometer hence there's no concepts of tagging in Spring Data. Spring Boot integrates by inspecting RepositoryFactoryBeanSupport respective customizing RepositoryFactorySupport objects. Each Spring Data module has its own variant of RepositoryFactoryBeanSupport (org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean, org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean). Information about which module is in charge of registering a repository is only available during repository scanning. The information isn't propagated anywhere and isn't also available later on.

Comment From: snicoll

Thanks @mp911de. I am going to close this now and RepositoryTagsProvider can be used for such scenario.