How spring boot actuator heapdump behave in cloudfoundry

736 views Asked by At

I am using cloudfoundry with multiple instances. I am trying to generate heapdump using /actuator endpoint of spring.

My doubt is in case of cloudfoundry env where at a time 2 instances running , for which instance it will generate the heapdump. How to know the heapdump is for which instance and is there anyway we can hit a specific instance .

Note: I want to use spring boot actuator /heapdump url option only .

1

There are 1 answers

0
Daniel Mikusa On BEST ANSWER

My doubt is in case of cloudfoundry env where at a time 2 instances running , for which instance it will generate the heapdump.

You can't really know where the request will land in advance. Requests to your app instances are load balanced by Gorouter (round-robin), so unless there is no traffic to your app, the request could hit either backend app instance.

You can, however, determine the app instance to which a request went, after the fact.

  1. In a terminal, run cf logs for your app.

  2. In another terminal, run curl -v .... The output will have a header called X-Vcap-Request-Id. Copy that guid.

    < HTTP/1.1 200 OK
    < Content-Type: text/html; charset=UTF-8
    < Date: Thu, 20 May 2021 12:27:39 GMT
    < Server: Apache
    < Vary: Accept-Encoding
    < X-Vcap-Request-Id: c254c0df-c03f-475f-6210-fe3eea7cf28a  # <-- this line
    < Content-Length: 399
    
  3. Look in the output of cf logs for the guid you captured in the previous step. This will identify the access log entry for the request (see the vcap_request_id field). The app_index field on the same record will tell you which app received the request.

    2021-05-20T08:27:39.85-0400 [RTR/0] OUT php-info.apps.pcfone.io - [2021-05-20T12:27:39.848995848Z] "GET / HTTP/1.1" 200 0 399 "-" "curl/7.64.1" "192.168.4.4:34744" "192.168.16.31:61075" x_forwarded_for:"23.115.134.147, 192.168.4.4" x_forwarded_proto:"https" vcap_request_id:"c254c0df-c03f-475f-6210-fe3eea7cf28a" response_time:0.008122 gorouter_time:0.000506 app_id:"c1985534-3ca3-4ada-8bd2-b9b7a57de440" app_index:"0" x_cf_routererror:"-" x_b3_traceid:"5bc96459099edbfd" x_b3_spanid:"5bc96459099edbfd" x_b3_parentspanid:"-" b3:"5bc96459099edbfd-5bc96459099edbfd"
    

How to know the heapdump is for which instance and is there anyway we can hit a specific instance .

This is what you want: https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#surgical-routing

If you send the X-Cf-App-Instance you can pick a specific app instance. You can then target a specific app instance or ensure you get heap dumps from all of your app instances.

Ex: curl myapp.example.com -H "X-Cf-App-Instance: 5cdc7595-2e9b-4f62-8d5a-a86b92f2df0e:9"

The contents of X-Cf-App-Instance is X-Cf-App-Instance: APP_GUID:APP_INDEX. You can retrieve your app guid with cf app myapp --guid. The APP_INDEX is zero-based, so 0 is the first instance, 1 is the second instance, etc...