Skip to content
Open
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
17 changes: 17 additions & 0 deletions parts/linux/cloud-init/artifacts/cse_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,20 @@ get_compute_sku() {
fi
echo "$vm_sku"
}

enableAndStartCgroupTelemetry() {
# Don't enable cgroup-memory-telemetry on AzureLinux due to incompatibility with cgroup2fs driver and absence of required azure.slice directory
if ! isMarinerOrAzureLinux "$OS"; then
systemctlEnableAndStartNoBlock cgroup-memory-telemetry.timer 30 || exit $ERR_START_CGROUP_TELEMETRY
systemctlEnableAndStartNoBlock cgroup-memory-telemetry.service 30 || exit $ERR_START_CGROUP_TELEMETRY
fi

CGROUP_VERSION=$(stat -fc %T /sys/fs/cgroup)
if [ "$CGROUP_VERSION" = "cgroup2fs" ]; then
systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.timer 30 || exit $ERR_START_CGROUP_TELEMETRY
systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.service 30 || exit $ERR_START_CGROUP_TELEMETRY

systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.timer 30 || exit $ERR_START_CGROUP_TELEMETRY
systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.service 30 || exit $ERR_START_CGROUP_TELEMETRY
fi
}
2 changes: 2 additions & 0 deletions parts/linux/cloud-init/artifacts/cse_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ ERR_CHRONY_NTP_SYNC_FAIL=245 # Chrony could not synchronize with the configured
ERR_CHRONY_CONFIG_FAIL=246 # Chrony could not be configured for Intel TDX
# -----------------------------------------------------------------------------

ERR_START_CGROUP_TELEMETRY=247 # Error enabling and starting cgroup telemetry services

# This probably wasn't launched via a login shell, so ensure the PATH is correct.
[ -f /etc/profile.d/path.sh ] && . /etc/profile.d/path.sh

