Hystrix Dashboard with Spring Boot Deployed On PCF not showing Metrics - spring

I created a simple app using Spring boot and the spring cloud starter hystrix library.
In my build.gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-hystrix-dashboard:1.0.0.RC2")
compile("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RC2")
}
I deployed one app as a hystrix dashboard using the above libraries and #EnableHystrixDashboard
I then deployed another app which was annotated with #EnableHystrix
I added a component that has a command that I invoke through a controller, just to test things out:
#HystrixCommand(fallbackMethod = "onFailedToSayHello")
public String sayHello(Map<String, String> parameters) {
if (parameters.get("fail") != null && parameters.get("fail").equals("yes")) {
throw new RuntimeException("I failed because you told me to");
}
return "Hello";
}
private String onFailedToSayHello(Map<String, String> parameters) {
return "Bye";
}
The hystrix app runs fine. When I hit the URL I see the stream, the ouptut of which I put in a gist here.
I just see that repeating over and over.
My dashboard is up and running and when I enter the URL of my running hystrix sample app I get a loading screen:
Then, when I check my hystrix app again I see this:
λ curl http://myappurl/hystrix.stream
{"timestamp":1423748238280,"status":503,"error":"Service Unavailable","message":"MaxConcurrentConnections reached: 5","path":"/hystrix.stream"}
I am not sure where to go from here. I tried deploying the hystrix dashboard war instead of building it myself which I downloaded from here but got the same result.
I also noticed some JavaScript error outputs in the browser console which I put here in case they are any use.
And in the server logs I see this repeated over and over:
2015-02-15 20:03:55.324 INFO 9360 --- [nio-8080-exec-9]
ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://myappurl/hystrix.stream
I am now going to try and get turbine running and see if using that somehow magically fixes things. Thought I would post here too though on the off chance someone can spot an error on my part based on what I've done so far.
EDIT:
An important point I didn't mention is that I have both the app and the dashboard deployed on PCF. This seems to be important since this issue doesn't happen when I deploy locally. Still no idea what's causing it though.

Problem goes away if you build hystrix-dashboard from the latest source, or use the most recently released war (version 1.4.3 on 27th March at time of writing).

Several things can probably lead to MaxConcurrentConnections, and one of them is no any metrics data generated by the application. The servlets (Hystrix.stream servlets) will keep looping to wait data, then it will consumes all the connections. There are very good discussion on the Hystrix github wiki. For example:
hystrix.stream holds connection open if no metrics #85

Related

EmbeddedKafka Spring boot test fails only on Github actions but not locally

I am creating a demo application for Groovy using Spring boot with Kafka and elastic.
I used #EmbeddedKafka annotation in my Spock tests and they are working really nice locally; both on Windows and Ubuntu. They work from within Intellij by just running or debuggin, no issue. It's the same when trying in my shell "./gradlew test". Everything is good.
As soon as I pushed it to github.com, my github action fails. But it's calling the same command.
the action definition: https://github.com/besessener/GroovySpringBootKafkaElasticsearchDemo/blob/main/.github/workflows/test.yml
remote failing test case:
https://github.com/besessener/GroovySpringBootKafkaElasticsearchDemo/blob/main/src/test/groovy/me/spring/GroovyDemo/stream/KafkaSendAndReceiveTest.groovy
action: https://github.com/besessener/GroovySpringBootKafkaElasticsearchDemo/runs/3019862203?check_suite_focus=true
The only thing that looks like an error to me from the actions output, is this:
2021-07-08 14:05:35.896 WARN 2693 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-UserGroup-1, groupId=UserGroup] Error while fetching metadata with correlation id 4 : {topic-user=LEADER_NOT_AVAILABLE}
I read many things about not using static ports for the kafka tests. but this is my only kafka test, so I don't really understand how there should be a conflict. Furthermore LEADER_NOT_AVAILABLE could be a problem with a non-existing topic or maybe the consumer is simply not able to properly conenct to the broker. But I don't see any of this.
I still have the feeling it is more related to "localhost:9092" as brokerProperties. Is there an issue in regards to that when using Github actions? Or anything else I am missing?

springdoc-openapi generate openapi yaml on build without server

