Debug with Functions CLI

With Pulsar Functions CLI, you can debug Pulsar Functions with the following subcommands:

  • get
  • status
  • stats
  • list
  • trigger

get

To get information about a function, you can specify --fqfn as follows.

  1. ./bin/pulsar-admin functions get public/default/ExclamationFunctio6

Alternatively, you can specify --name, --namespace and --tenant as follows.

  1. ./bin/pulsar-admin functions get \
  2. --tenant public \
  3. --namespace default \
  4. --name ExclamationFunctio6

As shown below, the get command shows input, output, runtime, and other information about the ExclamationFunctio6 function.

  1. {
  2. "tenant": "public",
  3. "namespace": "default",
  4. "name": "ExclamationFunctio6",
  5. "className": "org.example.test.ExclamationFunction",
  6. "inputSpecs": {
  7. "persistent://public/default/my-topic-1": {
  8. "isRegexPattern": false
  9. }
  10. },
  11. "output": "persistent://public/default/test-1",
  12. "processingGuarantees": "ATLEAST_ONCE",
  13. "retainOrdering": false,
  14. "userConfig": {},
  15. "runtime": "JAVA",
  16. "autoAck": true,
  17. "parallelism": 1
  18. }

list

To list all Pulsar Functions running under a specific tenant and namespace:

  1. bin/pulsar-admin functions list \
  2. --tenant public \
  3. --namespace default

As shown below, the list command returns three functions running under the public tenant and the default namespace.

  1. ExclamationFunctio1
  2. ExclamationFunctio2
  3. ExclamationFunctio3

status

To check the current status of a function:

  1. ./bin/pulsar-admin functions status \
  2. --tenant public \
  3. --namespace default \
  4. --name ExclamationFunctio6

As shown below, the status command shows the number of instances, running instances, the instance running under the ExclamationFunctio6 function, received messages, successfully processed messages, system exceptions, the average latency and so on.

  1. {
  2. "numInstances" : 1,
  3. "numRunning" : 1,
  4. "instances" : [ {
  5. "instanceId" : 0,
  6. "status" : {
  7. "running" : true,
  8. "error" : "",
  9. "numRestarts" : 0,
  10. "numReceived" : 1,
  11. "numSuccessfullyProcessed" : 1,
  12. "numUserExceptions" : 0,
  13. "latestUserExceptions" : [ ],
  14. "numSystemExceptions" : 0,
  15. "latestSystemExceptions" : [ ],
  16. "averageLatency" : 0.8385,
  17. "lastInvocationTime" : 1557734137987,
  18. "workerId" : "c-standalone-fw-23ccc88ef29b-8080"
  19. }
  20. } ]
  21. }

stats

To get the current stats of a function:

  1. bin/pulsar-admin functions stats \
  2. --tenant public \
  3. --namespace default \
  4. --name ExclamationFunctio6

The output is shown as follows:

  1. {
  2. "receivedTotal" : 1,
  3. "processedSuccessfullyTotal" : 1,
  4. "systemExceptionsTotal" : 0,
  5. "userExceptionsTotal" : 0,
  6. "avgProcessLatency" : 0.8385,
  7. "1min" : {
  8. "receivedTotal" : 0,
  9. "processedSuccessfullyTotal" : 0,
  10. "systemExceptionsTotal" : 0,
  11. "userExceptionsTotal" : 0,
  12. "avgProcessLatency" : null
  13. },
  14. "lastInvocation" : 1557734137987,
  15. "instances" : [ {
  16. "instanceId" : 0,
  17. "metrics" : {
  18. "receivedTotal" : 1,
  19. "processedSuccessfullyTotal" : 1,
  20. "systemExceptionsTotal" : 0,
  21. "userExceptionsTotal" : 0,
  22. "avgProcessLatency" : 0.8385,
  23. "1min" : {
  24. "receivedTotal" : 0,
  25. "processedSuccessfullyTotal" : 0,
  26. "systemExceptionsTotal" : 0,
  27. "userExceptionsTotal" : 0,
  28. "avgProcessLatency" : null
  29. },
  30. "lastInvocation" : 1557734137987,
  31. "userMetrics" : { }
  32. }
  33. } ]
  34. }

trigger

To trigger a specified function with a supplied value:

  1. ./bin/pulsar-admin functions trigger \
  2. --tenant public \
  3. --namespace default \
  4. --name ExclamationFunctio6 \
  5. --topic persistent://public/default/my-topic-1 \
  6. --trigger-value "hello pulsar functions"

This command simulates the execution process of a function and verifies it. As shown below, the trigger command returns the following result:

  1. This is my function!

Debug with Functions CLI - 图1note

When using the --topic option, you must specify the entire topic name. Otherwise, the following error occurs.

  1. Function in trigger function has unidentified topic
  2. Reason: Function in trigger function has unidentified topic