Skip to content

Commit 3b436f7

Browse files
authored
Merge pull request #217805 from SteveSaunders1952/v-ssaunders-LGDoor
Edit of [Spring] Add the doc for "app connect".
2 parents 6faf2a7 + a2ddf4a commit 3b436f7

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: Connect to an app instance for troubleshooting
3+
description: Learn how to connect to an app instance in Azure Spring Apps for troubleshooting.
4+
author: karlerickson
5+
ms.author: xiangy
6+
ms.service: spring-apps
7+
ms.topic: article
8+
ms.date: 11/09/2021
9+
ms.custom: devx-track-java, devx-track-azurecli
10+
---
11+
12+
# Connect to an app instance for troubleshooting
13+
14+
This article describes how to access the shell environment inside your application instances to do advanced troubleshooting.
15+
16+
Although Azure Spring Apps offers various managed troubleshooting approaches, you may want to do advanced troubleshooting using the shell environment. For example, you may want to accomplish the following troubleshooting tasks:
17+
18+
- Directly use Java Development Kit (JDK) tools.
19+
- Diagnose against an app’s back-end services for network connection and API call latency for both virtual-network and non-virtual-network instances.
20+
- Diagnose storage capacity, performance, and CPU/memory issues.
21+
22+
## Prerequisites
23+
24+
- [Azure CLI](/cli/azure/install-azure-cli) with the Azure Spring Apps extension. Use the following command to remove previous versions and install the latest extension. If you previously installed the `spring-cloud` extension, uninstall it to avoid configuration and version mismatches.
25+
26+
```azurecli
27+
az extension remove --name spring
28+
az extension add --name spring
29+
az extension remove --name spring-cloud
30+
```
31+
32+
- A deployed application in Azure Spring Apps.
33+
- If you've deployed a custom container, a shell program. The default is `/bin/sh`.
34+
35+
## Assign an Azure role
36+
37+
Before connecting to an app instance, you must be granted the role *Azure Spring Apps Connect Role*. Connecting to an app instance requires the data action permission `Microsoft.AppPlatform/Spring/apps/deployments/connect/action`.
38+
39+
Use the following command to assign the *Azure Spring Apps Connect Role* role:
40+
41+
```azurecli
42+
az role assignment create \
43+
--role 'Azure Spring Apps Connect Role' \
44+
--scope '<service-instance-resource-id>' \
45+
--assignee '<your-identity>'
46+
```
47+
48+
## Connect to an app instance
49+
50+
If your app contains only one instance, use the following command to connect to the instance:
51+
52+
```azurecli
53+
az spring app connect \
54+
--service <your-service-instance> \
55+
--resource-group <your-resource-group> \
56+
--name <app-name>
57+
```
58+
59+
Otherwise, use the following command to specify the instance:
60+
61+
```azurecli
62+
az spring app connect \
63+
--service <your-service-instance> \
64+
--resource-group <your-resource-group> \
65+
--name <app-name> \
66+
--instance <instance_name>
67+
```
68+
69+
Use the following command to specify another deployment of the app:
70+
71+
```azurecli
72+
az spring app connect \
73+
--service <your-service-instance> \
74+
--resource-group <your-resource-group> \
75+
--name <app-name> \
76+
--deployment green
77+
```
78+
79+
By default, Azure Spring Apps launches the app instance with `/bin/sh` bundled in the base image of the container. Use the following command to switch to another bundled shell such as `/bin/bash`:
80+
81+
```azurecli
82+
az spring app connect \
83+
--service <your-service-instance> \
84+
--resource-group <your-resource-group> \
85+
--name <app-name> \
86+
--shell-cmd /bin/bash
87+
```
88+
89+
If your app is deployed with a custom image and shell, you can also use the `--shell-cmd` parameter to specify your shell.
90+
91+
## Troubleshoot your app instance
92+
93+
After you connect to an app instance, you can check the status of the heap memory.
94+
95+
Use the following command to find the Java process ID, which is usually `1`:
96+
97+
```azurecli
98+
jps
99+
```
100+
101+
The output should look like the following example:
102+
103+
:::image type="content" source="media/how-to-connect-to-app-instance-for-troubleshooting/jps-result.png" alt-text="Screenshot showing the output of the jps command.":::
104+
105+
Then use the following command to run the JDK tool to check the result:
106+
107+
```azurecli
108+
jstat -gc 1
109+
```
110+
111+
The output should look like the following example:
112+
113+
:::image type="content" source="media/how-to-connect-to-app-instance-for-troubleshooting/jstat-result.png" alt-text="Screenshot showing the output of the jstat command.":::
114+
115+
## Disconnect from your app instance
116+
117+
When you're done troubleshooting, use the `exit` command to disconnect from the app instance, or press `Ctrl+d`.
118+
119+
## Troubleshooting tools
120+
121+
The following list describes some of the pre-installed tools that you can use for troubleshooting:
122+
123+
- `lsof` - Lists open files.
124+
- `top` - Displays system summary information and current utilization.
125+
- `ps` - Gets a snapshot of the running process.
126+
- `netstat` - Prints network connections and interface statistics.
127+
- `nslookup` - Queries internet name servers interactively.
128+
- `ping` - Tests whether a network host can be reached.
129+
- `nc` - Reads from and writes to network connections using TCP or UDP.
130+
- `wget` - Lets you download files and interact with REST APIs.
131+
- `df` - Displays the amount of available disk space.
132+
133+
You can also use JDK-bundled tools such as `jps`, `jcmd`, and `jstat`.
134+
135+
The available tools depend on your service tier and type of app deployment. The following table describes the availability of troubleshooting tools:
136+
137+
| Tier | Deployment type | Common tools | JDK tools | Notes |
138+
|------------------------|--------------------------|-----------------------------------------------|------------------------------|-------------------------------------------|
139+
| Basic / Standard tier | Source code / Jar | Y | Y (for Java workloads only) | |
140+
| Basic / Standard tier | Custom image | N | N | Up to your installed tool set. |
141+
| Enterprise Tier | Source code / Artifacts | Y (for full OS stack), N (for base OS stack) | Y (for Java workloads only) | Depends on the OS stack of your builder. |
142+
| Enterprise Tier | Custom image | N | N | Depends on your installed tool set. |
143+
144+
## Limitations
145+
146+
Using the shell environment inside your application instances has the following limitation:
147+
148+
- Because the app is running as a non-root user, you can't execute some actions requiring root permission. For example, you can't install new tools by using the system package manager `apt / yum`.
149+
150+
- Because some Linux capabilities are prohibited, tools that require special privileges, such as `tcpdump`, don't work.
151+
152+
## Next steps
153+
154+
- [Self-diagnose and solve problems in Azure Spring Apps](./how-to-self-diagnose-solve.md)
6.75 KB
Loading
13.9 KB
Loading

articles/spring-apps/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ items:
286286
href: how-to-capture-dumps.md
287287
- name: Use JVM options for troubleshooting
288288
href: how-to-dump-jvm-options.md
289+
- name: Connect to an app instance for troubleshooting
290+
href: how-to-connect-to-app-instance-for-troubleshooting.md
289291
- name: Migrate
290292
items:
291293
- name: Migrate Standard and Basic to Enterprise

0 commit comments

Comments
 (0)