Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
SONIC_INCLUDE_SYSTEM_GNMI=$(INCLUDE_SYSTEM_GNMI) \
SONIC_INCLUDE_SYSTEM_BMP=$(INCLUDE_SYSTEM_BMP) \
SONIC_INCLUDE_SYSTEM_EVENTD=$(INCLUDE_SYSTEM_EVENTD) \
SONIC_INCLUDE_SYSTEM_OTEL=$(INCLUDE_SYSTEM_OTEL) \
INCLUDE_DHCP_RELAY=$(INCLUDE_DHCP_RELAY) \
INCLUDE_DHCP_SERVER=$(INCLUDE_DHCP_SERVER) \
INCLUDE_MACSEC=$(INCLUDE_MACSEC) \
Expand Down
63 changes: 63 additions & 0 deletions dockers/docker-sonic-otel/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
ARG BASE=docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

FROM $BASE AS base

ARG docker_container_name
ARG image_version

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

# Pass the image_version to container
ENV IMAGE_VERSION=$image_version

RUN apt-get update

{% if docker_sonic_otel_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_sonic_otel_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_sonic_otel_debs.split(' ')) }}
{%- endif %}

# Install dependencies
RUN apt-get install -y \
ca-certificates \
curl \
wget

# Install OpenTelemetry Collector from official .deb package
ARG OTEL_VERSION=0.114.0

# Download and install official .deb package with architecture-specific logic
{% if CONFIGURED_ARCH == "armhf" %}
RUN wget -v -O /tmp/otelcol-contrib.deb \
"https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}/otelcol-contrib_${OTEL_VERSION}_linux_armv7.deb" && \
dpkg --info /tmp/otelcol-contrib.deb && \
(dpkg -i /tmp/otelcol-contrib.deb || apt-get install -f -y) && \
ln -sf /usr/bin/otelcol-contrib /usr/local/bin/otelcol-contrib && \
rm /tmp/otelcol-contrib.deb
{% elif CONFIGURED_ARCH == "arm64" %}
RUN wget -v -O /tmp/otelcol-contrib.deb \
"https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}/otelcol-contrib_${OTEL_VERSION}_linux_arm64.deb" && \
dpkg --info /tmp/otelcol-contrib.deb && \
(dpkg -i /tmp/otelcol-contrib.deb || apt-get install -f -y) && \
ln -sf /usr/bin/otelcol-contrib /usr/local/bin/otelcol-contrib && \
rm /tmp/otelcol-contrib.deb
{% else %}
RUN wget -v -O /tmp/otelcol-contrib.deb \
"https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}/otelcol-contrib_${OTEL_VERSION}_linux_amd64.deb" && \
dpkg --info /tmp/otelcol-contrib.deb && \
(dpkg -i /tmp/otelcol-contrib.deb || apt-get install -f -y) && \
ln -sf /usr/bin/otelcol-contrib /usr/local/bin/otelcol-contrib && \
rm /tmp/otelcol-contrib.deb
{% endif %}

COPY ["start.sh", "otel.sh", "/usr/bin/"]
RUN chmod +x /usr/bin/start.sh /usr/bin/otel.sh
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["critical_processes", "/etc/supervisor"]

ENTRYPOINT ["/usr/local/bin/supervisord"]
5 changes: 5 additions & 0 deletions dockers/docker-sonic-otel/base_image_files/monit_otel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
###############################################################################
## Monit configuration for otel container
###############################################################################
check program container_memory_otel with path "/usr/bin/memory_checker otel 419430400"
if status == 3 for 10 times within 20 cycles then exec "/usr/bin/restart_service otel" repeat every 2 cycles
2 changes: 2 additions & 0 deletions dockers/docker-sonic-otel/critical_processes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
program:otel

38 changes: 38 additions & 0 deletions dockers/docker-sonic-otel/otel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

EXIT_OTEL_CONFIG_FILE_NOT_FOUND=1
OTEL_CONFIG_FILE=/etc/sonic/otel_config.yml

echo "Starting otel.sh script"
echo "Checking for config file: $OTEL_CONFIG_FILE"

