Skip to content

Commit 63038bb

Browse files
committed
Add telemetry-watchdog container implementation for KubeSonic rollout (sonic-net#23724)
Why I did it To implement KubeSonic Design https://github.com/sonic-net/SONiC/blob/ce3ffda18399add1435cb18299c267733dcc2b38/doc/kubernetes/k8s_migration_design.md Work item tracking Microsoft ADO (number only):34506286 How I did it Implement watchdog in rust Signed-off-by: Feng Pan <[email protected]>
1 parent c037d56 commit 63038bb

13 files changed

Lines changed: 353 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
2+
ARG BASE=docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}
3+
4+
FROM $BASE AS builder
5+
6+
# Update apt's cache of available packages
7+
RUN apt-get update && apt-get install -y \
8+
build-essential
9+
10+
# Install Rust/Cargo via rustup
11+
ARG RUST_ROOT=/usr/.cargo
12+
RUN RUSTUP_HOME=$RUST_ROOT CARGO_HOME=$RUST_ROOT bash -c \
13+
'curl --proto "=https" -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.79.0 -y'
14+
ENV RUSTUP_HOME=$RUST_ROOT
15+
ENV PATH $PATH:$RUST_ROOT/bin
16+
17+
# Copy watchdog source into /watchdog
18+
WORKDIR /watchdog
19+
COPY watchdog/ ./
20+
21+
# Build from within /watchdog
22+
RUN cargo build --release
23+
24+
FROM $BASE AS base
25+
26+
ARG docker_container_name
27+
ARG image_version
28+
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf
29+
30+
ENV DEBIAN_FRONTEND=noninteractive
31+
ENV IMAGE_VERSION=$image_version
32+
33+
# Copy supervisord.conf into final stage
34+
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
35+
36+
# Copy the compiled Rust binary from the builder stage
37+
COPY --from=builder /watchdog/target/release/telemetry_watchdog /usr/bin/telemetry_watchdog
38+
RUN chmod +x /usr/bin/telemetry_watchdog
39+
40+
FROM $BASE
41+
42+
RUN --mount=type=bind,from=base,target=/changes-to-image rsync -axAX --no-D --exclude=/sys --exclude=/proc --exclude=/dev --exclude=resolv.conf /changes-to-image/ /
43+
44+
# Make apt-get non-interactive
45+
ENV DEBIAN_FRONTEND=noninteractive
46+
47+
# Pass the image_version to container
48+
ENV IMAGE_VERSION=$image_version
49+
50+
ENTRYPOINT ["/usr/local/bin/supervisord"]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[supervisord]
2+
logfile_maxbytes=1MB
3+
logfile_backups=2
4+
nodaemon=true
5+
6+
[eventlistener:dependent-startup]
7+
command=python3 -m supervisord_dependent_startup
8+
autostart=true
9+
autorestart=unexpected
10+
startretries=0
11+
exitcodes=0,3
12+
events=PROCESS_STATE
13+
buffer_size=1024
14+
15+
[program:rsyslogd]
16+
command=/usr/sbin/rsyslogd -n -iNONE
17+
priority=1
18+
autostart=false
19+
autorestart=unexpected
20+
stdout_logfile=NONE
21+
stdout_syslog=true
22+
stderr_logfile=NONE
23+
stderr_syslog=true
24+
dependent_startup=true
25+
26+
[program:telemetry_watchdog]
27+
command=/usr/bin/telemetry_watchdog
28+
priority=3
29+
autostart=false
30+
autorestart=false
31+
startsecs=0
32+
stdout_logfile=NONE
33+
stdout_syslog=true
34+
stderr_logfile=NONE
35+
stderr_syslog=true
36+
dependent_startup=true
37+
dependent_startup_wait_for=rsyslogd:running

dockers/docker-telemetry-watchdog/watchdog/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "telemetry_watchdog"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "watchdog for telemetry container"
6+
license = "MIT"
7+
authors = ["Feng Pan"]
8+
9+
[dependencies]
10+
daemonize = "0.5"
11+
chrono = "0.4"
12+
serde = { version = "1", features = ["derive"] }
13+
serde_json = "1"
14+
redis = "0.23.3"
15+
url = "=2.4.1"
16+
17+
[[bin]]
18+
name = "telemetry_watchdog"
19+
path = "src/main.rs"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.ONESHELL:
2+
SHELL = /bin/bash
3+
.SHELLFLAGS += -e
4+
5+
#
6+
# Debug build targets
7+
#
8+
build:
9+
cargo build --all
10+
11+
test:
12+
cargo test --all
13+
14+
clean:
15+
cargo clean
16+
17+
#
18+
# Release build targets
19+
#
20+
build-release:
21+
cargo build --release --all
22+
23+
test-release:
24+
cargo test --release --all
25+
26+
clean-release:
27+
cargo clean --release
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonic (1.0.0) stable; urgency=medium
2+
3+
* Initial release
4+
5+
-- Feng Pan <[email protected]> Tue, 15 Apr 2025 03:13:12 +0000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Source: sonic
2+
Maintainer: Feng Pan <[email protected]>
3+
Section: net
4+
Priority: optional
5+
Standards-Version: 1.0.0
6+
7+
Package: sonic-telemetry-watchdog
8+
Architecture: any
9+
Description: telemetry watchdog for KubeSONiC project
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/release/telemetry_watchdog /usr/bin
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/make -f
2+
# See debhelper(7) (uncomment to enable)
3+
# output every command that modifies files on the build system.
4+
#export DH_VERBOSE = 1
5+
6+
%:
7+
dh $@
8+
9+
override_dh_auto_build:
10+
cargo build --release --all
11+
12+
override_dh_auto_clean:
13+
cargo clean --release
14+
15+
override_dh_auto_test:
16+
# do nothing
17+
:

0 commit comments

Comments
 (0)