Query timings in prometheus with datasource-micrometer - spring-boot

I'm trying to publish query timing to prometheus with datasource-micrometer.
I've configured spring boot started as defined in docs
I see the trace and timings of queries in logs
2023-01-09T10:09:29.929Z INFO [user-service,63bbe7d9a54810ffb94948d2a5724064,e35aae4db80e8647] 98235 --- [ntContainer#1-4] n.t.d.l.l.SLF4JQueryLoggingListener :
Name:mysql, Connection:185, Time:1, Success:True
Type:Prepared, Batch:False, QuerySize:1, BatchSize:0
Query:["select * from user where name=?;"]
Params:[(admin)]
And I can see generic metrics in prometheus
jdbc_query_seconds_max{error="none",} 113.698347232
How can I see metrics per query?
What I want is
jdbc_query_seconds_max{error="none",query="select * from user where name=?;"} 113.698347232
jdbc_query_seconds_max{error="none",query="select * from user where id=?;"} 113.698347232
Update:
I'm using spring-boot autoconfiguration so there is nothing else other than maven dependency.
<dependency>
<groupId>net.ttddyy.observation</groupId>
<artifactId>datasource-micrometer-spring-boot</artifactId>
<version>1.0.1</version>
</dependency>

Related

Unable to connect non stop SQL from Spring boot applivcation

My project uses non stop SQL/MX as RDBMS database, a product from HP.I am not able to connect to the data source using Spring Boot's standard practice of defining JDBC URL, user, password inside application.properties file.
spring.datasource.driverClassName = com.tandem.sqlmx.SQLMXDriver
spring.datasource.url = jdbc:sqlmx:
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SqlmxDialect
spring.datasource.hikari.connection-test-query=SELECT 1 FROM $USER1.TLFM3SQL.IF09CSTB
This is the error:
com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for
connections. (com.tandem.sqlmx.SQLMXConnection.getNetworkTimeout()I)
JdbcEnvironmentInitiator: could not obtain connection to query metadata: Unable to resolve name
[org.hibernate.dialect.SqlmxDialect ] as strategy [org.hibernate.dialect.Dialect]
I had not included SQLMX hibernate jar in project.
It worked after I included that jar in my pom.

Problem with Google Cloud Pub/Sub API and Spring boot application

I write spring boot application for subscribing Google cloud Pub/Sub topic for this I use Google's tutorial, but when I run application I have get this error
2019-02-02 18:03:10.248 INFO 15080 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-02-02 18:03:10.271 INFO 15080 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-02 18:03:10.610 ERROR 15080 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method messageChannelAdapter in tech.garoon.cloud.CloudApplication required a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' in your configuration.
Process finished with exit code 1
How Can I solve this problem?
GcpPubSubAutoConfiguration provides autoconfiguration feature of creating necessary beans including PubSubTemplate. In your case, somethng is missed, Kindly ensure that dependencies are in place or recreate following bean to make it work.
#Bean
public PubSubTemplate pubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate,
PubSubSubscriberTemplate pubSubSubscriberTemplate) {
return new PubSubTemplate(pubSubPublisherTemplate, pubSubSubscriberTemplate);
}
Additionally, make sure GcpContextAutoConfiguration is created based on below properties in application.properties.
spring.cloud.gcp.credentials.location=${gcp_credentials}
starter dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>
Solution
I added this dependency
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
My dependencies
dependencies {
implementation 'org.springframework.cloud:spring-cloud-gcp-pubsub:1.1.0.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE"
implementation 'org.springframework.integration:spring-integration-core:5.1.2.RELEASE'
}
if using external configuration class that is registering your channels, message handlers etc, make sure to annotate the configuration class with #Import({GcpPubSubAutoConfiguration.class})
#Configuration
#Import({GcpPubSubAutoConfiguration.class})
public class PubSubConfig{
}
I ran into this issue with these versions of spring-boot and spring-cloud-gcp-starter-pub:
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
and in my application.properties I had
spring.cloud.gcp.pubsub.enabled=false for local development.
I removed spring.cloud.gcp.pubsub.enabled=false and it worked. Although now it creates a connection to the pubsub gcp topic, so for local development, you will need to comment out publishing, to avoid sending messages.

OpenTracing not activating for Sleuth-Zipkin in Spring Boot App

Spring Doc says
Spring Cloud Sleuth is compatible with OpenTracing. If you have OpenTracing on the classpath, we automatically register the OpenTracing Tracer bean. If you wish to disable this, set spring.sleuth.opentracing.enabled to false
I have the below dependency in my POM.
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-starter</artifactId>
<version>${version.opentracing.spring}</version>
</dependency>
But, I get the following print out it the logs when I try to print the trace and span information : tracer: NoopTracer
2018-11-19 12:12:03.938 [{X-B3-SpanId=4cd8eed6fe759bd1, X-B3-TraceId=5bf25b3bd0714ae54cd8eed6fe759bd1, X-Span-Export=true, spanExportable=true, spanId=4cd8eed6fe759bd1, traceId=5bf25b3bd0714ae54cd8eed6fe759bd1}] DEBUG ahallim-1ef960 --- [nio-7070-exec-1] a.h.w.RestaurantController : tracer: NoopTracer
2018-11-19 12:12:03.939 [{X-B3-SpanId=4cd8eed6fe759bd1, X-B3-TraceId=5bf25b3bd0714ae54cd8eed6fe759bd1, X-Span-Export=true, spanExportable=true, spanId=4cd8eed6fe759bd1, traceId=5bf25b3bd0714ae54cd8eed6fe759bd1}] INFO ahallim-1ef960 --- [nio-7070-exec-1] a.h.w.RestaurantController : active span: null
Why am I getting a NopTracer? Why isn't Brave being registered automatically as promised? Am I doing something wrong?
I am using
Finchley.SR2
I was using Finchley.SR2 train of releases. Once I upgraded to the latest Spring Boot and Spring Cloud versions, the issue fixed itself.
I removed the opentracing-spring-cloud-starter dependency and am now just using
<dependency>
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
</dependency>

