synchronize guest logs to controller node

use rsync to synchronize guest logs to the controller node so that we can
find the logs even after the instance is deleted

Add a guest-log-collection timer, this timer triggers
guest-log-collection service every 10 seconds

Change-Id: I264235ce7b7df585358654c46bdac4dcd743fb3d
This commit is contained in:
wu.chunyang 2023-06-07 17:44:21 +08:00
parent 58b24ad44f
commit 09fd606163
7 changed files with 50 additions and 1 deletions

View File

@ -463,7 +463,7 @@ function create_guest_image {
curl -sSL ${TROVE_NON_DEV_IMAGE_URL} -o ${image_file} curl -sSL ${TROVE_NON_DEV_IMAGE_URL} -o ${image_file}
else else
echo "Starting to create guest image" echo "Starting to create guest image"
export SYNC_LOG_TO_CONTROLLER=${SYNC_LOG_TO_CONTROLLER:-"False"}
$DEST/trove/integration/scripts/trovestack \ $DEST/trove/integration/scripts/trovestack \
build-image \ build-image \
${TROVE_IMAGE_OS} \ ${TROVE_IMAGE_OS} \
@ -499,6 +499,10 @@ function create_guest_image {
$TROVE_MANAGE db_load_datastore_config_parameters "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" \ $TROVE_MANAGE db_load_datastore_config_parameters "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" \
$DEST/trove/trove/templates/$TROVE_DATASTORE_TYPE/validation-rules.json $DEST/trove/trove/templates/$TROVE_DATASTORE_TYPE/validation-rules.json
fi fi
# NOTE(wuchunyang): Create log directory so that guest agent can rsync logs to this directory
if [[ ${SYNC_LOG_TO_CONTROLLER} == "True" ]]; then
test -e /var/log/guest-agent-logs || sudo mkdir -p /var/log/guest-agent-logs/ && sudo chmod 777 /var/log/guest-agent-logs
fi
} }
function create_registry_container { function create_registry_container {

View File

@ -25,6 +25,12 @@ ${GUEST_VENV}/bin/pip install pip --upgrade
${GUEST_VENV}/bin/pip install -U -c /opt/upper-constraints.txt /opt/guest-agent ${GUEST_VENV}/bin/pip install -U -c /opt/upper-constraints.txt /opt/guest-agent
chown -R ${GUEST_USERNAME}:root ${GUEST_VENV} chown -R ${GUEST_USERNAME}:root ${GUEST_VENV}
# this should only happen in zuul system.
if [[ ${SYNC_LOG_TO_CONTROLLER} == "True" ]]; then
sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g;s/HOST_SCP_USERNAME/${HOST_SCP_USERNAME}/g;" ${SCRIPTDIR}/guest-log-collection.service > /etc/systemd/system/guest-log-collection.service
cp ${SCRIPTDIR}/guest-log-collection.timer /etc/systemd/system/guest-log-collection.timer
fi
if [[ ${DEV_MODE} == "true" ]]; then if [[ ${DEV_MODE} == "true" ]]; then
[[ -n "${HOST_SCP_USERNAME}" ]] || die "HOST_SCP_USERNAME needs to be set to the trovestack host user" [[ -n "${HOST_SCP_USERNAME}" ]] || die "HOST_SCP_USERNAME needs to be set to the trovestack host user"
[[ -n "${ESCAPED_PATH_TROVE}" ]] || die "ESCAPED_PATH_TROVE needs to be set to the path to the trove directory on the trovestack host" [[ -n "${ESCAPED_PATH_TROVE}" ]] || die "ESCAPED_PATH_TROVE needs to be set to the path to the trove directory on the trovestack host"

View File

@ -0,0 +1,13 @@
[Unit]
Description=OpenStack Trove Guest Log Collection Service
[Service]
Type=oneshot
User=ubuntu
Group=ubuntu
EnvironmentFile=/etc/trove/controller.conf
EnvironmentFile=/etc/trove/conf.d/guest_info.conf
ExecStart=/bin/bash -c "sudo rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /home/GUEST_USERNAME/.ssh/id_rsa' -az --exclude='.*' /var/log /var/lib/docker/containers HOST_SCP_USERNAME@$CONTROLLER:/var/log/guest-agent-logs/$guest_id"

View File

@ -0,0 +1,11 @@
[Unit]
Description=OpenStack Trove Guest Log Collection Timer
[Timer]
OnActiveSec=10s
OnUnitInactiveSec=10s
Unit=guest-log-collection.service
Persistent=true
[Install]
WantedBy=multi-user.target

View File

@ -9,3 +9,7 @@ set -o pipefail
if [ "$DIB_INIT_SYSTEM" == "systemd" ]; then if [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
systemctl enable $(svc-map guest-agent) systemctl enable $(svc-map guest-agent)
fi fi
if [[ ${SYNC_LOG_TO_CONTROLLER} == "True" ]]; then
systemctl enable guest-log-collection.timer
fi

View File

@ -37,6 +37,11 @@ function build_guest_image() {
if [[ "${DEV_MODE}" == "true" ]]; then if [[ "${DEV_MODE}" == "true" ]]; then
export SSH_DIR=${SSH_DIR:-"$HOME/.ssh"} export SSH_DIR=${SSH_DIR:-"$HOME/.ssh"}
manage_ssh_keys manage_ssh_keys
# sync_log_to_controller only works in dev mode
export SYNC_LOG_TO_CONTROLLER=${SYNC_LOG_TO_CONTROLLER:-False}
else
# set SYNC_LOG_TO_CONTROLLER to false when dev mode is false
export SYNC_LOG_TO_CONTROLLER=False
fi fi
TEMP=$(mktemp -d ${working_dir}/diskimage-create.XXXXXXX) TEMP=$(mktemp -d ${working_dir}/diskimage-create.XXXXXXX)

View File

@ -299,6 +299,7 @@
Q_ML2_TENANT_NETWORK_TYPE: vxlan Q_ML2_TENANT_NETWORK_TYPE: vxlan
Q_ML2_PLUGIN_MECHANISM_DRIVERS: openvswitch Q_ML2_PLUGIN_MECHANISM_DRIVERS: openvswitch
TROVE_ENABLE_LOCAL_REGISTRY: True TROVE_ENABLE_LOCAL_REGISTRY: True
SYNC_LOG_TO_CONTROLLER: True
TROVE_DATASTORE_VERSION: 5.7.29 TROVE_DATASTORE_VERSION: 5.7.29
devstack_local_conf: devstack_local_conf:
post-config: post-config:
@ -307,6 +308,8 @@
usage_timeout: 1800 usage_timeout: 1800
test-config: test-config:
$TEMPEST_CONFIG: $TEMPEST_CONFIG:
auth:
tempest_roles: ResellerAdmin
database: database:
default_datastore_versions: mysql:5.7.29 default_datastore_versions: mysql:5.7.29
devstack_plugins: devstack_plugins:
@ -330,6 +333,7 @@
s-container: true s-container: true
s-object: true s-object: true
s-proxy: true s-proxy: true
tls-proxy: false
tempest: true tempest: true
q-svc: true q-svc: true
q-agt: true q-agt: true
@ -341,6 +345,8 @@
ovn-northd: false ovn-northd: false
tempest_test_regex: ^trove_tempest_plugin\.tests tempest_test_regex: ^trove_tempest_plugin\.tests
tempest_test_blacklist: '{{ ansible_user_dir }}/{{ zuul.projects["opendev.org/openstack/trove-tempest-plugin"].src_dir }}/tempest_blacklist.txt' tempest_test_blacklist: '{{ ansible_user_dir }}/{{ zuul.projects["opendev.org/openstack/trove-tempest-plugin"].src_dir }}/tempest_blacklist.txt'
zuul_copy_output:
'/var/log/guest-agent-logs/': 'logs'
- job: - job:
name: trove-tempest-postgres name: trove-tempest-postgres