Skip to content

Commit 5f635f6

Browse files
committed
Beginning of rewrite Petclinic
1 parent a126f29 commit 5f635f6

File tree

6 files changed

+207
-133
lines changed

6 files changed

+207
-133
lines changed

content/en/other/wip/pet-clinic/2-zero-configuration.md renamed to content/en/other/wip/pet-clinic/10-preparation.md

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
---
2-
title: Zero Configuration Auto Instrumentation for Java
3-
linkTitle: 2. Zero Configuration
4-
weight: 2
2+
title: Preparation of the Pet Clinic application.
3+
linkTitle: 1. Preparation
4+
weight: 10
55
---
66

7-
## 1. Spring PetClinic Application
7+
## 1. Spring PetClinic Application build
88

9-
The first thing we need to set up APM is... well, an application. For this exercise, we will use the Spring PetClinic Microservices Application. This is a very popular sample Java application built with Spring framework (Springboot), using a Microservices Architecture.
9+
The first thing we need to set up is... well, an application. For this exercise, we will use the Spring PetClinic application. This is a very popular sample Java application built with the Spring framework (Springboot). We are using the Micro services version of it.
1010

11-
First, clone the PetClinic GitHub repository, and then we will compile, build, package and test the application:
11+
First, clone the PetClinic GitHub repository, and then we will compile, build, package and containerize the application:
1212

1313
```bash
1414
git clone https://github.com/hagen-p/spring-petclinic-microservices.git
1515
```
1616

17-
<!--```bash
18-
git clone https://github.com/spring-projects/spring-petclinic
19-
```-->
20-
21-
Change into the `spring-petclinic` directory <!--(and checkout a specific commit): -->
17+
Change into the `spring-petclinic` directory (and checkout a specific commit):
2218

