From 601c8c22f5c6a742cfb6249c6a4cd67c3d8b3327 Mon Sep 17 00:00:00 2001 From: LINxiansheng Date: Sun, 4 Feb 2024 04:16:59 +0000 Subject: [PATCH] [CP] add telemetry in rpm install and systemd deploy --- .gitignore | 1 + .secignore | 1 + cmake/RPM.cmake | 4 + .../profile/oceanbase-service.sh.template | 9 +++ tools/rpm/systemd/profile/oceanbase.cnf | 9 ++- .../systemd/profile/post_install.sh.template | 4 +- .../systemd/profile/pre_uninstall.sh.template | 5 +- .../rpm/systemd/profile/telemetry.sh.template | 80 +++++++++++++++++++ 8 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 tools/rpm/systemd/profile/telemetry.sh.template diff --git a/.gitignore b/.gitignore index 0dee72ffe..67cb28874 100644 --- a/.gitignore +++ b/.gitignore @@ -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_* diff --git a/.secignore b/.secignore index d4b90b7fc..67539447d 100644 --- a/.secignore +++ b/.secignore @@ -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/ diff --git a/cmake/RPM.cmake b/cmake/RPM.cmake index 4b11c9c44..d3ccfd953 100644 --- a/cmake/RPM.cmake +++ b/cmake/RPM.cmake @@ -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() diff --git a/tools/rpm/systemd/profile/oceanbase-service.sh.template b/tools/rpm/systemd/profile/oceanbase-service.sh.template index e78513e8f..da690239b 100644 --- a/tools/rpm/systemd/profile/oceanbase-service.sh.template +++ b/tools/rpm/systemd/profile/oceanbase-service.sh.template @@ -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 diff --git a/tools/rpm/systemd/profile/oceanbase.cnf b/tools/rpm/systemd/profile/oceanbase.cnf index 1a7d696ac..372c49499 100644 --- a/tools/rpm/systemd/profile/oceanbase.cnf +++ b/tools/rpm/systemd/profile/oceanbase.cnf @@ -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 \ No newline at end of file +log_disk_size=13G +enable_syslog_wf=false +enable_syslog_recycle=true +max_syslog_file_count=4 +__min_full_resource_pool_memory=1073741824 \ No newline at end of file diff --git a/tools/rpm/systemd/profile/post_install.sh.template b/tools/rpm/systemd/profile/post_install.sh.template index 5e1aa1bd2..2661a1a6d 100644 --- a/tools/rpm/systemd/profile/post_install.sh.template +++ b/tools/rpm/systemd/profile/post_install.sh.template @@ -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 \ No newline at end of file +# telemetry +/bin/bash $prefix/profile/telemetry.sh $1 \ No newline at end of file diff --git a/tools/rpm/systemd/profile/pre_uninstall.sh.template b/tools/rpm/systemd/profile/pre_uninstall.sh.template index e1731b66d..0a56121bb 100644 --- a/tools/rpm/systemd/profile/pre_uninstall.sh.template +++ b/tools/rpm/systemd/profile/pre_uninstall.sh.template @@ -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 \ No newline at end of file +systemctl daemon-reload + +# telemetry +/bin/bash $prefix/profile/telemetry.sh $1 \ No newline at end of file diff --git a/tools/rpm/systemd/profile/telemetry.sh.template b/tools/rpm/systemd/profile/telemetry.sh.template new file mode 100644 index 000000000..500e607f7 --- /dev/null +++ b/tools/rpm/systemd/profile/telemetry.sh.template @@ -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 \ No newline at end of file