spring-projects / spring-data-elasticsearch

Provide support to increase developer productivity in Java when using Elasticsearch. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-elasticsearch/
Apache License 2.0
2.9k stars 1.33k forks source link

Add Micrometer integration #2445

Open patpatpat123 opened 1 year ago

patpatpat123 commented 1 year ago

Hello Spring Data Elasticsearch team,

Wanted to start a small issue regarding a SpringBoot app, which has micrometer + actuator + Spring Data Elasticsearch please.

This issue is based on the very recent talk at SpringOne regarding Spring Data: https://springone.io/sessions/modern-persistence-with-spring-data-3 (very cool talk btw)

As you can see at 21:00 (please see screenshot), it is mentioned the Spring Data projects which are integrated with observability. Unfortunately, Elasticsearch is not present.

Screenshot_20230206_055330

In order to confirm that, we have a SpringBoot app which is storing / retrieving data from Cassandra, and indeed, in our Zipkin, we could see the database interactions.

However, a similar app, where the data source is Elasticsearch, we are able to see the traces, but traces are without the interaction with Elasticsearch.

May I ask how to enable the traces with Elasticsearch please?

Thank you

sothawo commented 1 year ago

There currently is no support implemented in Spring Data Elasticsearch for that.

patpatpat123 commented 1 year ago

Thank you @sothawo for the clear explanation.

May I ask if it is possible to take this as enhancement, improvement request please?

davidmelia commented 1 year ago

@sothawo I'm also interested in this and can see the other Spring Data projects have support for this:

even a section in the spring data elastic reference on how we can override the auto configuration would be beneficial.

Thanks

sothawo commented 1 year ago

As I wrote, there is no support currently in Spring Data Elasticsearch in regards to this observability topic.

In contrast to Spring Data Mongodb a Spring Data Elasticsearch is a community driven project, there is no dedicated team anywhere working on it. So this issue will be open until either a contribution from the community adds support for observability or I find time to add this. But I am doing this work in my spare time, so I can't tell when I will find to address this issue.

patpatpat123 commented 1 year ago

Just wanted to take the time to say thanks to @sothawo. I am a heavy user a spring data reactive elasticsearch and this repo makes things much easier.

I do not have the level of a contributor, but if you believe you can leave some pointers here, happy to try to come up with a PR. Regardless, looking forward to seeing this!

davidmelia commented 1 year ago

Hi, as an FYI this is the solution I found to add observation to Spring Data Elastic Reactive

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.httpcomponents.MicrometerHttpClientInterceptor;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.boot.autoconfigure.elasticsearch.RestClientBuilderCustomizer;
import org.springframework.context.annotation.Bean;

  @Bean
  RestClientBuilderCustomizer elasticSearchMetricsrestClientBuilderCustomizer(MeterRegistry registry) {

    return new RestClientBuilderCustomizer() {

    @Override
    public void customize(HttpAsyncClientBuilder builder) {
        MicrometerHttpClientInterceptor interceptor = new MicrometerHttpClientInterceptor(registry,
                  request -> request.getRequestLine().getUri(),
                  Tags.empty(),
                 true);
      builder.addInterceptorFirst(interceptor.getRequestInterceptor());
      builder.addInterceptorLast(interceptor.getResponseInterceptor());
    }

    @Override
    public void customize(RestClientBuilder builder) {
      // TODO Auto-generated method stub

    }
  };
  }
sothawo commented 1 year ago

import org.springframework.boot.autoconfigure.elasticsearch.RestClientBuilderCustomizer;

Adding this to Spring Data Elasticsearch would add a dependency on Spring Boot, which we cannnot do (it would create a circular dependency).

patpatpat123 commented 1 year ago

Is this possible to break the circular dependency with some other mechanism? (reflection, etc...)

Metrics and traces are quite baseline features for any production workload and having those in this project would be a great plus

piotrooo commented 2 months ago

That's a HUGE functionality gap since Elasticsearch in Spring Data is widely used. And that's one of the deal breakers for using the OpenTelemetry JavaAagent instead of Micrometer.

cc: @marcingrzejszczak

sothawo commented 2 months ago

As I already wrote:

Spring Data Elasticsearch is a community driven project, there is no dedicated team anywhere working on it. So this issue will be open until either a contribution from the community adds support for observability or I find time to add this. But I am doing this work in my spare time, so I can't tell when I will find to address this issue.

I have a day time job, a family and some other hobbies and interests beside this project. Contributions are always welcome.