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

Provide metric auto-configuration for spring data repository [DATACMNS-1420] #1853

Closed
spring-projects-issues opened this issue Nov 16, 2018 · 9 comments
Assignees
Labels
in: repository type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 16, 2018

Julien Fougere opened DATACMNS-1420 and commented

With spring boot actuator we get automatically metrics around a whole bunch of things (jvm, cpu, tomcat, file, log, mvc, jersey, webflux, http client, rabbitmq, hibernate, cache, datasource, etc...) but we don't get any metrics related to spring data repositories.

My proposition is to add support for that and also auto-configuration from spring-boot.

What do u think ?

 

Locally I have a working project for jpa repositories that is adding a time gauge with class & method name as tags. However I haven't been able to see how to auto-configure it in a spring-boot way so I created a EnableJpaMetricsRepositories annotation that plug a interceptor (advice) around repositories via the repositoryFactoryBean.


1 votes, 5 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 16, 2018

Andy Wilkinson commented

This was originally raised as a Spring Boot issue

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 16, 2018

Mark Paluch commented

Thanks for raising this issue. When looking at the data side, you can various perspectives and levels of detail. Repositories are a common API to use. If we look what's inside a repository we will recognize there may be multiple things going on in terms of statements and execution models. Repositories use typically a Template API that is store specific and Template API calls translate to one or more data store interactions.

There's fair amount of metric integrations that you can plug in (e.g. on driver level), so the actual questions to answer are:

  • What metrics are you interested in?
  • From what perspective do we want to measure metrics? A repository granularity is different than Template API granularity.

From an integration perspective, it would make the most sense to add another interceptor to RepositoryFactorySupport that adds the observability aspect to all (metrics-enabled) repositories. This approach would only consider repositories but not the underlying data-store-specific Template API

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 17, 2018

Julien Fougere commented

Hi Mark Paluch. Thanks for your comment.

My primarily thoughts were to add execution time metrics at a repository level (so including provided generic methods as well as user defined methods).

For example with the following repository:

@Repository
public interface BrandRepository extends JpaRepository<Brand, Integer> {

    @QueryHints(value = {@QueryHint(name = HINT_COMMENT, value = "86314aab-1287-4118-b5da-296fec744842")}, forCounting = false)
    Optional<Brand> findByName(String name);
} 

We would get execution time for method such as CrudRepository.save as well as BrandRepository.findByName.

 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 19, 2018

Oliver Drotbohm commented

I am not entirely sold that Spring Data is the right place to implement those things. Everything actuator and metrics lives in Boot these days and we would not be able to make use of the integration APIs living there. We currently don't expose anything Spring Data related for any module, except MongoDB driver JMX stats

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 19, 2018

Andy Wilkinson commented

Everything actuator and metrics lives in Boot these days
 
That's not the case:

  • Spring Integration has Micrometer support that Boot just auto-configures
  • HikariCP support Micrometer directly
  • Spring Web Services has a ticket to provide metrics in WebServicesTemplate.

That's just three examples off the top of my head. In each case, supporting Micrometer directly (rather than relying on Boot to do it) makes sense to me as it means that all users of the project can benefit from Micrometer support irrespective of whether Spring Boot is being used. Where I think Boot should come into it is with auto-configuring the Micrometer support that the project provides.

not be able to make use of the integration APIs living there

What APIs are you referring to? I'm struggling to think of any that would make it easier for Spring Data to provide repository-level Micrometer Metrics

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 20, 2018

Julien Fougere commented

Any updates on this improvement ? sprint data or spring boot scope ? 

@timtebeek
Copy link

@timtebeek timtebeek commented Apr 26, 2021

Spring Boot 2.5 picks up Spring Data Repository Metrics: https://docs.spring.io/spring-boot/docs/2.5.x-SNAPSHOT/reference/html/production-ready-features.html#production-ready-metrics-data-repository
That seems to cover this issue as first reported. @jfougere would you agree?

@mp911de
Copy link
Member

@mp911de mp911de commented Apr 26, 2021

Auto-configurations are generally managed by Spring Boot. As noted by @timtebeek, Spring Boot has integrated with Spring Data's repository metrics so closing this ticket here.

@mp911de mp911de closed this as completed Apr 26, 2021
@jfougere
Copy link

@jfougere jfougere commented Apr 26, 2021

yes @timtebeek agreed. Thanks for the news.

I see that the metrics are tagged with repository:

Simple class name of the source Repository.

Let's say I have a CustomerRepository extending a JpaRepository, and I use the save method from CrudRepository on an instance of CustomerRepository, would the metric be tagged with repository=CustomerRepository or repository=CrudRepository ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository type: enhancement
Projects
None yet
Development

No branches or pull requests

5 participants