Camel Upgrade 2.22 breaks Apache CXF endpoints

I have upgraded Camel 2.22. along with CXF version 3.2.5,Spring boot 2.04.RELEASE
When I start my application I can't see any errors but the can't access endpoints anymore
below is the code:
1) Camel route:
<cxf:cxfEndpoint id="porEndpoint" address="/por/" serviceClass="x.y.z.service.PorService" publishedEndpointUrl="">
<cxf:binding>
<soap:soapBinding version="1.2"/>
</cxf:binding>
</cxf:cxfEndpoint>
2) Properties:
cxf.path=/services
server.servlet.context-path=/fuse-test
3)This URL worked fine earlier :http://localhost:8080/fuse-test/services/por?wsdl
I have enabled trace at context level and log mode as debug but I can't find any errors apart from :
o.s.s.ldap.SpringSecurityLdapTemplate : Ignoring PartialResultException
camel-cxf(v 3.2.5) somehow doesn't include the cxf spring boot. After adding the below dependency the endpoint is available
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.6</version>
</dependency>

Empty list of Keys refreshed [] on Spring Cloud Config Server (Spring Boot application)

In my Spring Cloud config server pom.xml I have
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M8</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
In bootstrap.properties I have specified with spring.cloud.config.server.git.uri the repository to fetch configuration properties from (as yml files). I have set up a Github webhook and have ngrok forwarding POST requests to port 8888 that the config server is listening on. When I commit a change to a yml configuration file, everything seems to go as expected:
In ngrok console window there is a POST request to /monitor and response with 200.
The delivery is marked successful on Github's webhook management page.
The following log entries are created in config server's console window.
2018-03-14 13:55:03.023 INFO 17004 --- [nio-8888-exec-3] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: develop_localhost
2018-03-14 13:55:04.451 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2018-03-14 13:55:04.483 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1: startup date [Wed Mar 14 13:55:04 EET 2018]; root of context hierarchy
2018-03-14 13:55:04.521 INFO 17004 --- [nio-8888-exec-3] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$5a4e4f18] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-14 13:55:06.027 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2018-03-14 13:55:06.041 INFO 17004 --- [nio-8888-exec-3] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-03-14 13:55:06.043 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#429eafc3: startup date [Wed Mar 14 13:55:06 EET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1
2018-03-14 13:55:06.053 INFO 17004 --- [nio-8888-exec-3] o.s.boot.SpringApplication : Started application in 3.024 seconds (JVM running for 97.323)
2018-03-14 13:55:06.054 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#429eafc3: startup date [Wed Mar 14 13:55:06 EET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1
2018-03-14 13:55:06.055 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1: startup date [Wed Mar 14 13:55:04 EET 2018]; root of context hierarchy
2018-03-14 13:55:06.128 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
Why is the list of keys refreshed empty? When I check the local property source yml file, the change committed on Github and POSTed to the monitor endpoint is not reflected there either. I am running RabbitMQ on another server in my local network, and I can see on its web management console the connection from the config server and the channel created for it. Yet there are no messages on the overview tab.
This used to work with Spring Boot 1.5.4.RELEASE and Spring Cloud Dalston.SR5 on the occasions when the embedded Tomcat/Jetty managed to start. The main reason to try version upgrades was that the servlet container actually started only like in 10% percent of the launches. Now with Spring Boot 2.0.0.RELEASE and Spring Cloud Finchley.M8, Tomcat always starts but the configuration changes do not seem to propagate to the config server and definitely not to RabbitMQ.
Any ideas?
Edit June 5th, 2018.
Now that I have updated spring-boot-starter-parent to 2.0.2.RELEASE in the config server pom.xml, config client gets its configuration from it. But as before, no push notification is propagated to RabbitMQ. Both the config server and client have their respective connections, channels and queues with RabbitMQ.
Now if I change spring-cloud.version to Finchley.BUILD-SNAPSHOT or Finchley.RC2 (and keep Spring Boot 2.0.2.RELEASE or change it to 2.0.1.RELEASE, no difference), I can see a queued message from the config server on the RabbitMQ web management console when it receives a push notification. Fine. The downside of the combination is that when config client tries to fetch its settings from the server, the server logs the exception below
2018-06-04 16:16:12.352 ERROR 10428 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot load environment] with root cause
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source) ~[na:1.8.0_144]
at org.springframework.cloud.config.server.environment.HttpClientConfigurableHttpConnectionFactory.lookupHttpClientBuilder(HttpClientConfigurableHttpConnectionFactory.java:69) ~[spring-cloud-config-server-2.0.0.BUILD-SNAPSHOT.jar!/:2.0.0.BUILD-SNAPSHOT]
and because the client does not get its configuration, it fails to boot.
What would be the working combination of Spring Boot and Cloud versions to have both full RabbitMQ integration (with messages propagated to RabbitMQ) and successful config server and client interaction? Like I mentioned earlier, this used to work with Spring Boot 1.5.4.RELEASE and Spring Cloud Dalston.SR5, but downgrading to them is not an option.

Resources