2319
```bash
24-
cd spring-petclinic
20+
cd spring-petclinic-microservices
2521
```
26-
22+
<!--
2723
Start a MySQL database for PetClinic to use:
2824
2925
```bash
@@ -33,20 +29,76 @@ docker run -d -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_
3329
Next, we will start a Docker container running Locust that will generate some simple traffic to the PetClinic application. Locust is a simple load-testing tool that can be used to generate traffic to a web application.
3430
3531
```bash
36-
docker run --network="host" -d -p 8090:8090 -v /home/ubuntu/workshop/petclinic:/mnt/locust docker.io/locustio/locust -f /mnt/locust/locustfile.py --headless -u 1 -r 1 -H http://127.0.0.1:8083
32+
docker run --network="host" -d -p 8090:8090 -v ~/workshop/petclinic:/mnt/locust docker.io/locustio/locust -f /mnt/locust/locustfile.py --headless -u 1 -r 1 -H http://127.0.0.1:8083
3733
```
38-
39-
Next, run the `maven` command to compile/build/package PetClinic:
34+
-->
35+
Next, run the script that will use the `maven` command to compile/build/package the PetClinic Micro services into Docker containers:
4036

4137
```bash
42-
./mvnw package -Dmaven.test.skip=true
38+
. ./scripts/build.sh
4339
```
4440

4541
{{% notice style="info" %}}
46-
This will take a few minutes the first time you run, `maven` will download a lot of dependencies before it compiles the application. Future executions will be a lot quicker.
42+
This will take a few minutes the first time you run, `maven` will download a lot of dependencies before it compiles the application. Future builds will be a lot quicker.
4743
{{% /notice %}}
4844

49-
Once the compilation is complete, you can run the application with the following command. Notice that we are passing the `mysql` profile to the application, this will tell the application to use the MySQL database we started earlier. We are also setting the `otel.service.name` to a logical service name that will also be used in the UI for filtering:
45+
## 2. Check Docker Images
46+
47+
Once the build completes, you need to verify if the containers are indeed build:
48+
49+
{{< tabs >}}
50+
{{% tab title="Check Docker Containers" %}}
51+
52+
```bash
53+
docker images
54+
```
55+
56+
{{% /tab %}}
57+
{{% tab title="Docker Output" %}}
58+
59+
``` text
60+
61+
splunk@show-no-config-i-027057abec7c0c6d3:~/spring-petclinic-microservices$ docker images
62+
REPOSITORY TAG IMAGE ID CREATED SIZE
63+
quay.io/phagen/spring-petclinic-api-gateway latest f954254824ed 7 seconds ago 510MB
64+
<none> <none> 5dbbb7d1fbb2 9 seconds ago 563MB
65+
quay.io/phagen/spring-petclinic-discovery-server latest 0761e73d679d 26 seconds ago 500MB
66+
<none> <none> d71dc0ff96f4 28 seconds ago 544MB
67+
quay.io/phagen/spring-petclinic-config-server latest 81a0ab6495c2 39 seconds ago 488MB
68+
<none> <none> 69d60a035bb9 40 seconds ago 519MB
69+
quay.io/phagen/spring-petclinic-visits-service latest ca306495bf11 50 seconds ago 526MB
70+
<none> <none> b60155eb8ab4 52 seconds ago 596MB
71+
quay.io/phagen/spring-petclinic-vets-service latest 29f1b1909b8b About a minute ago 527MB
72+
<none> <none> b07e8de54c99 About a minute ago 598MB
73+
quay.io/phagen/spring-petclinic-customers-service latest 5b21e448c91e About a minute ago 526MB
74+
<none> <none> 722fa001614c About a minute ago 596MB
75+
quay.io/phagen/spring-petclinic-admin-server latest 4a1906a91210 About a minute ago 498MB
76+
<none> <none> 96f61c7bb66a About a minute ago 540MB
77+
eclipse-temurin 17 807dd649ff14 13 days ago 407MB
78+
79+
```
80+
81+
{{% /tab %}}
82+
{{< /tabs >}}
83+
84+
To test the application you need to obtain the public IP address of the instance you are running on. You can do this by running the following command:
85+
86+
```bash
87+
curl ifconfig.me
88+
89+
```
90+
91+
You will see an IP address returned, make a note of this as we will need it to validate that the application is running.
92+
93+
We also need to obtain the `INSTANCE` environment variable value, as this is what is being used as the `otel.service.name` attribute. You can do this by running the following command:
94+
95+
```bash
96+
echo $INSTANCE
97+
```
98+
99+
Also, make a note of this value as we will need it to filter the data in the UI.
100+
101+
You can now run the application with the following command. Notice that we are passing the `mysql` profile to the application, this will tell the application to use the MySQL database we started earlier. We are also setting the `otel.service.name` to a logical service name that will also be used in the UI for filtering:
50102

51103
```bash
52104
java \
@@ -55,11 +107,11 @@ java \
55107
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
56108
```
57109

58-
You can validate if the application is running by visiting `http://<VM_IP_ADDRESS>:8083`.
110+
You can validate if the application is running by visiting `http://<IP_ADDRESS>:8083` (replace `<IP_ADDRESS>` with the IP address you obtained earlier). You should see the PetClinic application running.
59111

60112
## 2. AlwaysOn Profiling and Metrics
61113

62-
When we installed the collector we configured it to enable AlwaysOn Profiling and Metrics. This means that the collector will automatically generate CPU and Memory profiles for the application and send them to Splunk Observability Cloud.
114+
When we installed the collector we configured it to enable **AlwaysOn Profiling** and **Metrics**. This means that the collector will automatically generate CPU and Memory profiles for the application and send them to Splunk Observability Cloud.
63115

64116
When you start the PetClinic application you will see the collector automatically detect the application and instrument it for traces and profiling.
65117

@@ -92,7 +144,7 @@ OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader clas
92144

93145
## 3. Review Profiling Data Collection
94146

95-
You can now visit the Splunk APM UI and examine the application components, traces, profiling, DB Query performance and metrics. From the left-hand menu **APM** → Explore**, click the environment dropdown and select your environment (which is prefixed with the hostname of your instance).
147+
You can now visit the Splunk APM UI and examine the application components, traces, profiling, DB Query performance and metrics. From the left-hand menu **APM****Explore**, click the environment dropdown and select your environment e.g. `<INSTANCE>-petclinic` (where`<INSTANCE>` is replaced with the value you noted down earlier).
96148

97149
![APM Environment](../images/apm-environment.png)
98150

