Skip to content

Commit b6b1f3f

Browse files
arlakshmabdosi
authored andcommitted
syslog changes Multi ASIC platforms (#4738)
Add changes for syslog support for containers running in namespaces on multi ASIC platforms. On Multi ASIC platforms Rsyslog service is only running on the host. There is no rsyslog service running in each namespace. On multi ASIC platforms the rsyslog service on the host will be listening on the docker0 ip address instead of loopback address. The rsyslog.conf on the containers is modified to have omfwd target ip to be docker0 ipaddress instead of loopback ip Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <[email protected]>
1 parent ee13e78 commit b6b1f3f

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

files/build_templates/docker_image_ctl.j2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ link_namespace() {
2727
}
2828
{%- endif %}
2929

30+
function updateSyslogConf()
31+
{
32+
# On multiNPU platforms, change the syslog target ip to docker0 ip to allow logs from containers
33+
# running on the namespace to reach the rsyslog service running on the host
34+
# Also update the container name
35+
if [[ ($NUM_ASIC -gt 1) ]]; then
36+
TARGET_IP=$(docker network inspect bridge --format={{ "'{{(index .IPAM.Config 0).Gateway}}'" }})
37+
CONTAINER_NAME="{{docker_container_name}}$DEV"
38+
TMP_FILE="/tmp/rsyslog.$CONTAINER_NAME.conf"
39+
40+
sonic-cfggen -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{\"target_ip\": \"$TARGET_IP\", \"container_name\": \"$CONTAINER_NAME\" }" > $TMP_FILE
41+
docker cp $TMP_FILE {{docker_container_name}}$DEV:/etc/rsyslog.conf
42+
rm -rf $TMP_FILE
43+
fi
44+
}
45+
3046
function getMountPoint()
3147
{
3248
echo $1 | python -c "import sys, json, os; mnts = [x for x in json.load(sys.stdin)[0]['Mounts'] if x['Destination'] == '/usr/share/sonic/hwsku']; print '' if len(mnts) == 0 else os.path.basename(mnts[0]['Source'])" 2>/dev/null
@@ -68,6 +84,7 @@ function preStartAction()
6884
{%- else %}
6985
: # nothing
7086
{%- endif %}
87+
updateSyslogConf
7188
}
7289

7390
function postStartAction()

files/build_templates/sonic_debian_extension.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ echo "warmboot-finalizer.service" | sudo tee -a $GENERATED_SERVICE_FILE
209209
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
210210
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/
211211
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
212+
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-container.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
212213
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/
213214
echo "rsyslog-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
214215

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
#!/bin/bash
22

3-
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf
3+
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
4+
5+
# Parse the device specific asic conf file, if it exists
6+
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
7+
if [ -f "$ASIC_CONF" ]; then
8+
source $ASIC_CONF
9+
fi
10+
11+
# On Multi NPU platforms we need to start the rsyslog server on the docker0 ip address
12+
# for the syslogs from the containers in the namespaces to work.
13+
# on Single NPU platforms we continue to use loopback adddres
14+
15+
if [[ ($NUM_ASIC -gt 1) ]]; then
16+
udp_server_ip=$(ip -o -4 addr list docker0 | awk '{print $4}' | cut -d/ -f1)
17+
else
18+
udp_server_ip=$(ip -o -4 addr list lo scope host | awk '{print $4}' | cut -d/ -f1)
19+
fi
20+
21+
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 -a "{\"udp_server_ip\": \"$udp_server_ip\"}" >/etc/rsyslog.conf
22+
423
systemctl restart rsyslog
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# /etc/rsyslog.conf Configuration file for rsyslog.
3+
#
4+
# For more information see
5+
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
6+
7+
8+
#################
9+
#### MODULES ####
10+
#################
11+
12+
$ModLoad imuxsock # provides support for local system logging
13+
14+
#
15+
# Set a rate limit on messages from the container
16+
#
17+
$SystemLogRateLimitInterval 300
18+
$SystemLogRateLimitBurst 20000
19+
20+
#$ModLoad imklog # provides kernel logging support
21+
#$ModLoad immark # provides --MARK-- message capability
22+
23+
# provides UDP syslog reception
24+
#$ModLoad imudp
25+
#$UDPServerRun 514
26+
27+
# provides TCP syslog reception
28+
#$ModLoad imtcp
29+
#$InputTCPServerRun 514
30+
31+
32+
###########################
33+
#### GLOBAL DIRECTIVES ####
34+
###########################
35+
36+
# Set remote syslog server
37+
template (name="ForwardFormatInContainer" type="string" string="<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% {{container_name}}#%syslogtag%%msg:::sp-if-no-1st-sp%%msg%")
38+
*.* action(type="omfwd" target="{{target_ip}}" port="514" protocol="udp" Template="ForwardFormatInContainer")
39+
40+
#
41+
# Use traditional timestamp format.
42+
# To enable high precision timestamps, comment out the following line.
43+
#
44+
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
45+
46+
# Define a custom template
47+
$template SONiCFileFormat,"%TIMESTAMP%.%timestamp:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% {{container_name}}#%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
48+
$ActionFileDefaultTemplate SONiCFileFormat
49+
50+
#
51+
# Set the default permissions for all log files.
52+
#
53+
$FileOwner root
54+
$FileGroup adm
55+
$FileCreateMode 0640
56+
$DirCreateMode 0755
57+
$Umask 0022
58+
59+
#
60+
# Where to place spool and state files
61+
#
62+
$WorkDirectory /var/spool/rsyslog
63+
64+
#
65+
# Include all config files in /etc/rsyslog.d/
66+
#
67+
$IncludeConfig /etc/rsyslog.d/*.conf
68+
69+
#
70+
# Suppress duplicate messages and report "message repeated n times"
71+
#
72+
$RepeatedMsgReduction on
73+
74+
###############
75+
#### RULES ####
76+
###############

files/image_config/rsyslog/rsyslog.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ModLoad imklog # provides kernel logging support
1919

2020
# provides UDP syslog reception
2121
$ModLoad imudp
22-
$UDPServerAddress 127.0.0.1 # bind to localhost before udp server run
22+
$UDPServerAddress {{udp_server_ip}} #bind to localhost before udp server run
2323
$UDPServerRun 514
2424

2525
# provides TCP syslog reception

0 commit comments

Comments
 (0)