Micrometer KafkaConsumerMetrics present when running locally but not when deployed - spring-boot

When I run locally I can see that kafka.consumer. are being collected. While when I deploy my service - I see that those metrics are not present.
I use kafka version 1.11.0, java 11 and Spring Boot 2.2.
How I can determine what is missing?

In case anyone has this issue. I've had to explicitly add:
spring.jmx.enabled=true
It is needed since Kafka publishes data to jmx, and Micrometer reads it from there. By default jmx is disabled starting from Spring Boot 2.2.
It worked locally because IDEA added spring.jmx.enabled=true flag under the covers.

Related

Elasticsearch 7.10.2 doesn't bind application.properties variables on Mac M1

I'm facing a weird issue. I have 2 laptops, one running under Windows where everything works fine and on the other side, a Mac Mini M1.
Assuming, I'm developing a basic Spring Boot application with Elasticsearch as Repository.
In the application.yml, as usual I have the following properties :
spring:
elasticsearch:
rest:
uris: https://dummy-cloud-provider.cloud.com:12833
username: myusername
password: mypassword
But everytime I want to start the application on my Mac, I have the following error :
2021-06-23 15:55:51.972 ERROR [reactor-http-nio-3] r.c.p.Operators - Operator called default onErrorDropped
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
Caused by: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider.lambda$lookupActiveHost$3(SingleNodeHostProvider.java:101)
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:102)
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2397)
...
I don't understand why it always skip my application.yml variables and try to reach localhost:9200.
I hope someone can help me :)
Best regards
This is not a Spring Data Elasticsearch problem, but a Spring Boot problem. Spring Data Elasticsearch does not use application properties to set anything up.
Looking at the configuration it seems that you want to set up a imperative (non-reactive) client connection to Elasticsearch?
The stacktrace shows that the failing call is done by the reactive client.
I suspect that you have the reactive Spring libraries (webflux) in the classpath and Spring boot actuator. And Spring Boot then configures a reactive client for the actuator using the default of localhost:9200.
I can't tell for sure without seeing your maven/gradle setup, but this for me is most possible explanation for this error.

Apache ActiveMQ - retrieving JMS metrics

In my corporate project I am using Spring Boot and Apache ActiveMQ 5.x Spring Boot starter. I am a totally beginner in this.
My goal is to expose Prometheus endpoint with some JMS queue metrics:
number of messages in queue
number of messages in error queue
What are dedicated tools for retrieving such metrics? Up to now I have found two possible ways. Can anyone confirm which of these two tools can solve my problem?
https://docs.spring.io/spring-integration/docs/5.1.7.RELEASE/reference/html/#system-management-chapter
https://activemq.apache.org/components/artemis/documentation/latest/metrics.html (here the example is not very helpful)
I don't think the Spring stuff will work because that will provide Spring-related metrics from the application itself, not the ActiveMQ broker.
Also, the documentation for ActiveMQ you cited is for ActiveMQ Artemis. However, the dependency you're using is for ActiveMQ 5.x. Therefore, the documentation is not applicable. However, if you choose to use ActiveMQ Artemis it is very simple to expose a Prometheus endpoint using this Prometheus metrics plugin implementation. It's worth noting that Artemis is ActiveMQ's next generation message broker. If you're starting a new project I would recommend you use it rather than 5.x. Artemis is planned to replace 5.x and become ActiveMQ 6.0 in the future.
I think your best bet would be to configure the Prometheus JMX exporter. It even has a sample configuration for ActiveMQ 5.x.
ActiveMQ comes with Jolokia bundled by default for extracting JMX Beans for the JVM, queues and a bunch of other metrics using HTTP. That way we can easily export using a software like Telegraf, which comes with a simple input plugin for ActiveMQ and a simple output plugin for Prometheus.

Spring boot microservices doesn't work with Intelij IDEA

I am creating a spring boot microservice project with intelij IDEA.
Currently I have developed three seperate spring boot rest services as customer service, vehicle service and spring cloud config server. Spring cloud config server is pointing to a github repository.
The issue is sometimes above projects take more than 10 minutes to run and sometimes does't run and give an error message as "failed to check application readystate intellij attached provider for the vm is not found". I have no idea why this happens ?
There are two possible causes:
1. IntelliJ IDEA and the Spring application are running in different JVMs.
There is a bug for IntelliJ IDEA regarding that:
https://youtrack.jetbrains.com/issue/IDEA-210665
Here is short summary:
IntelliJ IDEA uses local JMX connector for retrieving Spring Boot actuator endpoint's data by default. However, it could be impossible to get local JMX connector address via attach api if Spring Boot application and IntelliJ IDEA are run by different JVMs. In this case, add the following lines to VM options of your Spring Boot run configuration:
-Dcom.sun.management.jmxremote.port={some_port}
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
As mentioned in the official Oracle documentation, this configuration is insecure. Any remote user who knows (or guesses) your port number and host name will be able to monitor and control your Java applications and platform.
2. Prolonged time to retrieve local hostname
You can check that time using inetTester. Normally it should take only several milliseconds to complete. If it takes a long time then you can add the hostname returned by inetTester to /etc/hosts file like this:
127.0.0.1 localhost winsky
::1 localhost winsky

spring boot startup failure if mongo host not reachable

I have Spring boot mongo db app, when i start running this application if mongo host is alive, am able to see the my app is up and running successfully,
if my mongo host is down when i start my application my app failed to start.
is there any way even thought if mongo host is down my application should be up and running.
could someone please help me on this?
am using spring boot mongo properties in my application
spring.data.mongodb.repositories.enabled=true
spring.data.mongodb.port=27017
spring.data.mongodb.database=db
spring.data.mongodb.uri=mongodb://mongo-node-1.ballu/db
have same problem with spring boot kafka also.
Sorry for the previous comment. It was for excluding auto config beans, anyway
Is there any way even though if mongo host is down my application
should be up and running.
Yes,
spring.datasource.continue-on-error=true #Whether to stop if an error occurs while initializing the database.
as per spring doc
By default, Spring Boot enables the fail-fast feature of the Spring
JDBC initializer. This means that, if the scripts cause exceptions,
the application fails to start. You can tune that behavior by setting
spring.datasource.continue-on-error.
and as of spring kafka try this(i'm not sure if this meets your requirement)
spring.kafka.admin.fail-fast=true # Whether to fail fast if the broker is not available on startup.

Spring cloud stream 2.0 and startOffset latest

While upgrading our app to spring boot 2.0.3 , we encoutered an issue with consuming messages and using startOffset: latest.
The scenario that we tested is as follows:
deploy an app with consumer(topic = TEST_CHANNEL,group = kafka2_test) configured with startOffset: latest to pcf and increase the number of instances to 5.
stop the app
publish 40 messages to TEST_CHANNEL topic
start the app
we can see that the app successfully assigns to the partitions ,however, some of the instances does not consume from the partitions that they are assigned to.
We also verified it by checking the lag for the group.
This scenario worked when using spring boot 1.5.10. It also worked when using spring boot 2.0.3 and not setting the startOffset: latest.
Note: this is not a new group , so offset suppose to be present for the consumer to use, and resetOffsets should not have any effect.
Is this an issue in spring boot 2.0.3?
not a new group ... and resetOffsets should not have any effect.
resetOffsets is specifically designed to reset the offset for an existing group to the startOffset value.
It was broken in the 1.3.x version of the binder (the version used by Boot 1.5.x) and had no effect.

Resources