This document describes how to debug Pulsar functions through Pod logs, log topics, and
Use Pod logs
Logs in Kubernetes give you insight into resources such as nodes, Pods, containers, deployments and replica sets. This insight allows you to observe the interactions between those resources and see the effects that one action has on another. Pod logs record events happening in a cluster, which can be very useful for debugging. Before debugging a Pod, you need to ensure the Pod is already scheduled and running.
The built-in way to check logs on your Kubernetes cluster is with
kubectl CLI commands. You can use the
kubectl logs pod POD_NAME -n NAMESPACE_NAME to check logs of the affected container. In addition, you can use
kubectl logs pod POD_NAME -n NAMESPACE_NAME --previous to retrieve logs from a previous instantiation of a container.
In addition, you can use the following command to check the specific Pod.
kubectl get pod POD_NAME -n NAMESPACE_NAME: check Pod status.
kubectl describe pod POD_NAME -n NAMESPACE_NAME: check the current state of the Pod and recent events.
For the use of
kubectl commands, see here.
Use log topic
In Pulsar Functions, you can generate log information defined in functions to a specified log topic. You can configure consumers to consume messages from a specified log topic to check the log information.
As shown in the example above, you can get the logger via
context.getLogger() and assign the logger to the
LOG variable of
slf4j, so you can define your desired log information in a function using the
LOG variable. Meanwhile, you need to specify the topic to which the log information is produced.
This example shows how to specify the log topic through the CRD.apiVersion: cloud.streamnative.io/v1alpha1kind: Functionmetadata:name: java-function-samplenamespace: defaultspec:className: exclamation_function.ExclamationFunctionforwardSourceMessageProperty: truemaxPendingAsyncRequests: 1000replicas: 1maxReplicas: 5logTopic: persistent://public/default/logging-function-logsinput:topics:- persistent://public/default/java-function-input-topictypeClassName: java.lang.Stringoutput:topic: persistent://public/default/java-function-output-topictypeClassName: java.lang.String# Other function configs
This example shows how to specify the log topic through the
To use the
pulsar-adminCLI tool to monitor Pulsar functions and connectors, you should start Function Mesh Worker service in advance. For details, see work with
pulsar-adminCLI tool.bin/pulsar-admin functions create \--log-topic persistent://public/default/logging-function-logs \# Other function configs
pulsar-admin CLI tool
To debug a Pulsar function, you can perform the following operations.
- Get the information of a Pulsar function.
- Get a list of running Pulsar functions.
- Get the current status of a Pulsar function.
- Get the current stats of a Pulsar function.
- Trigger the specified Pulsar Function.
For more information, see Pulsar Functions CLIs.
pulsar-admin functions get command is used to get information about a Pulsar Function.
pulsar-admin functions list command is used to lists all running Pulsar functions.
pulsar-admin functions status command is used to check the current status of a Pulsar function.
pulsar-admin functions stats command is used to get the current stats of a Pulsar Function.
pulsar-admin functions trigger command is used to trigger a specified Pulsar Function with a supplied value. This command simulates the execution process of a Pulsar Function and verifies it.