Is It Wrong to Pick Up Girls at the Public Cafeteria Near the Office?
"It's always fix this, fix that, deploy this, deploy that. They give me trash documentation and expect me to understand? Do they think I'm psychic or something?"
You listen to Alex complain about things you don't understand while walking together. It is lunchtime, and Alex has invited you to check out the public cafeteria he often frequents. You have never been there and so decide to take him up on his offer.
The Office does have a store and a small cafeteria, but you rarely see anyone you know eat there. You often see Emory eating lunch at their desk, eyes glued on their monitor. It seems that your team does not particularly enjoy the food there.
The two of you arrive at the Shopping District where the Cafeteria is located. It is pretty packed at this hour, but the variety is overwhelming. You and Alex check out the vendors available.
"You're still pretty new here so you might not understand my pain, but working with development ready code made by someone else, especially if they don't know how to make proper documentation, is a pain in the--"
"Alex? Is that you?"
A girl calls out to him. You notice Alex turn red and attempt to hide his face. The girl in front of you appears to be oblivious to it, though.
"A friend of yours?" You inquire. Alex seems unsure of how to answer.
"Ah. Nice to meet you. My name is Maya."
"Err, she works at our Front End department. It's natural that you haven't met her yet since you haven't worked on projects with our other teams." Alex tells you. That's true, you haven't really gotten to know anyone aside from your team. Does everyone like eating here?
"Do you want to eat together?" Maya asks Alex.
You can hear Alex scream internally. He nods at the proposal. Way to go, Alex. He glances at you. You exchange between looking at Alex and Maya. The girl invites you too.
After quick consideration, you decide to leave them alone and get some take-out to eat at the Office instead.
Keeping a High Profile
Alex and Maya order some noodles from a vendor and find a place to sit. Alex isn't sure on what to talk about, but Maya starts a topic about the new programmer and eases the conversation in.
"So they joined not too long ago, huh? No wonder I didn't recognize them."
"Yeah. They're doing pretty good. Thanks to my tutoring of course."
The girl chuckles. The truth is Alex is probably the least involved member in their endeavors thus far.
"So, um, earlier, were you complaining about our current project?"
"WHA!? You heard that?"
"You were making quite the fuss, and I just happened to overhear a little bit. Sorry..." "Ah, no, that's fine. Well, you're not wrong."
Alex and Maya are currently working on the same application, albeit from different perspectives. It is a simple grammar application, and is currently able to use an API to retrieve the synonyms and antonyms of a word. There are currently no major problems in the application, but Alex's next task is to prepare profiling tools to check the metrics of said application.
"Why do we even need to profile this application? There's only like what, two separate functionalities that probably don't even take that long to run."
"But I'm pretty sure in the last daily check-in, this was going to be a test setup before we begin profiling the more complicated functions, was it not?" Maya explains.
"Oh, was it?" Alex had not paid attention during that meeting.
"So how do you set-up the environment for profiling, anyway?" Maya asks with genuine intrigue. Alex finds it a chance to show off his knowledge to the girl.
"You know how we're using SpringBoot for the backend, right? SpringBoot has a built in metrics system that we can access
with the actuator endpoint, and all we need to do is add a single dependency to the build.gradle
." Alex runs his mouth.
The dependency Alex mentions is implementation 'org.springframework.boot:spring-boot-starter-actuator'
and this must
be added to the build.gradle
for you to run the /actuator
endpoint.
"Uh-huh. Add some dependency in the build dot griggle, got it."
"Gradle. Anyway, we're going to be using something called Prometheus."
"Prometheus like the Greek god Prometheus? The one who stole fire and gave it to the humans?"
"Yes but this Prometheus steals metrics from our application and gives it to us" Alex jokes. "It is an open-source system for monitoring."
Alex explains that anyone can just download Prometheus and instantly run it
on localhost:9090
. But for it to actually read the metrics from the application, there are several steps to do first:
- Add the
'io.micrometer:micrometer-registry-prometheus'
dependency to thebuild.gradle
- Expose metric endpoints by adding
management.endpoints.web.exposure.include=*
in theapplication.properties
file
These two steps should allow you to see Prometheus metrics in /actuator/prometheus
endpoint. But for the Prometheus to
listen in to the Spring Boot project's metrics itself, one more step is necessary:
- Edit the
prometheus.yml
file available in the downloaded Prometheus folder so that it listens to your Spring Boot project's metrics endpoint. (For this practice, deployment is not necessary. Reading metrics locally is enough.)
"Once that's set up, you just access the metrics through Prometheus!"
"With queries and stuff?"
"Yup. Spring MVC comes with several default metrics. Say we call the synonym function a couple of times. We can try
querying the http_server_requests_count
metric to see how many times it was called, among other queries."
"We can also use Grafana to display our metrics. There's this really nice dashboard template called JVM Micrometer dashboard, and we can use it to display metrics with our Prometheus source."
Alex goes on a tangent
about Grafana and how it can
be used to display metrics, using many available preset dashboards to monitor infrastructure and architecture of
applications. It generally runs on localhost:3000
, and you'll need to set it up so that it will listen to your
Prometheus data source in localhost:9090
.
Once you have logged in and set up your data source, you can make a panel and try querying the same Prometheus queries as before.
You can also create or import a dashboard for monitoring. Try importing the JVM Micrometer Dashboard and understand the data it displays.
Alex wraps up his explanation and Maya lightly claps her hands.
"Well? How was that?"
"Very informative. You really like talking about technical stuff, don't you?"
"Ah well... It's really all I can talk about. Pretty lame, huh."
"I think it's pretty cool."
Alex's heart skips a beat. Is that just an off-hand remark, or does it have any meaning behind it? Alex can't help but wonder. He looks at Maya with an expression of disbelief, to whom she responds with an innocent grin.
"Your food's getting cold."
They finish their lunch and return to the office without much small talk. Alex had offered to pay for his coworker but was quickly shot down as she insisted the company was more than enough. Either way for Alex, today was a win in his book. He may need to work on a way to impress people that does not involve technical lectures, though.
Tasks
- Succesfully open the
/actuator
endpoint - Install Prometheus, run it locally at
localhost:9090
- Configure your project to display Prometheus endpoint at
/actuator/prometheus
- Configure your local Prometheus to listen in on your Spring Boot project
- Try to query some default metrics from Prometheus and display it using Graph in Prometheus. (Minimum:
count
,max
,sum
) - Set up Grafana in your localhost, and display your Prometheus data on it (using custom panel and JVM Micrometer Dashboard)
- Write the answer in the README file, and answer the following questions:
- What does software profiling mean and why do we do it?
- What is Prometheus? What is Grafana?
- How do you set up Grafana to display your Prometheus data on it?
- According to your findings based on the profiling process, what will you say about the application at current state?
- How do you interpret the findings? Answer this along with a screenshot of a graph query result from your Grafana/Prometheus dashboard.
- What new things did you learn from this tutorial?
Created: 2022-03-08 21:38:57