Skip to content

Commit

Permalink
more improvements on the process (#147)
Browse files Browse the repository at this point in the history
## Purpose

1. move Dockfiles out of source directory
2. use 'az containerapp update' with updated Dockerfile to update apps
3. build service connection for apps one by one
4. refine the steps to update pom files
5. fix open ai deployment quota issue

## Does this introduce a breaking change?
<!-- Mark one with an "x". -->
```
[ ] Yes
[x] No
```

## Pull Request Type
What kind of change does this Pull Request introduce?

<!-- Please check the one that applies to this PR using "x". -->
```
[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[x] Documentation content changes
[ ] Other... Please describe:
```
  • Loading branch information
sonwan2020 authored Dec 6, 2024
1 parent c860b1e commit 31a6bbd
Show file tree
Hide file tree
Showing 25 changed files with 389 additions and 288 deletions.
2 changes: 1 addition & 1 deletion cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you're not going to continue to use this lab environment, run the following c

`az cognitiveservices account deployment list -g $RESOURCE_GROUP -n $OPEN_AI_SERVICE_NAME -o table`

- delete the deployments on by one
- delete the deployments one by one

`az cognitiveservices account deployment delete -g $RESOURCE_GROUP -n $OPEN_AI_SERVICE_NAME --deployment-name <deployment-name>`

Expand Down
10 changes: 5 additions & 5 deletions docs/02_lab_launch/0203.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Your MySQL database will also have a firewall enabled. This firewall will by def
1. Run the following commands to create a database in the Azure Database for MySQL Flexible Server instance.

```bash
az mysql flexible-server db create \
--server-name $MYSQL_SERVER_NAME \
--resource-group $RESOURCE_GROUP \
-d $DATABASE_NAME
az mysql flexible-server db create \
--server-name $MYSQL_SERVER_NAME \
--resource-group $RESOURCE_GROUP \
-d $DATABASE_NAME
```

1. You will also need to allow connections to the server from your ACA environment. For now, to accomplish this, you will create a server firewall rule to allow inbound traffic from all Azure Services.
Expand Down Expand Up @@ -83,7 +83,7 @@ Your MySQL database will also have a firewall enabled. This firewall will by def
* It changes the default `spring.sql.init` values to use `mysql` configuration.
* It adds a `spring.datasource` property for your mysql database.

1. In the part you pasted, update the values of the target datasource endpoint on line 6, the corresponding admin user account on line 7, and its password on line 8 to match your configuration. Set these values by using the information in the Azure Database for MySQL Flexible Server connection string you recorded earlier in this task.
1. In the part you pasted, update the values of `url`, `username`, `password` in the segment `spring.datasource`. Set these values by using the information in the Azure Database for MySQL Flexible Server connection string you recorded earlier in this task.

1. Save the changes and push the updates you made to the _application.yml_ file to your private GitHub repo by running the following commands from the Git Bash prompt:

Expand Down
30 changes: 25 additions & 5 deletions docs/02_lab_launch/0205.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,27 @@ Make sure the api-gateway and admin-server microservices have public IP addresse

1. Once your build has finished, you can create each of the microservices.

Create image using acr and create container apps with the image from acr.
Create image using acr and create container apps with the image from acr. A Dockerfile is required for acr to build the image. The content of the Dockerfile is:

You'll start with the **api-gateway**. Since this is the entrypoint to your other microservices, you will create it with an `external` ingress. Also, you will bind this app to the configserver and eureka components you created earlier.
```docker
# syntax=docker/dockerfile:1
# run
FROM mcr.microsoft.com/openjdk/jdk:17-distroless
COPY ./target/*.jar app.jar
EXPOSE 8080
# Run the jar file
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
```

The content is saved in file **../tools/Dockerfile**, we use the saved file in the next steps.

1. Let's start with the **api-gateway**. Since this is the entrypoint to your other microservices, you will create it with an `external` ingress. Also, you will bind this app to the configserver and eureka components you created earlier.

```bash
APP_NAME=api-gateway
cp -f ../tools.Dockerfile ./spring-petclinic-$APP_NAME/Dockerfile
az containerapp create \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
Expand All @@ -83,19 +98,22 @@ Make sure the api-gateway and admin-server microservices have public IP addresse
--runtime java
```

1. Wait for the provisioning to finish, now you can create the other microservices, **customers-service**, **vets-service** and **visits-service**. These will be internal microservices, exposed by the **api-gateway**. Since these microservices connect to the MySQL database, you will also assign them the user assigned managed identity.
1. Wait for the provisioning to finish, now you can create the other microservices, **customers-service**, **vets-service** and **visits-service**. These will be internal microservices, exposed by the **api-gateway**.

Since these microservices connect to the acr with managed identity, assign them the user assigned managed identity `USER_ID`.

To save the execute time, you may use the script **create-apps.sh** to deploy the apps:
To save the execute time, you may use the script **../tools/create-apps.sh** to deploy the apps:

```bash
export RESOURCE_GROUP ACA_ENVIRONMENT MYACR USER_ID JAVA_CONFIG_COMP_NAME JAVA_EUREKA_COMP_NAME
./create-apps.sh
../tools/create-apps.sh
```

Or you can run the commands one by one to create these apps:

```bash
APP_NAME=customers-service
cp -f ../tools.Dockerfile ./spring-petclinic-$APP_NAME/Dockerfile
az containerapp create \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
Expand All @@ -111,6 +129,7 @@ Make sure the api-gateway and admin-server microservices have public IP addresse
--runtime java

APP_NAME=vets-service
cp -f ../tools.Dockerfile ./spring-petclinic-$APP_NAME/Dockerfile
az containerapp create \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
Expand All @@ -126,6 +145,7 @@ Make sure the api-gateway and admin-server microservices have public IP addresse
--runtime java

APP_NAME=visits-service
cp -f ../tools.Dockerfile ./spring-petclinic-$APP_NAME/Dockerfile
az containerapp create \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
Expand Down
2 changes: 1 addition & 1 deletion docs/03_lab_monitor/0302.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Enable logging on your Azure Container Apps environment. You can follow the belo
WORKSPACE=la-$APPNAME-$UNIQUEID
az monitor log-analytics workspace create \
--resource-group $RESOURCE_GROUP \
--workspace-name $WORKSPACE
--workspace-name $WORKSPACE
```

1. Enable logging on your Azure Container Apps environment.
Expand Down
141 changes: 121 additions & 20 deletions docs/03_lab_monitor/0303.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,69 +44,86 @@ You can follow the below guidance to do so.

```bash
AI_CONNECTIONSTRING=$(az monitor app-insights component show --app $AINAME -g $RESOURCE_GROUP --query connectionString --output tsv)

echo $AI_CONNECTIONSTRING
```

1. Define image tag
1. Build a image with application insights agent, and set the related environment variables.

```bash
IMAGE_TAG=petclinic-ai-agent
We customize the Dockerfile to build the image with application insights agent. The content of the Dockerfile is

```dockerfile
# syntax=docker/dockerfile:1

# build
FROM mcr.microsoft.com/openjdk/jdk:17-mariner AS build
ARG AI_VERSION=3.5.4
RUN yum update -y && \
yum install -y wget

RUN wget https://github.com/microsoft/ApplicationInsights-Java/releases/download/$AI_VERSION/applicationinsights-agent-$AI_VERSION.jar -O ai.jar --quiet

# run
FROM mcr.microsoft.com/openjdk/jdk:17-distroless

COPY --from=build ./ai.jar ai.jar
COPY ./target/*.jar app.jar
EXPOSE 8080

# Run with javaagent
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-javaagent:/ai.jar", "-jar", "/app.jar"]
```

1. You will now use Azure Container Registry with customized Dockerfile to build your image, and update the container app to enable Application Insights Agent.
This content is saved in file **../tools/ai.Dockerfile**, we use the saved file in the next steps.

1. You will now update the container app to enable Application Insights Agent.

Do this first for the **api-gateway** service. Notice how you are also setting the `APPLICATIONINSIGHTS_CONNECTION_STRING` and `APPLICATIONINSIGHTS_CONFIGURATION_CONTENT` environment variables.
Do this first for the **api-gateway** service. Notice how you are also setting the environment variables `APPLICATIONINSIGHTS_CONNECTION_STRING` and `APPLICATIONINSIGHTS_CONFIGURATION_CONTENT`.

```bash
APP_NAME="api-gateway"
cp -f ../tools/ai.Dockerfile spring-petclinic-$APP_NAME/Dockerfile

az acr build -g $RESOURCE_GROUP --registry $MYACR --image spring-petclinic-$APP_NAME:$IMAGE_TAG --file spring-petclinic-$APP_NAME/ai.Dockerfile spring-petclinic-$APP_NAME

az containerapp update \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--image $MYACR.azurecr.io/spring-petclinic-$APP_NAME:$IMAGE_TAG \
--source ./spring-petclinic-$APP_NAME \
--set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "'$APP_NAME'"}}'
```

1. Once the app **api-gateway** deployment has succeeded, execute the same statements for the other microservices **customers-service**, **vets-service** and **visits-service**.

To save the execute time, you may use the script **build-update-apps.sh** to deploy the apps:
To save the execute time, you may use the script **../tools/build-update-apps.sh** to deploy the apps:

```bash
export RESOURCE_GROUP MYACR IMAGE_TAG AI_CONNECTIONSTRING
./build-update-apps.sh
../tools/build-update-apps.sh
```

Or you can run the commands one by one to build and update these apps:

```bash
APP_NAME="customers-service"
az acr build -g $RESOURCE_GROUP --registry $MYACR --image spring-petclinic-$APP_NAME:$IMAGE_TAG --file spring-petclinic-$APP_NAME/ai.Dockerfile spring-petclinic-$APP_NAME

cp -f ../tools/ai.Dockerfile spring-petclinic-$APP_NAME/Dockerfile
az containerapp update \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--image $MYACR.azurecr.io/spring-petclinic-$APP_NAME:$IMAGE_TAG \
--source ./spring-petclinic-$APP_NAME \
--set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "'$APP_NAME'"}}'

APP_NAME="vets-service"
az acr build -g $RESOURCE_GROUP --registry $MYACR --image spring-petclinic-$APP_NAME:$IMAGE_TAG --file spring-petclinic-$APP_NAME/ai.Dockerfile spring-petclinic-$APP_NAME

cp -f ../tools/ai.Dockerfile spring-petclinic-$APP_NAME/Dockerfile
az containerapp update \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--image $MYACR.azurecr.io/spring-petclinic-$APP_NAME:$IMAGE_TAG \
--source ./spring-petclinic-$APP_NAME \
--set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "'$APP_NAME'"}}'

APP_NAME="visits-service"
az acr build -g $RESOURCE_GROUP --registry $MYACR --image spring-petclinic-$APP_NAME:$IMAGE_TAG --file spring-petclinic-$APP_NAME/ai.Dockerfile spring-petclinic-$APP_NAME

cp -f ../tools/ai.Dockerfile spring-petclinic-$APP_NAME/Dockerfile
az containerapp update \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--image $MYACR.azurecr.io/spring-petclinic-$APP_NAME:$IMAGE_TAG \
--source ./spring-petclinic-$APP_NAME \
--set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "'$APP_NAME'"}}'
```

Expand All @@ -115,3 +132,87 @@ You can follow the below guidance to do so.
{: .note }
> To make sure everything is back up and running as expected, you may want to double check if all your services are back up and running. Check console log if you are seeing any service in failed state.
## Analyze application specific monitoring data

Now that Application Insights is properly configured, you can use this service to monitor what is going on in your application. You can follow the below guidance to do so.

- [Application Insights Overview dashboard](https://learn.microsoft.com/azure/azure-monitor/app/overview-dashboard)

Use this guidance to take a look at:
- The Application Map
- Performance data
- Failures
- Metrics
- Live Metrics
- Availability
- Logs

To get the logging information flowing, you should navigate to your application and to the different sub-pages and refresh each page a couple of times. It might take some time to update Application Insights with information from your application.

Step by step operations

1. In your browser, navigate to the Azure Portal and your resource group.

1. Select the Application Insights resource in the resource group. On the overview page you will already see data about Failed requests, Server response time, Server requests and Availability.

![ai_overview](../../images/ai_overview.png)

1. Select _Application map_. This will show you information about the different applications running in your Spring Cloud Service and their dependencies. This is where the role names you configured in the YAML files are used.

![application map](../../images/app-map.png)

1. Select the _api-gateway_ service. This will show you details about this application, like slowest requests and failed dependencies.

![api-gateway](../../images/api-gateway.png)

1. Select _Performance_. This will show you more data on performance.

![performance](../../images/api-gw-perf.png)

1. You can also drag your mouse on the graph to select a specific time period, and it will update the view.

1. Select again your Application Insights resource to navigate back to the _Application map_ and the highlighted _api-gateway_ service.

1. Select _Live Metrics_, to see live metrics of your application. This will show you near real time performance of your application, as well as the logs and traces coming in

![live metrics](../../images/live-perf.png)

1. Select _Availability_, and next _Create Standard test_, to configure an availability test for your application.

1. Fill out the following details and select _Create_:

- *Test name*: Name for your test
- *URL*: Fill out the URL to your api-gateway
- Keep all the default settings for the rest of the configuration. Notice that Alerts for this test will be enabled.

Once created every 5 minutes your application will now be pinged for availability from 5 test locations.

1. Select the three dots on the right of your newly created availability test and select _Open Rules (Alerts) page_.

1. Select the alert rule for your availability test. By default there are no action groups associated with this alert rule. We will not configure them in this lab, but just for your information, with action groups you can send email or SMS notifications to specific people or groups.

- [Create and manage action groups in the Azure portal](https://docs.microsoft.com/azure/azure-monitor/alerts/action-groups)

1. Navigate back to your Application Insights resource.

1. Select _Failures_, to see information on all failures in your applications. You can click on any of the response codes, exception types or failed dependencies to get more information on these failures.

![failures](../../images/failure.png)

1. Select _Performance_, to see performance data of your applications' operations. This will be a similar view to the one you looked at earlier.

![performance](../../images/perf2.png)

1. Select _Logs_, to see all logged data. You can use Kusto Query Language (KQL) queries to search and analyze the logged data

* [Log queries in Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/logs/log-query-overview)

{:style="counter-reset:step-counter 16"}
1. Select _Queries_ and next _Performance_.

1. Double click _Operations performance_. This will load this query in the query window.

1. Select _Run_, to see the results of this query.

![performance](../../images/performance3.png)
Loading

0 comments on commit 31a6bbd

Please sign in to comment.