if [ ! -f "$OTEL_CONFIG_FILE" ]; then
echo "ERROR: OTEL config file not found at $OTEL_CONFIG_FILE"
exit $EXIT_OTEL_CONFIG_FILE_NOT_FOUND
fi

echo "Config file found at: $OTEL_CONFIG_FILE"

# Validate the YAML configuration
echo "Validating YAML configuration..."
python3 -c "import yaml; yaml.safe_load(open(\"$OTEL_CONFIG_FILE\"))" 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: YAML configuration is invalid"
exit 1
fi

OTEL_ARGS="--config=$OTEL_CONFIG_FILE"

echo "Checking otelcol-contrib binary"
ls -la /usr/local/bin/otelcol-contrib

if [ ! -x "/usr/local/bin/otelcol-contrib" ]; then
echo "ERROR: otelcol-contrib binary not found or not executable"
exit 1
fi

echo "otel collector args: $OTEL_ARGS"
echo "Starting OTEL Collector with config file: $OTEL_CONFIG_FILE"

exec /usr/local/bin/otelcol-contrib ${OTEL_ARGS}

14 changes: 14 additions & 0 deletions dockers/docker-sonic-otel/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

if [ "${RUNTIME_OWNER}" == "" ]; then
RUNTIME_OWNER="kube"
fi

CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py"
if test -f ${CTR_SCRIPT}
then
${CTR_SCRIPT} -f otel -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION}
fi

mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
58 changes: 58 additions & 0 deletions dockers/docker-sonic-otel/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[supervisord]
logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true

[eventlistener:dependent-startup]
command=python3 -m supervisord_dependent_startup
autostart=true
autorestart=unexpected
startretries=0
exitcodes=0,3
events=PROCESS_STATE
buffer_size=1024

[eventlistener:supervisor-proc-exit-listener]
command=/usr/local/bin/supervisor-proc-exit-listener --container-name otel
events=PROCESS_STATE_EXITED,PROCESS_STATE_RUNNING
autostart=true
autorestart=unexpected
buffer_size=1024

[program:rsyslogd]
command=/usr/sbin/rsyslogd -n -iNONE
priority=1
autostart=false
autorestart=true
stdout_logfile=NONE
stdout_syslog=true
stderr_logfile=NONE
stderr_syslog=true
dependent_startup=true

[program:start]
command=/usr/bin/start.sh
priority=2
autostart=false
autorestart=false
startsecs=0
stdout_logfile=NONE
stdout_syslog=true
stderr_logfile=NONE
stderr_syslog=true
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running

[program:otel]
command=/usr/bin/otel.sh
priority=3
autostart=false
autorestart=true
startsecs=0
stdout_logfile=NONE
stdout_syslog=true
stderr_logfile=NONE
stderr_syslog=true
dependent_startup=true
dependent_startup_wait_for=start:exited

15 changes: 15 additions & 0 deletions files/build_templates/otel.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Otel container
Requires=database.service
Before=swss.service
BindsTo=sonic.target
After=sonic.target
StartLimitIntervalSec=1200
StartLimitBurst=3

[Service]
User={{ sonicadmin_user }}
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop
RestartSec=30
8 changes: 8 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,13 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable dash-engine

{%- endif %}

{%- if include_system_otel == "y" %}

# Copy OTEL configuration files
sudo cp $IMAGE_CONFIGS/otel/otel_config.yml $FILESYSTEM_ROOT/etc/sonic/

{%- endif %}

