diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d2da66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/dev_environment/.vagrant +/dev_environment/*.log diff --git a/dev_environment/README.md b/dev_environment/README.md index 0377a1a..92cf5c1 100644 --- a/dev_environment/README.md +++ b/dev_environment/README.md @@ -75,3 +75,7 @@ Here is a visual overview: 3. Start traffic mirrroing via `curl -X POST http://localhost:37080/l3af/configs/v1/add -d "@cfg/traffic_mirroring_payload.json"` from the host 4. Delete the default route by executing this command (`sudo ip r del 192.168.10.50 via 192.168.10.1 dev enp0s8`) on l3af-VM as it is not required in the current vagrant environment 5. SSH into Collector VM via `vagrant ssh collector` command and execute `sudo tcpdump -i enp0s8` to see the mirrored-GUE packets and `sudo tcpdump -i gue1` to see the mirrored-original packets when we send traffic to the l3af VM web server (`hey -n 200 -c 20 http://localhost:18080`) from the host +* Additional steps if you would like to use a custom backend instead of Prometheus for observability through Opentelemetry Collector: + 1. Set `otel_collector: 'true'` in [config.yaml](config.yaml) + 2. Set `endpoint` field in [otel-collector-config.yaml](../dev_environment/cfg/otel-collector-config.yml) under `exporters` > `prometheusremotewrite`. Refer [Opentelemetry Exporters](https://opentelemetry.io/docs/collector/configuration/#exporters) documentation to know more. + 3. Redeploy the Vagrant script (`vagrant reload --provision`) to install the Opentelemetry Collector binary. \ No newline at end of file diff --git a/dev_environment/Vagrantfile b/dev_environment/Vagrantfile index e2753e2..b548f09 100644 --- a/dev_environment/Vagrantfile +++ b/dev_environment/Vagrantfile @@ -91,6 +91,51 @@ Vagrant.configure("2") do |config| rsync SHELL + # Install Opentelemetry collector + if cfg['otel_collector'] == "true" + l3af.vm.provision "shell", inline: <<-SHELL + OTEL_VERSION="0.97.0" + ARCH=$(uname -p) + case $ARCH in + arm) + echo "Installing OTELC for arm" + OTEL_ARCH=arm64 + ;; + aarch64) + echo "Installing OTELC for arm" + OTEL_ARCH=arm64 + ;; + x86_64) + echo "Installing OTELC for amd64" + OTEL_ARCH=amd64 + ;; + i386) + KERNEL=$(uname -m) + if [ "$KERNEL" = "x86_64" ]; + then + echo "Installing OTELC for amd64" + OTEL_ARCH=amd64 + elif [ "$KERNEL" = "i386" ]; + then + echo "Installing OTELC for i386" + OTEL_ARCH=386 + else + echo "The CPU kernel $KERNEL is not supported by the script" + exit 1 + fi + ;; + *) + echo "The CPU architecture $ARCH is not supported by the script" + exit 1 + ;; + esac + OTEL_BINARY="otelcol_${OTEL_VERSION}_linux_${OTEL_ARCH}.tar.gz" + OTEL_DIR="otelcol_${OTEL_VERSION}_linux_${OTEL_ARCH}" + curl --proto '=https' --tlsv1.2 -fOL "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}/${OTEL_BINARY}" + tar -xvf ${OTEL_BINARY} + SHELL + end + # # Install latest golang version l3af.vm.provision "shell", inline: <<-SHELL # Get cpu architecture, arm or amd @@ -140,6 +185,16 @@ Vagrant.configure("2") do |config| # Reboot for updated kernel to load l3af.vm.provision :reload + + # Copy opentelemetry collector config and start opentelemetry collector + if cfg['otel_collector'] == "true" + l3af.vm.provision "shell", inline: <<-SHELL + mkdir -p "/etc/otelcol/" + cp /vagrant/cfg/otel-collector-config.yml /etc/otelcol/config.yml + ./otelcol --config=/etc/otelcol/config.yml & + SHELL + end + l3af.vm.provision :shell, path: "provision.sh" # Always start test servers because they aren't managed services diff --git a/dev_environment/cfg/otel-collector-config.yml b/dev_environment/cfg/otel-collector-config.yml new file mode 100644 index 0000000..1c970d8 --- /dev/null +++ b/dev_environment/cfg/otel-collector-config.yml @@ -0,0 +1,30 @@ +receivers: + prometheus: + config: + scrape_configs: + - job_name: 'otelcol' + scrape_interval: 5s + static_configs: + - targets: ['0.0.0.0:8888'] + - job_name: 'node' + scrape_interval: 5s + static_configs: + - targets: ['localhost:9100'] + - job_name: 'l3af' + scrape_interval: 5s + static_configs: + - targets: ['localhost:8898'] + +processors: + batch: + +exporters: + prometheusremotewrite: + endpoint: # Update the endpoint field with your desired remote backend + +service: + pipelines: + metrics: + receivers: [prometheus] + processors: [batch] + exporters: [prometheusremotewrite] diff --git a/dev_environment/config.yaml b/dev_environment/config.yaml index ed4904b..3f36d3f 100644 --- a/dev_environment/config.yaml +++ b/dev_environment/config.yaml @@ -7,4 +7,5 @@ configs: host_l3af_debug_port: '38899' host_l3afd_code_dir: '/code/l3afd' traffic_mirroring: 'false' + otel_collector: 'false' host_distro_codename: 'jammy' diff --git a/dev_environment/setup_linux_dev_env.sh b/dev_environment/setup_linux_dev_env.sh index d9483cb..786aca0 100755 --- a/dev_environment/setup_linux_dev_env.sh +++ b/dev_environment/setup_linux_dev_env.sh @@ -108,6 +108,55 @@ apt-get install -y bc \ prometheus \ rsync +# Install OTEL collector +if [ $# -ge 1 ] && [ "$1" == "--otel-collector" ]; then + OTEL_VERSION="0.97.0" + case $ARCH in + arm) + echo "Installing OTELC for arm" + OTEL_ARCH="arm" + ;; + + aarch64) + echo "Installing OTELC for arm" + OTEL_ARCH="arm64" + ;; + + x86_64) + echo "Installing OTELC for amd64" + OTEL_ARCH="amd64" + ;; + i386) + KERNEL=$(uname -m) + if [ "$KERNEL" = "x86_64" ]; + then + echo "Installing OTELC for amd64" + OTEL_ARCH="amd64" + elif [ "$KERNEL" = "i386" ]; + then + echo "Installing OTELC for i386" + OTEL_ARCH="386" + else + echo "The CPU kernel $KERNEL is not supported by the script" + exit 1 + fi + ;; + + *) + echo "The CPU architecture $ARCH is not supported by the script" + exit 1 + ;; + esac + OTEL_BINARY="otelcol_${OTEL_VERSION}_linux_${OTEL_ARCH}.tar.gz" + OTEL_DIR="otelcol_${OTEL_VERSION}_linux_${OTEL_ARCH}" + curl --proto '=https' --tlsv1.2 -fOL "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}/${OTEL_BINARY}" + tar -xvf ${OTEL_BINARY} + sudo mv ${OTEL_DIR}/otelcol /usr/local/bin/otelcol + sudo chmod +x /usr/local/bin/otelcol + echo "OTEL Collector version ${OTEL_VERSION} installed successfully." +fi + + # Install the latest go lang version os=`uname|tr '[:upper:]' '[:lower:]'` go_filename=`curl -s https://go.dev/dl/?mode=json|jq '.[0].files[].filename'|grep $os|grep $arch|egrep -v "ppc"|tr -d '"'` @@ -149,6 +198,15 @@ chown root:grafana /etc/grafana/provisioning/datasources/*.yaml # Copy prometheus config and restart prometheus cp /root/l3af-arch/dev_environment/cfg/prometheus.yml /etc/prometheus/prometheus.yml + +# Copy OTEL collector config and start OTEL collector +if [ $# -ge 1 ] && [ "$1" == "--otel-collector" ]; then + echo "Copying OTEL Collector config." + mkdir -p "/etc/otelcol/" + cp /root/l3af-arch/dev_environment/cfg/otel-collector-config.yml /etc/otelcol/config.yml +fi + + if uname -a | grep -q 'WSL'; then echo "WSL DETECTED" @@ -160,6 +218,13 @@ then sleep 1 /etc/init.d/grafana-server stop || true /etc/init.d/grafana-server start || true + + # Start OTEL collector + if [ $# -ge 1 ] && [ "$1" == "--otel-collector" ]; then + /usr/local/bin/otelcol --config=/etc/otelcol/config.yml & + else + echo "Skipping OTEL collector binary startup." + fi else # The configuration got copied, restart the prometheus service systemctl daemon-reload @@ -170,6 +235,13 @@ else # Start and enable Grafana systemctl restart grafana-server systemctl enable grafana-server.service + + # Start OTEL collector + if [ $# -ge 1 ] && [ "$1" == "--otel-collector" ]; then + /usr/local/bin/otelcol --config=/etc/otelcol/config.yml & + else + echo "Skipping OTEL collector binary startup." + fi fi # Get Linux source code to build our eBPF programs against