Expand Down
2 changes: 2 additions & 0 deletions parts/linux/cloud-init/artifacts/cse_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ function nodePrep {
fi
fi

logs_to_events "AKS.CSE.enableAndStartCgroupTelemetry" enableAndStartCgroupTelemetry

if $REBOOTREQUIRED; then
echo 'reboot required, rebooting node in 1 minute'
/bin/bash -c "shutdown -r 1 &"
Expand Down
103 changes: 103 additions & 0 deletions spec/parts/linux/cloud-init/artifacts/cse_config_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,109 @@ Describe 'cse_config.sh'
CSE_CONFIG_ADDONS_FILEPATH="./parts/linux/cloud-init/artifacts/cse_config_addons.sh"
Include "./parts/linux/cloud-init/artifacts/cse_config.sh"
Include "./parts/linux/cloud-init/artifacts/cse_helpers.sh"
Describe 'enableAndStartCgroupTelemetry'
setup_cgroup_telemetry() {
OS="UBUNTU"
OS_VARIANT=""
MOCK_CGROUP_VERSION="cgroup2fs"
FAILED_TELEMETRY_COMMAND=""
memory_commands="systemctlEnableAndStartNoBlock cgroup-memory-telemetry.timer 30
systemctlEnableAndStartNoBlock cgroup-memory-telemetry.service 30"
cpu_pressure_commands="systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.timer 30
systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.service 30
systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.timer 30
systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.service 30"
}

BeforeEach 'setup_cgroup_telemetry'

stat() {
if [ "$*" != "-fc %T /sys/fs/cgroup" ]; then
echo "Unexpected stat arguments: $*" >&2
return 1
fi
echo "$MOCK_CGROUP_VERSION"
}

systemctlEnableAndStartNoBlock() {
echo "systemctlEnableAndStartNoBlock $*"
[ "systemctlEnableAndStartNoBlock $*" != "$FAILED_TELEMETRY_COMMAND" ]
}

Describe 'OS and cgroup eligibility'
Parameters
UBUNTU "" true
MARINER "" false
MARINERKATA "" false
AZURELINUX "" false
AZURELINUXKATA "" false
AZURELINUX OSGUARD false
AZURECONTAINERLINUX "" true
AZURELINUX AZURECONTAINERLINUX true
End

It "configures eligible telemetry on cgroup v2 for $1 variant '$2'"
OS="$1"
OS_VARIANT="$2"
expected_commands="$cpu_pressure_commands"
if [ "$3" = "true" ]; then
expected_commands="$memory_commands
$cpu_pressure_commands"
fi

When run enableAndStartCgroupTelemetry

The status should be success
The output should equal "$expected_commands"
End

It "configures only eligible memory telemetry on cgroup v1 for $1 variant '$2'"
OS="$1"
OS_VARIANT="$2"
MOCK_CGROUP_VERSION="tmpfs"
expected_commands=""
if [ "$3" = "true" ]; then
expected_commands="$memory_commands"
fi

When run enableAndStartCgroupTelemetry

The status should be success
The output should equal "$expected_commands"
End
End

Describe 'startup failures'
Parameters
"systemctlEnableAndStartNoBlock cgroup-memory-telemetry.timer 30" 1
"systemctlEnableAndStartNoBlock cgroup-memory-telemetry.service 30" 2
"systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.timer 30" 3
"systemctlEnableAndStartNoBlock cgroup-cpu-telemetry.service 30" 4
"systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.timer 30" 5
"systemctlEnableAndStartNoBlock cgroup-pressure-telemetry.service 30" 6
End

It "exits with the telemetry error and stops setup when '$1' fails"
FAILED_TELEMETRY_COMMAND="$1"

When run enableAndStartCgroupTelemetry

The status should equal "$ERR_START_CGROUP_TELEMETRY"
The lines of output should equal "$2"
The line "$2" of output should equal "$1"
End
End

It 'exits with the telemetry error when memory service startup fails on cgroup v1'
MOCK_CGROUP_VERSION="tmpfs"
FAILED_TELEMETRY_COMMAND="systemctlEnableAndStartNoBlock cgroup-memory-telemetry.service 30"

When run enableAndStartCgroupTelemetry

The status should equal "$ERR_START_CGROUP_TELEMETRY"
The output should equal "$memory_commands"
End
End
Describe 'configureTransparentHugePageSystemdService'
setup_thp_service() {
THP_ENABLED="never"
Expand Down
2 changes: 2 additions & 0 deletions vhdbuilder/packer/cleanup-vhd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ rm -f /opt/azure/disk-usage.txt
rm -f /opt/azure/containers/image-fetcher
# Cleanup IMDS instance metadata cache file
rm -f /opt/azure/containers/imds_instance_metadata_cache.json
# Cleanup Microsoft.Azure.Extensions.CustomScript to prevent unnecessary logs/telemetry payloads being persisted on the OS disk
rm -rf /var/log/azure/Microsoft.Azure.Extensions.CustomScript
24 changes: 0 additions & 24 deletions vhdbuilder/packer/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1435,30 +1435,6 @@ fi
configureServiceExecutionTelemetryForSystemdVersion "$(systemctl --version | awk 'NR == 1 { print $2 }')" || exit $ERR_PACKER_COPY_FILE
systemctl daemon-reload

# Disable cgroup-memory-telemetry on AzureLinux due to incompatibility with cgroup2fs driver and absence of required azure.slice directory
if ! isMarinerOrAzureLinux "$OS"; then
systemctlEnableAndStart cgroup-memory-telemetry.timer 30 || exit 1
systemctl enable cgroup-memory-telemetry.service || exit 1
systemctl restart cgroup-memory-telemetry.service
fi

CGROUP_VERSION=$(stat -fc %T /sys/fs/cgroup)
if [ "$CGROUP_VERSION" = "cgroup2fs" ]; then
systemctlEnableAndStart cgroup-cpu-telemetry.timer 30 || exit 1
systemctl enable cgroup-cpu-telemetry.service || exit 1
systemctl restart cgroup-cpu-telemetry.service

systemctlEnableAndStart cgroup-pressure-telemetry.timer 30 || exit 1
systemctl enable cgroup-pressure-telemetry.service || exit 1
systemctl restart cgroup-pressure-telemetry.service
fi

if [ -d "/var/log/azure/Microsoft.Azure.Extensions.CustomScript/events/" ] && [ "$(ls -A /var/log/azure/Microsoft.Azure.Extensions.CustomScript/events/)" ]; then
cat /var/log/azure/Microsoft.Azure.Extensions.CustomScript/events/*
rm -r /var/log/azure/Microsoft.Azure.Extensions.CustomScript || exit 1
fi
capture_benchmark "${SCRIPT_NAME}_configure_telemetry"

if [ "$OS" = "$UBUNTU_OS_NAME" ]; then
# remove snapd, which is not used by container stack
apt_get_purge 20 30 120 snapd || exit 1
Expand Down
Loading