How to debug InfluxDB remotely using Visual Studio Code

InfluxDB is implemented in Go language. So, we need build and debug tools in Go language.

1. Prerequisites

Version of InfluxDB: InfluxDB 2.0

Target Machine: CentOS7

Host Machine: Windows10

2. Preparation in taget machine

Perform the follwing steps in target machine

(1) Install gvm(go version manager)

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

(2) Install build tools for Go language

gvm install go1.15
gvm use go1.15 --default

(3) Install Git

yum -y install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install git --enablerepo=ius --disablerepo=base,epel,extras,updates

(4) Install Bazaar which is a version control system

yum -y install bzr

(5) Install nodejs

yum install https://rpm.nodesource.com/pub_10.x/el/7/x86_64/nodejs-10.23.0-1nodesource.x86_64.rpm

(6) Install yarn which is a package manager for nodejs

yum install yarn

(7) Install build tools for Rust language

curl https://sh.rustup.rs -sSf | sh
source ~/.cargo/env

(8) Install clang which is a C language compiler

yum install clang
yum install llvm-devel
export LLVM_CONFIG_PATH=/bin/llvm-config
export LIBCLANG_PATH=/usr/lib64/llvm

(9) Download the source code of InfluxDB. Hereinafter, we call <src> the directory in which you download source codes of InfluxDB.

Download link: https://github.com/influxdata/influxdb/tree/v2.0.0

3. Preparation in host machine

Install Visual Studio Code and enable remote debugging using vscode-go. For these steps, Refet to 6.(2) and so on.

4. Building InfluxDB

(1) Change directory to <src>

(2) Change “GO_BUILD_ARGS” in ./MakeFile for debugging

Before:

GO_BUILD_ARGS := -tags ‘$(GO_BUILD_TAGS)’

After:

GO_BUILD_ARGS := -tags ‘$(GO_BUILD_TAGS)’ -gcflags=all=’-N -l’

(3) Build with make command

make

5. Debugging

Perform the following steps in Visual Studio Code for debugging influxd which is a backend process of InfluxDB.

(1) Connect to remote machine from host machine

(2) Select [Run]>[Add Configuration]>[Go launch file] and add the following configuration

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "program": "<src>/bin/linux/influxd"
        }
    ]
}

(3) Create any break point on main function “<src>/influxdb-2.0/cmd/main.go”

(4) Press “F5” for starting debug

6. References

(1) Build InfluxDB 2.0 from source codes

https://github.com/influxdata/influxdb/blob/master/CONTRIBUTING.md

(2) Debuging using vscode-go

https://github.com/golang/vscode-go/blob/master/docs/debugging.md

Published by Yuuki Fujii

I love open souce database management systems.

Leave a comment

Your email address will not be published. Required fields are marked *