# Copy platform topology configuration scripts
sudo cp $IMAGE_CONFIGS/config-topology/config-topology.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "config-topology.service" | sudo tee -a $GENERATED_SERVICE_FILE
Expand Down Expand Up @@ -1032,6 +1039,7 @@ sudo LANG=C cp $SCRIPTS_DIR/database.sh $FILESYSTEM_ROOT/usr/local/bin/database.
sudo LANG=C cp $SCRIPTS_DIR/snmp.sh $FILESYSTEM_ROOT/usr/local/bin/snmp.sh
sudo LANG=C cp $SCRIPTS_DIR/telemetry.sh $FILESYSTEM_ROOT/usr/local/bin/telemetry.sh
sudo LANG=C cp $SCRIPTS_DIR/gnmi.sh $FILESYSTEM_ROOT/usr/local/bin/gnmi.sh
sudo LANG=C cp $SCRIPTS_DIR/otel.sh $FILESYSTEM_ROOT/usr/local/bin/otel.sh
sudo LANG=C cp $SCRIPTS_DIR/bmp.sh $FILESYSTEM_ROOT/usr/local/bin/bmp.sh
sudo LANG=C cp $SCRIPTS_DIR/mgmt-framework.sh $FILESYSTEM_ROOT/usr/local/bin/mgmt-framework.sh
sudo LANG=C cp $SCRIPTS_DIR/asic_status.sh $FILESYSTEM_ROOT/usr/local/bin/asic_status.sh
Expand Down
1 change: 1 addition & 0 deletions files/image_config/logrotate/rsyslog.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/var/log/teamd.log
/var/log/telemetry.log
/var/log/gnmi.log
/var/log/otel.log
/var/log/frr/bgpd.log
/var/log/frr/zebra.log
/var/log/swss/sairedis*.rec
Expand Down
38 changes: 38 additions & 0 deletions files/image_config/otel/otel_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
receivers:
otlp:
protocols:
grpc:
endpoint: "127.0.0.1:4317"
http:
endpoint: "127.0.0.1:4318"

processors:
batch:
timeout: 1s
send_batch_size: 1000

exporters:
debug:
verbosity: detailed

service:
telemetry:
logs:
level: "info"

pipelines:
metrics:
receivers: [otlp]
processors: [batch]
exporters: [debug]

logs:
receivers: [otlp]
processors: [batch]
exporters: [debug]

traces:
receivers: [otlp]
processors: [batch]
exporters: [debug]

15 changes: 15 additions & 0 deletions files/image_config/rsyslog/rsyslog.d/00-sonic.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ if $msg startswith " telemetry" or ($msg startswith " dialout" )then {
/var/log/telemetry.log
stop
}

## otel rules
if $msg startswith " otel" then {
/var/log/otel.log
stop
}

## stpd rules
if $programname contains "stp" then {
if not ($msg contains "STP_SYSLOG") then {
/var/log/stpd.log
stop
}
}

1 change: 1 addition & 0 deletions files/scripts/otel.sh
3 changes: 3 additions & 0 deletions rules/config
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ INCLUDE_SYSTEM_EVENTD = y
# INCLUDE_SYSTEM_TELEMETRY - build docker-sonic-telemetry for system telemetry support
INCLUDE_SYSTEM_TELEMETRY = n

# INCLUDE_SYSTEM_OTEL - build docker-sonic-otel for High Frequency Telemetry (HFT) support
INCLUDE_SYSTEM_OTEL = y

# INCLUDE_ICCPD - build docker-iccpd for mclag support
INCLUDE_ICCPD = n

Expand Down
11 changes: 11 additions & 0 deletions rules/docker-otel.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DPATH := $($(DOCKER_OTEL)_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/docker-otel.mk rules/docker-otel.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files $(DPATH))

$(DOCKER_OTEL)_CACHE_MODE := GIT_CONTENT_SHA
$(DOCKER_OTEL)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(DOCKER_OTEL)_DEP_FILES := $(DEP_FILES)

$(eval $(call add_dbg_docker,$(DOCKER_OTEL),$(DOCKER_OTEL_DBG)))

40 changes: 40 additions & 0 deletions rules/docker-otel.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# docker image for otel collector

DOCKER_OTEL_STEM = docker-sonic-otel
DOCKER_OTEL = $(DOCKER_OTEL_STEM).gz
DOCKER_OTEL_DBG = $(DOCKER_OTEL_STEM)-$(DBG_IMAGE_MARK).gz

$(DOCKER_OTEL)_PATH = $(DOCKERS_PATH)/$(DOCKER_OTEL_STEM)

