New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actuator trace parameters are empty when running in embedded Tomcat #8883

Closed
hotblac opened this Issue Apr 11, 2017 · 1 comment

Comments

Projects
None yet
4 participants
@hotblac
Copy link

hotblac commented Apr 11, 2017

When accessing the Actuator /trace endpoint, when the management.trace.include property includes 'parameters', I expect request parameters to be shown in the JSON response. Instead, the parameters JSON element is always empty.

This appears to be due to a setting in the Embedded Tomcat server. In tomcat-embed-core-8.5.11.jar, the org.apache.catalina.connector.Request class, recycle() method contains:

        if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
            parameterMap = new ParameterMap<>();
        } else {
            parameterMap.setLocked(false);
            parameterMap.clear();
        }

If the else clause is executed (as it is by default), it uses a single ParameterMap instance for all calls to getParameterMap(). When a request is cleared down, the parameters are cleared using parameterMap.clear(). This instance of ParameterMap is added to the Trace object by the WebRequestTraceFilter. When the Request calls the clear() method is called on the ParameterMap, it clears out the instance held by the Trace object, resulting in an empty parameter list when /trace is invoked.

A workaround is to call
System.setProperty("org.apache.catalina.connector.RECYCLE_FACADES", "true");
in the @SpringBootApplication class, before SpringApplication.run is called.This makes the Request.recycle() method create a new instance of ParameterMap.
A suggested solution would be to deep copy the ParameterMap in WebRequestTraceFilter before creating the Trace object.

Found in Spring Boot version 1.5.2.RELEASE
Demonstrated in https://github.com/hotblac/actuator-demo

Steps to reproduce:

  1. Build and run the actuator-demo project (mvn clean install, java -Dserver.port=18080 -jar target/actuator-demo-0.0.1-SNAPSHOT.jar)
  2. Hit the simple endpoint: http://localhost:18080/simple?param1=value1&param2=value2
  3. Request the actuator trace: http://localhost:18080/trace

Expected:
Response is

[
  {
    "timestamp": "2017-04-11 19:40:50",
    "info": {
      "method": "GET",
      "path": "/simple",
      "headers": {},
      "parameters": {
        "param1": [
          "value1"
        ],
        "param2": [
          "value2"
        ]

Actual:
Response is

[
  {
    "timestamp": "2017-04-11 19:39:03",
    "info": {
      "method": "GET",
      "path": "/simple",
      "headers": {},
      "parameters": {}
    }
  }
]
@philwebb

This comment has been minimized.

Copy link
Member

philwebb commented Apr 11, 2017

Thanks for the detailed analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment