[CP] add telemetry in rpm install and systemd deploy

This commit is contained in:
LINxiansheng 2024-02-10 08:16:20 +00:00 committed by ob-robot
parent 7fa5678400
commit 165f30cbfd
8 changed files with 109 additions and 4 deletions

1
.gitignore vendored
View File

@ -293,6 +293,7 @@ tools/rpm/systemd/profile/oceanbase-service.sh
tools/rpm/systemd/profile/post_install.sh
tools/rpm/systemd/profile/pre_uninstall.sh
tools/rpm/systemd/profile/post_uninstall.sh
tools/rpm/systemd/profile/telemetry.sh
############# unittest #############
unittest/**/test_*

View File

@ -195,6 +195,7 @@
https://github.com/lz4/lz4
https://www.contributor-covenant.org/*
https://github.com/oceanbase/*
https://openwebapi.oceanbase.com*
**/Doxyfile
www.doxygen.org)
https://www.gnu.org/software/libiconv/

View File

@ -67,6 +67,9 @@ if (OB_BUILD_OPENSOURCE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/oceanbase-service.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/oceanbase-service.sh
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/telemetry.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/telemetry.sh
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_install.sh.template
${CMAKE_CURRENT_SOURCE_DIR}/tools/rpm/systemd/profile/post_install.sh
@ -140,6 +143,7 @@ install(FILES
tools/rpm/systemd/profile/post_install.sh
tools/rpm/systemd/profile/post_uninstall.sh
tools/rpm/systemd/profile/pre_uninstall.sh
tools/rpm/systemd/profile/telemetry.sh
DESTINATION profile
COMPONENT server)
endif()

View File

@ -7,6 +7,7 @@ url="http://$ip:$port"
unix_socket="/tmp/obshell/$port.sock"
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
obshell="$prefix/bin/obshell"
report=3
function prepare_config_json {
cnf_file='/etc/oceanbase.cnf'
@ -190,6 +191,9 @@ function start_observer {
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 20 6
if [ $? -eq 0 ]; then
/bin/bash $prefix/profile/telemetry.sh $report "12"
fi
elif [ "x$identity" = "xSINGLE" ]; then
# do config observer first
do_config_observer
@ -202,6 +206,9 @@ function start_observer {
fi
trace=$(echo "$response" | jq -r '.data.id')
check_trace $trace "start observer" 40 6
if [ $? -eq 0 ]; then
/bin/bash $prefix/profile/telemetry.sh $report "11"
fi
else
# status is UNIDENTIFIED
echo "The observer has been installed before"
@ -270,6 +277,8 @@ function reload_observer {
if [ "x$1" = "xstart" ]; then
echo "oceanbase service started at ${DATE}"
# telemetry
/bin/bash $prefix/profile/telemetry.sh $report "10"
if check_daemon_process; then
echo "The agent service is exist"
else

View File

@ -1,9 +1,16 @@
mysqlPort=2881
rpcPort=2882
rootPwd=""
redoDir=/var/lib/oceanbase/redo
dataDir=/var/lib/oceanbase/data
datafile_size=2G
datafile_next=2G
datafile_maxsize=20G
cpu_count=16
memory_limit=6G
system_memory=1G
log_disk_size=13G
log_disk_size=13G
enable_syslog_wf=false
enable_syslog_recycle=true
max_syslog_file_count=4
__min_full_resource_pool_memory=1073741824

View File

@ -10,5 +10,5 @@ chmod +x $prefix/profile/oceanbase-service.sh
cp -f $prefix/profile/oceanbase.cnf /etc/oceanbase.cnf
systemctl daemon-reload
# deploy local observer
/bin/bash $prefix/profile/oceanbase-service.sh deploy
# telemetry
/bin/bash $prefix/profile/telemetry.sh $1

View File

@ -8,4 +8,7 @@ systemctl stop oceanbase
systemctl disable oceanbase
/bin/bash $prefix/profile/oceanbase-service.sh destroy
rm -f /etc/systemd/system/oceanbase.service /etc/oceanbase.cnf
systemctl daemon-reload
systemctl daemon-reload
# telemetry
/bin/bash $prefix/profile/telemetry.sh $1

View File

@ -0,0 +1,80 @@
#!/bin/bash
url="https://openwebapi.oceanbase.com/api/web/oceanbase/report"
type=@CPACK_PACKAGE_NAME@
version=@CPACK_PACKAGE_VERSION@
release=@CPACK_RPM_PACKAGE_RELEASE@
ip=($hostname -i)
hostHash=$(echo -n "$ip" | sha1sum | awk '{print $1}')
cnf_file='/etc/oceanbase.cnf'
step='none'
reporter='none'
jsonData=$(jq -n --arg reporter "$reporter" \
--arg type "$type" \
--arg step "$step" \
--arg version "$version" \
--arg release "$revision" \
--arg hostHash "$hostHash" '{
component: "ocs",
content: {
reporter: $reporter,
type: $type,
step: $step,
version: $version,
release: $release,
hostHash: $hostHash,
observerConfig: {}
}
}')
function add_observer_config {
while IFS='=' read -r key value; do
key=$(echo "$key" | awk '{$1=$1};1')
value=$(echo "$value" | awk '{$1=$1};1')
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
if [[ -n "$key" && ! "$key" =~ ^\; && $key != *"rootPwd"* ]]; then
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg child "observerConfig" --arg key "$key" --arg value "$value" '.[$parent][$child][$key] = $value')
fi
done < "$cnf_file"
}
# Function Name: do_telemetry
# Purpose: prepare the telemetry json data
# Arguments: arg1 - 0 means rpm uninstall, 1 means rpm install, 2 means rpm upgrade, 3 means systemd deploy
# Arguments: arg2 - systemd step: 10 means only start, 11 means start successfully with bootstrap,
# 12 means start successfully without bootstrap
# Return Value: None
function do_telemetry {
# arg1 0 means rpm uninstall, 1 means rpm install, 2 means rpm upgrade, 3 means systemd deploy
# arg2 means systemd step
if [ "$1" -eq 0 ]; then
# rpm uninstall step
step="0"
reporter="rpm"
elif [ "$1" -eq 1 ]; then
# rpm install step
step="1"
reporter="rpm"
elif [ "$1" -eq 2 ]; then
# rpm upgrade step
step="2"
reporter="rpm"
add_observer_config
elif [ "$1" -eq 3 ]; then
step="$2"
reporter="systemd"
add_observer_config
fi
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg key "reporter" --arg value "$reporter" '.[$parent][$key] = $value')
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg key "step" --arg value "$step" '.[$parent][$key] = $value')
nohup curl -X POST \
-H "Content-Type: application/json" \
-d "$jsonData" "$url" >/dev/null 2>&1 &
}
if [[ -z "$TELEMETRY_MODE" ]] || ( [[ "$TELEMETRY_MODE" =~ ^-?[0-9]+$ ]] && [[ "$TELEMETRY_MODE" -eq 1 ]] ); then
do_telemetry $1 "$2"
fi