I have a Spring boot Gradle project and I want to get it's OpenAPI spec YAML file.
As I understand the official swagger-core does not support Spring boot projects, thus I found springdoc-openapi (https://github.com/springdoc/springdoc-openapi-gradle-plugin).
It seems that in order to get the YAML/JSON files, when running the generateOpenApiDocs task, the springdoc library sets up a server with some endpoints (/v3/api-docs) to download the files.
I'm using the default configuration, and for some reason I keep getting the following error:
Execution failed for task 'generateOpenApiDocs'.
Unable to connect to http://localhost:8080/v3/api-docs waited for 30 seconds
It seems that for some reason it does not set up the server. How can I fix it?
Is it possible to skip the server part? Can I configure springdoc to simply generate files on build?
If you are deploying REST APIs with spring-boot, you are relying on a servlet container.
The necessry metadata for the OpenAPI spec are only available by spring framework on runtime, which explains the choice of generation at runtime.
You can define any embeded servlet container, during your integration tests to generate the OpenAPI Spec.
This is how I resolved the issue
Specify the path
In your properties file enter:
springdoc:
api-docs:
path: /{your path}
Configure the plugin
In your build.gradle file enter:
openApi {
apiDocsUrl.set("http://localhost:{your port}/your path)
}
This happens because sometimes embedded server took sometime to start and it has 30 sec default setting. Please add the below properties in your openAPI block and it will work fine for you. Please see the below sample:
openApi {
apiDocsUrl.set("http://localhost:9090/v3/api-docs.yaml")
outputDir.set(file("Your Directory path"))
outputFileName.set("openapi.yaml")
forkProperties.set("-Dserver.port=9090")
waitTimeInSeconds.set(60)
}
You need to add the dependency below, an updated version may exist depending on when you're seeing this - intellij would tell you and help upgrade:
implementation('org.springdoc:springdoc-openapi-ui:1.6.11')
Then add the line below to your application.properties file:
springdoc.api-docs.path=/api-docs
Perhaps also get rid of the plugin, it's not necessary as long as you have the above dependency. I got rid of mine and things work fine.
After the dependency is resolved, run the app normally with intellij run buttons or the commandline.
With the app running, visit http://localhost:8080/swagger-ui/index.html - assuming your app is running on port 8080. If not, use the right port accordingly.
Also, you can check out https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/10 and https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/10#issuecomment-594010078 - those were helpful when I faced the same issue, showed me part of what to do.

A new project using Spring Initializr does not run in browser

Building a new project downloaded using https://start.spring.io/ does not run on browser.
I have seen some solutions on stackoverflow which require to make some changes or add, but default/out-of-the-box application does not run.
I asked this in Github https://github.com/spring-projects/spring-boot/issues/20603 but was told that i need to add request mappings or something else. There's no default mapping for the root. That's indeed the default error page showing you a 404.
Is there a documentation to "add request mappings or something else" ? It will help if the application run showing some text instead of an error message. This maybe a simple obvious thing for Spring developers but for learners, takes a lot of effort.
http://localhost:8080/
STEPS TO REPRODUCE:
Download new project at https://start.spring.io/
mvn clean package
mvn spring-boot:run
That is the expected behavior right after creating a fresh Spring Boot project. The initializer does not register any endpoint for you, it just gives you the project skeleton you can start working with.
If you want to see something on localhost:8080/ consider adding the following Java class to your project:
#RestController
public class HelloWorldController {
#GetMapping
public String helloWorld() {
return "Hello World!";
}
}
If you are new to Spring/Spring Boot, I can recommend the following resources:
Official Spring Web documentation
Spring Boot Guides
Developing a CRUD API with Spring Boot YouTube course

Spring Boot Sleuth not sending traces to Zipkin

I'm trying to integrate sleuth into a Spring Boot application so that it will talk to a zipkin server for tracing, but I'm not having much luck.
I've followed a few tutorials (link to tutorial) and have no problems getting them to talk to zipkin, but it's not translating well to my application, and I'm not sure where to look.
essentially, in the build.gradle file, to the dependencies section, I added:
compile('org.springframework.cloud:spring-cloud-starter-sleuth')
compile("org.springframework.cloud:spring-cloud-sleuth-zipkin")
In the controller, I added these two beans:
#Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
#Bean
public AlwaysSampler defaultSampler() {
return new AlwaysSampler();
}
and, I added these to the application.properties file:
spring.application.name=pie2-lcp-endpoints
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
When I do all that in the demos, they send traces to my Zipkin host at localhost:4911 just fine (For the time being, I'm just running the quickstart jar file).
When I do all that in my application, I see that I have sleuth log entries with strings like:
[pie2-partner-integration,768070516213fc75,768070516213fc75,true]
so, I know that Sleuth is working.
When I run a demo app with the zipkin server application shut off, the application looks like it's working fine, but, reasonably enough, the log files show a big old ConnectionRefused stack trace.
When I try the same experiment with my application, I see no stack trace in my application logs, and the application also ran just fine.
Outside of my larger application, I can't reproduce my problem, and I don't know what else to share with you. Anyone have any suggestions about where to start?
*sigh, so it turns out, that someone had turned off zipking tracing in a properties file, for no good reason.
*sigh

Spring YARN: How to create a Tracking UI and correctly wire a proxy to it?

I want to deploy an application with a web interface. I want to use Spring YARN for this because that eases all the basic setup, and I can start the application with java -jar.
What steps do I have to do to:
have my application expose a web interface
have the tracking URI I get when submitting it proxy to that web interface
Unfortunately, I cannot find anything about this on the net, there is npthing on that particular issue in the Spring documentation and Google searches do not get me the correct results either.
Easiest way to do this is simply use Spring YARN Boot application model and framework is then trying to do the heavy lifting on your behalf. I actually showed a demo of this during my session at SpringOne 2GX 2014. You can find my session recording from youtube https://www.youtube.com/watch?v=qlvX7_r9aUA.
Interesting stuff for this particular feature is at the end (starting from 1:16:22) and you can see how web server address is registered into YARN resource manager and how I query it using a Spring YARN Boot CLI (around 1:32:13). Spring YARN will actually see that there is an embedded servlet context and registers it automatically. In this demo property "server.port=0" makes tomcat to choose random port which is then registered.
Code for this particular UI demo can be found from github https://github.com/SpringOne2GX-2014/JanneValkealahti-SpringYarn/tree/master/gs-yarn-rabbit. Demo was around RabbitMQ just to have some real UI functionality and not just a dummy hello world page.
There's also more up-to-date sample in https://github.com/spring-projects/spring-hadoop-samples/tree/master/boot/yarn-store-groups which doesn't have a real UI(just Boot management endpoints). Thought it's relatively easy to add Spring MVC magic there just by following normal Boot functionality(i.e. following https://spring.io/guides/gs/rest-service).
Lemmy know if this helps!

Resources