$(DOCKER_OTEL)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_DEPENDS)
$(DOCKER_OTEL)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BOOKWORM)
$(DOCKER_OTEL)_VERSION = 1.0.0
$(DOCKER_OTEL)_PACKAGE_NAME = otel
$(DOCKER_OTEL)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_IMAGE_PACKAGES)

SONIC_DOCKER_IMAGES += $(DOCKER_OTEL)
SONIC_BOOKWORM_DOCKERS += $(DOCKER_OTEL)
ifeq ($(INCLUDE_SYSTEM_OTEL), y)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_OTEL)
endif

SONIC_DOCKER_DBG_IMAGES += $(DOCKER_OTEL_DBG)
SONIC_BOOKWORM_DBG_DOCKERS += $(DOCKER_OTEL_DBG)
ifeq ($(INCLUDE_SYSTEM_OTEL), y)
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_OTEL_DBG)
endif

$(DOCKER_OTEL)_CONTAINER_NAME = otel
$(DOCKER_OTEL)_RUN_OPT += -t
$(DOCKER_OTEL)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
$(DOCKER_OTEL)_RUN_OPT += -v /etc/localtime:/etc/localtime:ro
$(DOCKER_OTEL)_RUN_OPT += -v /:/mnt/host:ro
$(DOCKER_OTEL)_RUN_OPT += -v /tmp:/mnt/host/tmp:rw
$(DOCKER_OTEL)_RUN_OPT += -v /var/tmp:/mnt/host/var/tmp:rw
$(DOCKER_OTEL)_RUN_OPT += --pid=host
$(DOCKER_OTEL)_RUN_OPT += --privileged
$(DOCKER_OTEL)_RUN_OPT += --userns=host

$(DOCKER_OTEL)_BASE_IMAGE_FILES += monit_otel:/etc/monit/conf.d


6 changes: 6 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ ifeq ($(SONIC_INCLUDE_SYSTEM_GNMI),y)
INCLUDE_SYSTEM_GNMI = y
endif

ifeq ($(SONIC_INCLUDE_SYSTEM_OTEL),y)
INCLUDE_SYSTEM_OTEL = y
endif

ifeq ($(SONIC_INCLUDE_SYSTEM_BMP),y)
INCLUDE_SYSTEM_BMP = y
endif
Expand Down Expand Up @@ -444,6 +448,7 @@ $(info "INCLUDE_ICCPD" : "$(INCLUDE_ICCPD)")
$(info "INCLUDE_SYSTEM_TELEMETRY" : "$(INCLUDE_SYSTEM_TELEMETRY)")
$(info "INCLUDE_SYSTEM_GNMI" : "$(INCLUDE_SYSTEM_GNMI)")
$(info "INCLUDE_SYSTEM_BMP" : "$(INCLUDE_SYSTEM_BMP)")
$(info "INCLUDE_SYSTEM_OTEL" : "$(INCLUDE_SYSTEM_OTEL)")
$(info "INCLUDE_SYSTEM_EVENTD" : "$(INCLUDE_SYSTEM_EVENTD)")
$(info "ENABLE_HOST_SERVICE_ON_START" : "$(ENABLE_HOST_SERVICE_ON_START)")
$(info "INCLUDE_RESTAPI" : "$(INCLUDE_RESTAPI)")
Expand Down Expand Up @@ -1437,6 +1442,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
export sonic_su_mode="$(SECURE_UPGRADE_MODE)"
export sonic_su_prod_signing_tool="/sonic/scripts/$(shell basename -- $(SECURE_UPGRADE_PROD_SIGNING_TOOL))"
export include_system_telemetry="$(INCLUDE_SYSTEM_TELEMETRY)"
export include_system_otel="$(INCLUDE_SYSTEM_OTEL)"
export include_system_gnmi="$(INCLUDE_SYSTEM_GNMI)"
export include_system_bmp="$(INCLUDE_SYSTEM_BMP)"
export include_system_eventd="$(INCLUDE_SYSTEM_EVENTD)"
Expand Down
Loading
Loading