Cloud Code IDE Java Callout Debugging

2 3 267

This community article describes the key steps that need to be done to remotely debug your Java Callout source that executes in a Kubernetes container.

The target audience are the Apigee Java Callout authors and users who need to troubleshoot a callout execution in context of a real proxy. Frequently (especially the second category) would know generic concepts behind remote debugging and can benefit from some tutorial on how this is done in a specific environment.

You can follow the following link for more detailed explanation and a complete step-by-step walkthrough using an example of JSON Sanitizer Apigee Java Callout

https://github.com/apigee/ahr/wiki/tadaa-cloud-code-apigee-hybrid-javacallout-debugging

It's still a good-old Remote JVM debugging

Of course, you can use Eclipse or VIM to do remote java debugging, but they need to be installed and connectivity needs to be taken cared. With CloudShell and Cloud Code it's already there. That also enables an ability to debug your Java Callout code in production deployments, especially when you cannot reproduce the problem on a development system.

In any case, we have to configure two items:

  • jvm-debug port that exposes container's remote debugging port;
  • JAVA_TOOL_OPTIONS environment variable that configures jvm remote debugging options.

Kubernetes Pod Configuration

1. Locate port: section and add three lines that patch the debug port 50005 for the apigee-runtime container name: apigee-runtime

        - containerPort: 50005
          name: jvm-debug
          protocol: TCP

2. Add container environment variable for container name: apigee-runtime at the containers:env: location

        - name: JAVA_TOOL_OPTIONS
          value: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=50005,quiet=y

Cloud Code Configuration

1. Select Cloud Code: Attach (Java) to k8s Pod

Attache Java K8s Pod

2. Edit the launch.json file to finetune a podSelector as follows:

      {
          "name": "Attach to Kubernetes Pod (Java)",
          "type": "cloudcode.kubernetes",
          "request": "attach",
          "language": "Java",
          "debugPort": 50005,
          "podSelector": {
              "debug": "apigee-runtime"
          }
      }

Set Breakpoint and Attach to the Pod

You are now ready to set a breakpoint in your source code; hit a request that would trigger the breakpoint and inspect the context.

Stop at breakpoint

Observe:

  • Call Stack;
  • Local Values;
  • etc...
Comments
dchiesa1
Staff

WOW, this is terrific Yuriy. Cool stuff ! This will be really useful.

Not applicable

Is this helpful in case of onprem ?

ylesyuk
New Member

on-prem case is documented in this lab at the following link:

https://apigee.github.io/alfa/edge-dev-javacallout/#11

Version history
Last update:
‎01-22-2021 05:48 AM
Updated by: