This guide explains how to debug connectors in localrun or cluster mode and gives a debugging checklist.
To better demonstrate how to debug Pulsar connectors, take the Mongo sink connector as an example.
Deploy a Mongo sink environment
Start a Mongo service.
docker pull mongo:4 docker run -d-p27017:27017 --name pulsar-mongo -v$PWD/data:/data/db mongo:4
Create a DB and a collection.
dockerexec-it pulsar-mongo /bin/bash mongo > use pulsar > db.createCollection('messages') >exit
To clearly explain the log information, the following is a breakdown into smaller blocks with added descriptions.
This piece of log information shows the storage path of the nar package after decompression.
08:21:54.132 [main] INFO org.apache.pulsar.common.nar.NarClassLoader - Created class loader with paths: [file:/tmp/pulsar-nar/pulsar-io-mongo-2.4.0.nar-unpacked/, file:/tmp/pulsar-nar/pulsar-io-mongo-2.4.0.nar-unpacked/META-INF/bundled-dependencies/,
tip
If class cannot be found exception is thrown, check whether the nar file is decompressed in the folder file:/tmp/pulsar-nar/pulsar-io-mongo-2.4.0.nar-unpacked/META-INF/bundled-dependencies/ or not.
This piece of log information illustrates the basic information about the Mongo sink connector, such as tenant, namespace, name, parallelism, resources, and so on, which can be used to check whether the Mongo sink connector is configured correctly or not.
This piece of log information demonstrates the status of the connections to Mongo and configuration information.
08:21:56.231 [cluster-ClusterId{value='5d6396a3c9e77c0569ff00eb', description='null'}-pulsar-mongo:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:1, serverValue:8}] to pulsar-mongo:27017 08:21:56.326 [cluster-ClusterId{value='5d6396a3c9e77c0569ff00eb', description='null'}-pulsar-mongo:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=pulsar-mongo:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 0]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=89058800}
This piece of log information explains the configuration of consumers and clients, including the topic name, subscription name, subscription type, and so on.
Use the status command to get the current status about the Mongo sink connector, such as the number of instance, the number of running instance, instanceId, workerId and so on.
./bin/pulsar-admin sinks status --tenant public \ --namespace default \ --name pulsar-mongo-sink
For more information about the status command, see status.
If there are multiple connectors running on a worker, workerId can locate the worker on which the specified connector is running.
Use the topics stats command to get the stats for a topic and its connected producer and consumer, such as whether the topic has received messages or not, whether there is a backlog of messages or not, the available permits and other key information. All rates are computed over a 1-minute window and are relative to the last completed 1-minute period.
This checklist indicates the major areas to check when you debug connectors. It is a reminder of what to look for to ensure a thorough review and an evaluation tool to get the status of connectors.
Does Pulsar start successfully?
Does the external service run normally?
Is the nar package complete?
Is the connector configuration file correct?
In localrun mode, run a connector and check the printed information (connector log) on the console.
In cluster modeοΌ
Use the get command to get the basic information.
Use the status command to get the current status.
Use the topics stats command to get the stats for a specified topic and its connected producers and consumers.
Check the connector log.
Enter into the external system and verify the result.