mirror of https://github.com/alibaba/arthas.git
A case tutorial for troubleshooting HTTP requests returning 401 (#1341)
parent
b66538e148
commit
4c7dd96661
@ -0,0 +1,45 @@
|
||||
{
|
||||
"title": "Arthas 排查HTTP请求返回401 案例",
|
||||
"description": "Arthas 排查HTTP请求返回401 案例",
|
||||
"difficulty": "高级使用者",
|
||||
"time": "10分钟",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "排查HTTP请求返回401",
|
||||
"text": "case-http-401.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "java",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
In this case, the user will resolve the HTTP 401 issue.
|
||||
|
||||
Visit: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/admin
|
||||
|
||||
The result is:
|
||||
|
||||
```
|
||||
Something went wrong: 401 Unauthorized
|
||||
```
|
||||
|
||||
We know that `401` is usually intercepted by the permission-managed `Filter`, so which `Filter` returns 401?
|
||||
|
||||
|
||||
### Track all Filter methods
|
||||
|
||||
Start trace:
|
||||
|
||||
`trace javax.servlet.Filter *`{{execute T2}}
|
||||
|
||||
Visit: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/admin
|
||||
|
||||
At the deepest level of the call tree, you can find `AdminFilterConfig$AdminFilter` which returns `401`:
|
||||
|
||||
```
|
||||
+---[3.806273ms] javax.servlet.FilterChain:doFilter()
|
||||
| `---[3.447472ms] com.example.demo.arthas.AdminFilterConfig$AdminFilter:doFilter()
|
||||
| `---[0.17259ms] javax.servlet.http.HttpServletResponse:sendError()
|
||||
```
|
||||
|
||||
### Get the call stack through stack command
|
||||
|
||||
From the above result, we can find the method: `HttpServletResponse:sendError()`. So we can use `stack` command to resolved the HTTP `401` issue.
|
||||
|
||||
|
||||
Run:
|
||||
|
||||
`stack javax.servlet.http.HttpServletResponse sendError 'params[0]==401'`{{execute T2}}
|
||||
|
||||
Visit: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/admin
|
||||
|
||||
The Result:
|
||||
|
||||
```bash
|
||||
$ stack javax.servlet.http.HttpServletResponse sendError 'params[0]==401'
|
||||
Press Q or Ctrl+C to abort.
|
||||
Affect(class-cnt:2 , method-cnt:4) cost in 87 ms.
|
||||
ts=2019-02-15 16:44:06;thread_name=http-nio-8080-exec-6;id=16;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@8546cd5
|
||||
@org.apache.catalina.connector.ResponseFacade.sendError()
|
||||
at com.example.demo.arthas.AdminFilterConfig$AdminFilter.doFilter(AdminFilterConfig.java:38)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
|
||||
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
|
||||
```
|
@ -0,0 +1,98 @@
|
||||
|
||||
|
||||
Currently, visiting http://localhost/user/0 will return a 500 error:
|
||||
|
||||
`curl http://localhost/user/0`{{execute T3}}
|
||||
|
||||
```
|
||||
{"timestamp":1550223186170,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"id < 1","path":"/user/0"}
|
||||
```
|
||||
|
||||
But what are the specific parameters of the request, what is the exception stack?
|
||||
|
||||
### View the parameters/exception of UserController
|
||||
|
||||
Execute in Arthas:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * '{params, throwExp}'`{{execute T2}}
|
||||
|
||||
|
||||
1. The first argument is the class name, which supports wildcards.
|
||||
2. The second argument is the function name, which supports wildcards.
|
||||
|
||||
Visit `curl http://localhost/user/0`{{execute T3}} , the `watch` command will print the parameters and exception
|
||||
|
||||
```bash
|
||||
$ watch com.example.demo.arthas.user.UserController * '{params, throwExp}'
|
||||
Press Q or Ctrl+C to abort.
|
||||
Affect(class-cnt:1 , method-cnt:2) cost in 53 ms.
|
||||
ts=2019-02-15 01:35:25; [cost=0.996655ms] result=@ArrayList[
|
||||
@Object[][isEmpty=false;size=1],
|
||||
@IllegalArgumentException[java.lang.IllegalArgumentException: id < 1],
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
The user can see that the actual thrown exception is `IllegalArgumentException`.
|
||||
|
||||
The user can exit the watch command by typing `Q`{{execute T2}} or `Ctrl+C`.
|
||||
|
||||
If the user want to expand the result, can use the `-x` option:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * '{params, throwExp}' -x 2`{{execute T2}}
|
||||
|
||||
### The return value expression
|
||||
|
||||
In the above example, the third argument is the `return value expression`, which is actually an `ognl` expression that supports some built-in objects:
|
||||
|
||||
* loader
|
||||
* clazz
|
||||
* method
|
||||
* target
|
||||
* params
|
||||
* returnObj
|
||||
* throwExp
|
||||
* isBefore
|
||||
* isThrow
|
||||
* isReturn
|
||||
|
||||
You can use these built-in objects in the expressions. For example, return an array:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * '{params[0], target, returnObj}'`{{execute T2}}
|
||||
|
||||
|
||||
More references: https://alibaba.github.io/arthas/en/advice-class.html
|
||||
|
||||
|
||||
### The conditional expression
|
||||
|
||||
The `watch` command supports conditional expressions in the fourth argument, such as:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * returnObj 'params[0] > 100'`{{execute T2}}
|
||||
|
||||
When visit https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1 , the `watch` command print nothing.
|
||||
|
||||
When visit https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/101 , the `watch` command will print:
|
||||
|
||||
```bash
|
||||
$ watch com.example.demo.arthas.user.UserController * returnObj 'params[0] > 100'
|
||||
Press Q or Ctrl+C to abort.
|
||||
Affect(class-cnt:1 , method-cnt:2) cost in 47 ms.
|
||||
ts=2019-02-13 19:42:12; [cost=0.821443ms] result=@User[
|
||||
id=@Integer[101],
|
||||
name=@String[name101],
|
||||
]
|
||||
```
|
||||
|
||||
### Capture when an exception occurs
|
||||
|
||||
The `watch` command supports the `-e` option, which means that only requests that throw an exception are caught:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * "{params[0],throwExp}" -e`{{execute T2}}
|
||||
|
||||
|
||||
### Filter by cost
|
||||
|
||||
The watch command supports filtering by cost, such as:
|
||||
|
||||
`watch com.example.demo.arthas.user.UserController * '{params, returnObj}' '#cost>200'`{{execute T2}}
|
@ -0,0 +1,6 @@
|
||||
|
||||
Through this tutorial, you can know how to Troubleshooting HTTP request returns 401. More advanced features can be found in the Advanced Guide below.
|
||||
|
||||
* [Arthas Advanced](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=arthas-advanced)
|
||||
* [Arthas Github](https://github.com/alibaba/arthas)
|
||||
* [Arthas Documentation](https://alibaba.github.io/arthas/en)
|
@ -0,0 +1,45 @@
|
||||
{
|
||||
"title": "Arthas Troubleshooting HTTP request returns 401",
|
||||
"description": "Arthas Troubleshooting HTTP request returns 401",
|
||||
"difficulty": "expert",
|
||||
"time": "10 minutes",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "Troubleshooting HTTP request returns 401",
|
||||
"text": "case-http-401.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "java",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
|
||||
![Arthas](https://alibaba.github.io/arthas/_images/arthas.png)
|
||||
|
||||
`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers.
|
||||
|
||||
`Arthas` supports JDK 6+, supports Linux/Mac/Windows.
|
||||
|
||||
* Github: https://github.com/alibaba/arthas
|
||||
* Documentation: https://alibaba.github.io/arthas/en
|
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command:
|
||||
|
||||
`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar
|
||||
java -jar demo-arthas-spring-boot.jar`{{execute T1}}
|
||||
|
||||
`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot)
|
||||
|
||||
After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com
|
||||
|
||||
![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png)
|
Loading…
Reference in New Issue