pause enpoint is not available - spring-cloud

I am using Finchley.SR1 with following cloud dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
I have enabled pause config like this
endpoints:
restart:
enabled: true
pause:
enabled: true
Still no pause and resume endpoint available is actuator like before
{"_links":{"self":{"href":"http://localhost:18182/actuator","templated":false},"archaius":{"href":"http://localhost:18182/actuator/archaius","templated":false},"auditevents":{"href":"http://localhost:18182/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:18182/actuator/beans","templated":false},"health":{"href":"http://localhost:18182/actuator/health","templated":false},"conditions":{"href":"http://localhost:18182/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:18182/actuator/configprops","templated":false},"env-toMatch":{"href":"http://localhost:18182/actuator/env/{toMatch}","templated":true},"env":{"href":"http://localhost:18182/actuator/env","templated":false},"info":{"href":"http://localhost:18182/actuator/info","templated":false},"loggers":{"href":"http://localhost:18182/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:18182/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:18182/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:18182/actuator/threaddump","templated":false},"metrics":{"href":"http://localhost:18182/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:18182/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:18182/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://localhost:18182/actuator/httptrace","templated":false},"mappings":{"href":"http://localhost:18182/actuator/mappings","templated":false},"refresh":{"href":"http://localhost:18182/actuator/refresh","templated":false},"features":{"href":"http://localhost:18182/actuator/features","templated":false},"service-registry":{"href":"http://localhost:18182/actuator/service-registry","templated":false},"bindings-name":{"href":"http://localhost:18182/actuator/bindings/{name}","templated":true},"bindings":{"href":"http://localhost:18182/actuator/bindings","templated":false},"channels":{"href":"http://localhost:18182/actuator/channels","templated":false}}

The endpoint configuration properties have been changed since Spring Boot 2.0.
To enable /actuator/restart, /actuator/pause and /actuator/resume you need to use management.endpoint.restart.enabled=true.
Also don't forget to include these endpoints in management.endpoints.web.exposure.include.

Related

Spring's ConstructorResolver#instantiateUsingFactoryMethod ignoring spring.mongodb.embedded.version for embedded mongodb

I'm trying to run a Spring Boot application with an embedded mongodb (not just for testing, but live). It was working fine until I decided to modernize to use latest available Spring jars, etc. Upgrading to Spring Boot 2.6.1 I now get an 'IllegalStateException: Set the spring.mongodb.embedded.version property or define your own MongodConfig bean to use embedded MongoDB' from EmbeddedMongoAutoConfiguration#determineVersion, where my application.properties entry for 'spring.mongodb.embedded.version=3.6.3' is being reported as null. Tracing back to ConstructorResolver#instantiateUsingFactoryMethod I see it passes in an EmbeddedMongoProperties with null 'version'. That method is way over my head but I believe it is the cause. I suspect it's somehow using the older MongoProperties which does not have version but I'm not sure. I've been debugging for hours and I'm not getting anywhere fast. Any help appreciated.
application.properties:
server.port=8090
spring.mongodb.embedded.version=3.6.3
spring.mongodb.embedded.features=SYNC_DELAY,NO_HTTP_INTERFACE_ARG
spring.datasource.driver-class-name=mongodb.jdbc.MongoDriver
#spring.data.mongodb.uri=mongodb://127.0.0.1:27017
spring.data.mongodb.database=jokes
spring.data.mongodb.host=127.0.0.1
spring.data.mongodb.port=27017
#spring.data.mongodb.username=craig
#spring.data.mongodb.password=***
#spring.data.mongodb.authentication-database=admin
spring.mongodb.embedded.storage.database-dir=/home/craig/.ca.footeware.web-mongodb/
pom.xml dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- exclude junit 4 -->
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-imaging</artifactId>
<version>1.0-alpha2</version>
</dependency>
</dependencies>
Please add below lines to test class.
#DataMongoTest
#ImportAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class)

Spring Cloud Gateway using Keycloak Successful Login, but what's the next step?

I managed to get the keycloak default login:
After successful login, keycloak redirect to uri: {hostname}/oauth2/authorization/keycloak. I'm just not sure where did that come from? Where's the setting in the Keycloak that can change that? I have my redirect uri in keycloak client set to: http://localhost/*. That doesn't do it. Wh
Here're my pom:
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
...
<!-- gateway -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- end of gateway -->
<!-- using CircuitBreaker -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
<!-- end of CircuitBreaker -->
<!-- oauth2 keycloak -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<!-- end of oauth2 keycloak -->
This is my gateway and keycloak settings in application.properties:
#Gateway
spring.cloud.gateway.routes[0].id=person
spring.cloud.gateway.routes[0].uri=http://localhost:8022/
spring.cloud.gateway.routes[0].predicates[0].name=Path
spring.cloud.gateway.routes[0].predicates[0].args[pattern]=/personprocess/**
spring.cloud.gateway.routes[0].filters[0].name=CircuitBreaker
spring.cloud.gateway.routes[0].filters[0].args[name]=myCircuitBreaker
spring.cloud.gateway.routes[0].filters[0].args[fallbackUri]=forward:/myCircuitBreaker/inCaseOfFailureUseThis
spring.cloud.gateway.routes[1].id=keycloak
spring.cloud.gateway.routes[1].uri=http://localhost:8180/
spring.cloud.gateway.routes[1].predicates[0].name=Path
spring.cloud.gateway.routes[1].predicates[0].args[pattern]=/auth/**
spring.cloud.gateway.routes[1].filters[0].name=TokenRelay
spring.cloud.gateway.routes[1].filters[1].name=RemoveRequestHeader
spring.cloud.gateway.routes[1].filters[1].args[name]=Cookie
#Keycloak
spring.security.oauth2.client.registration.keycloak.client-id=gateway-app
spring.security.oauth2.client.registration.keycloak.client-secret=f52b34e1-3cae-4de7-83ae-2d795e3b72d7
spring.security.oauth2.client.registration.keycloak.clientName=gateway-app
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirectUri=http://localhost/personprocess/
spring.security.oauth2.client.provider.keycloak.authorization-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/auth
spring.security.oauth2.client.provider.keycloak.token-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/token
spring.security.oauth2.client.provider.keycloak.user-info-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/userinfo
spring.security.oauth2.client.provider.keycloak.jwk-set-uri=http://localhost:8180/auth/realms/gateway-realm/protocol/openid-connect/certs
spring.security.oauth2.client.provider.keycloak.user-name-attribute=
I have tested the security token using Postman, and it is all valid. What's the next step?
I found out that you can't mix gateway and spring security in a single pom.
The solution is to split the the apps into a gateway and a spring security.

Spring cloud gateway hystrix not working

I am having issues getting hystrix to work with my route. things like re-write paths and load balancing are working but for some reason hystrix never trips. I am setting my timeouts very low and have a delay in a downstream service. Is there anything special you need to do to get hystrix working?
I am using spring-cloud-gateway with eureka and spring-cloud-config. Also, is there a way to debug when a route is not working? Like a log setting to see what is happening?
Here is my route:
spring:
cloud:
gateway:
routes:
# =====================================
- id: main-service
uri: lbl://main-service
predicates:
- Path=/main-service**
filters:
- Hystrix=mainservice
Here is my pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M7</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.M5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>2.0.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is my Application class:
#EnableDiscoveryClient
#EnableHystrix
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
The only other class in the jar is this:
#Configuration
public class GatewayConfiguration {
#Bean
public DiscoveryClientRouteDefinitionLocator
discoveryClientRouteLocator(DiscoveryClient discoveryClient) {
return new DiscoveryClientRouteDefinitionLocator(discoveryClient);
}
}
I figured out the issue. It seems that if you add eureka discovery then it automatically add routes that match all the spring.application.names returned by your eureka server and these have the same order as the ones I defined using application name as the predicate. I was able to fix this by setting the order for my route to -1.
Not sure if there is a better way to do this but at least I know hystrix is working.
Thanks
Maybe you should use this dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

why couldn't the configuration in bootstrap.yml work?

bootstrap.yml & application.yml
zuul.SendResponseFilter.post.disable: true
zuul.SendErrorFilter.post.disable: true
zuul.TraceDebugPreFilter.post.disable: true
zuul.ServletDetectionFilter.pre.disable: true
It couldn't work because com.netflix.zuul.ZuulFilter#isFilterDisabled is false.
But when I set command line like:
-Dzuul.ServletDetectionFilter.pre.disable=true \
-Dzuul.SendResponseFilter.post.disable=true
Then com.netflix.zuul.ZuulFilter#isFilterDisabled is true.
what's the matter? how can I make the bootstrap.yml configuration work?
Dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>

SpringCloud Eureka - simple client doesnt register

I have an Eureka Server where I want to register a very basic SpringBoot service. Unfortunately the service doesnt register although I tried to follow all the articles I could find.
Moreover when I check description of the DiscoveryClient (that gets autowired), I see "Spring Cloud No-op DiscoveryClient" which suggests (as per NoopDiscoveryClient.java source) that Eureka client library isnt found.
In pom I have
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
which if I am right should make sure that proper netflix libraries are in place. #EnableEurekaClient annotation is present. No errors on the console when starting the client, nothing interesting in the Eureka Server console logs.
This is the configuration from the application.yml:
eureka:
client:
serviceUrl:
defaultZone: ${vcap.services.eureka-service.credentials.uri:http://127.0.0.1:8761}/eureka/
Any suggestions are really welcomed as I am running out of ideas :)
http://start.spring.io is your friend. You need to use the starters.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.M5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Except #spencergibb's answer, in my case it also require <spring-cloud.version> inside the <properties>:
<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>Greenwich.M3</spring-cloud.version>
</properties>