@@ -102,13 +154,13 @@ Once your validation is complete you can stop the application by pressing `Ctrl-
102154

103155
Resource attributes can be added to every reported span. For example `version=0.314`. A comma-separated list of resource attributes can also be defined e.g. `key1=val1,key2=val2`.
104156

105-
Let's launch the PetClinic again using a new resource attribute. Note, that adding resource attributes to the run command will override what was defined when we installed the collector. Let's add a new resource attribute `version=0.314`:
157+
Let's launch the PetClinic again using new resource attributes. Note, that adding resource attributes to the run command will override what was defined when we installed the collector. Let's add two new resource attributes `deployment.environment=$INSTANCE-petclinic-env,version=0.314`:
106158

107159
```bash
108160
java \
109161
-Dserver.port=8083 \
110162
-Dotel.service.name=$INSTANCE-petclinic-service \
111-
-Dotel.resource.attributes=version=0.314 \
163+
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
112164
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
113165
```
114166

content/en/other/wip/pet-clinic/1-otel-collector.md renamed to content/en/other/wip/pet-clinic/20-otel-collector.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
---
22
title: Installing the OpenTelemetry Collector
3-
linkTitle: 1. OpenTelemetry Collector
4-
weight: 1
3+
linkTitle: 2. OpenTelemetry Collector
4+
weight: 20
55
---
66

77
## 1. Introduction
88

9-
The OpenTelemetry Collector is the core component of instrumenting infrastructure and applications. Its role is to collect and send:
9+
The Splunk OpenTelemetry Collector is the core component of instrumenting infrastructure and applications. Its role is to collect and send:
1010

11-
* Infrastructure metrics (disk, cpu, memory, etc)
11+
* Infrastructure metrics (disk, CPU, memory, etc)
1212
* Application Performance Monitoring (APM) traces
1313
* Profiling data
1414
* Host and application logs
1515

1616
Splunk Observability Cloud offers a wizard to walk you through the setup of the Collector on both your infrastructure and applications.
1717

1818
{{% notice title="Delete any existing OpenTelemetry Collectors" style="warning" %}}
19-
If you have completed the Splunk IM workshop, please ensure you have deleted the collector running in Kubernetes before continuing. This can be done by running the following command:
19+
If you have completed a Splunk Observability workshop using this EC2 instance, please ensure you have deleted the collector running in Kubernetes before continuing. This can be done by running the following command:
2020

2121
``` bash
2222
helm delete splunk-otel-collector
@@ -38,6 +38,8 @@ In the output check the following environment variables are present and have val
3838
ACCESS_TOKEN
3939
REALM
4040
RUM_TOKEN
41+
HEC_TOKEN
42+
HEC_URL
4143
```
4244

4345
For this workshop, **all** of the above are required. If any are missing, please contact your instructor.
@@ -51,14 +53,17 @@ We can then go ahead and install the Collector. Some additional parameters are p
5153
* `--enable-profiler` - Enables the profiler for the Java application. This will generate CPU profiles for the application.
5254
* `--enable-profiler-memory` - Enables the profiler for the Java application. This will generate memory profiles for the application.
5355
* `--enable-metrics` - Enables the exporting of Micrometer metrics
56+
* `--hec-token` - Sets the HEC token for the collector to use
57+
* `--hec-url` - Sets the HEC URL for the collector to use
5458

5559
``` bash
5660
curl -sSL https://dl.signalfx.com/splunk-otel-collector.sh > /tmp/splunk-otel-collector.sh && \
57-
sudo sh /tmp/splunk-otel-collector.sh --realm $REALM -- $ACCESS_TOKEN --mode agent --without-fluentd --with-instrumentation --deployment-environment $INSTANCE-petclinic --enable-profiler --enable-profiler-memory --enable-metrics
61+
sudo sh /tmp/splunk-otel-collector.sh --realm $REALM -- $ACCESS_TOKEN --mode agent --without-fluentd --with-instrumentation --deployment-environment $INSTANCE-petclinic --enable-profiler --enable-profiler-memory --enable-metrics --hec-token $HEC_TOKEN --hec-url $HEC_URL
5862
```
5963

60-
{{% notice style="info" title="AWS/EC2 instances" %}}
61-
If you are attempting this workshop on an AWS/EC2 instance you will have to patch the collector to expose the hostname of the instance:
64+
When prompted to restart services, select 'OK' and press enter.
65+
66+
Next, we will patch the collector to expose the hostname of the instance and not the AWS instance ID. This will make it easier to filter data in the UI. Run the following command to patch the collector:
6267

6368
``` bash
6469
sudo sed -i 's/gcp, ecs, ec2, azure, system/system, gcp, ecs, ec2, azure/g' /etc/otel/collector/agent_config.yaml
@@ -70,7 +75,6 @@ Once the `agent_config.yaml` has been patched, you will need to restart the coll
7075
sudo systemctl restart splunk-otel-collector
7176
```
7277

73-
{{% /notice %}}
7478
Once the installation is completed, you can navigate to the **Hosts with agent installed** dashboard to see the data from your host, **Dashboards → Hosts with agent installed**.
7579

76-
Use the dashboard filter and select `host.name` and type or select the hostname of your virtual machine. Once you see data flowing for your host, we are then ready to get started with the APM component.
80+
Use the dashboard filter and select `host.name` and type or select the hostname of your workshop instance (you can get this from the command prompt in your terminal session). Once you see data flowing for your host, we are then ready to get started with the APM component.

content/en/other/wip/pet-clinic/3-rum.md

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Real User Monitoring
3+
linkTitle: 4. Real User Monitoring
4+
weight: 40
5+
---
6+
7+
## 1. Enable RUM
8+
9+
For the Real User Monitoring (RUM) instrumentation, we will add the Open Telemetry Javascript [**https://github.com/signalfx/splunk-otel-js-web**](https://github.com/signalfx/splunk-otel-js-web) snippet in the pages, we will use the wizard again **Data Management → Add Integration → RUM Instrumentation → Browser Instrumentation**.
10+
11+
Your instructor will inform you which token to use from the dropdown, click **Next**. Enter **App name** and **Environment** using the following syntax:
12+
13+
- `<INSTANCE>-petclinic-service` - replacing `<INSTANCE>` with the value you noted down earlier.
14+
- `<INSTANCE>-petclinic-env` - replacing `<INSTANCE>` with the value you noted down earlier.
15+
16+
The wizard will then show a snippet of HTML code that needs to be placed at the top of the pages in the `<head>` section. The following is an example of the (do not use this snippet, use the one generated by the wizard):
17+
18+
``` html
19+
/*
20+
21+
IMPORTANT: Replace the <version> placeholder in the src URL with a
22+
version from https://github.com/signalfx/splunk-otel-js-web/releases
23+
24+
*/
25+
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
26+
<script>
27+
SplunkRum.init({
28+
realm: "eu0",
29+
rumAccessToken: "<redacted>",
30+
applicationName: "petclinic-1be0-petclinic-service",
31+
deploymentEnvironment: "petclinic-1be0-petclinic-env"
32+
});
33+
</script>
34+
```
35+
36+
The Spring PetClinic application uses a single HTML page as the "layout" page, that is reused across all pages of the application. This is the perfect location to insert the Splunk RUM Instrumentation Library as it will be loaded in all pages automatically.
37+
38+
Let's then edit the layout page:
39+
40+
```bash
41+
vi src/main/resources/templates/fragments/layout.html
42+
```
43+
44+
Next, insert the snippet we generated above in the `<head>` section of the page. Make sure you don't include the comment and replace `<version>` in the source URL to `latest` e.g.
45+
46+
```html
47+
<!doctype html>
48+
<html th:fragment="layout (template, menu)">
49+
50+
<head>
51+
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
52+
<script>
53+
SplunkRum.init({
54+
realm: "eu0",
55+
rumAccessToken: "<redacted>",
56+
applicationName: "petclinic-1be0-petclinic-service",
57+
deploymentEnvironment: "petclinic-1be0-petclinic-env"
58+
});
59+
</script>
60+
...
61+
```
62+
63+
## 2. Rebuild PetClinic
64+
65+
With the code changes complete, we need to rebuild the application and run it again. Run the `maven` command to compile/build/package PetClinic:
66+
67+
```bash
68+
./mvnw package -Dmaven.test.skip=true
69+
```
70+
71+
```bash
72+
java \
73+
-Dserver.port=8083 \
74+
-Dotel.service.name=$INSTANCE-petclinic-service \
75+
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
76+
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
77+
```
78+
79+
Then let's visit the application using a browser to generate real-user traffic `http://<IP_ADDRESS>:8083`.
80+
81+
In RUM, filter down into the environment as defined in the RUM snippet above and click through to the dashboard.
82+
83+
When you drill down into a RUM trace you will see a link to APM in the spans. Clicking on the trace ID will take you to the corresponding APM trace for the current RUM trace.

0 commit comments

Comments
 (0)