Skip to content

Commit

Permalink
setup.sh: metrics (commaai#33175)
Browse files Browse the repository at this point in the history
* save

* add sentry

* clean

* real sentry

* default

* true

* remote this
  • Loading branch information
maxime-desroches authored Aug 5, 2024
1 parent 7a7200c commit c7cf6f6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
36 changes: 32 additions & 4 deletions tools/op.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ function op_install() {
echo -e " ↳ [${GREEN}${NC}] op installed successfully. Open a new shell to use it.\n"
}

function loge() {
if [[ -f "$LOG_FILE" ]]; then
# error type
echo "$1" >> $LOG_FILE
# error log
echo "$2" >> $LOG_FILE
fi
}

function op_run_command() {
CMD="$@"
echo -e "${BOLD}Running:${NC} $CMD"
Expand Down Expand Up @@ -97,18 +106,21 @@ function op_check_os() {
;;
* )
echo -e " ↳ [${RED}${NC}] Incompatible Ubuntu version $VERSION_CODENAME detected!"
loge "ERROR_INCOMPATIBLE_UBUNTU" "$VERSION_CODENAME"
return 1
;;
esac
else
echo -e " ↳ [${RED}${NC}] No /etc/os-release on your system. Make sure you're running on Ubuntu, or similar!"
loge "ERROR_UNKNOWN_UBUNTU"
return 1
fi

elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e " ↳ [${GREEN}${NC}] macos detected.\n"
else
echo -e " ↳ [${RED}${NC}] OS type $OSTYPE not supported!"
loge "ERROR_UNKNOWN_OS" "$OSTYPE"
return 1
fi
}
Expand All @@ -120,11 +132,13 @@ function op_check_python() {

if [[ -z $INSTALLED_PYTHON_VERSION ]]; then
echo -e " ↳ [${RED}${NC}] python3 not found on your system. You need python version at least $(echo $REQUIRED_PYTHON_VERSION | tr -d -c '[0-9.]') to continue!"
loge "ERROR_PYTHON_NOT_FOUND"
return 1
elif [[ $(echo $INSTALLED_PYTHON_VERSION | grep -o '[0-9]\+\.[0-9]\+' | tr -d -c '[0-9]') -ge $(echo $REQUIRED_PYTHON_VERSION | tr -d -c '[0-9]') ]]; then
echo -e " ↳ [${GREEN}${NC}] $INSTALLED_PYTHON_VERSION detected."
else
echo -e " ↳ [${RED}${NC}] You need python version at least $(echo $REQUIRED_PYTHON_VERSION | tr -d -c '[0-9.]') to continue!"
loge "ERROR_PYTHON_VERSION" "$INSTALLED_PYTHON_VERSION"
return 1
fi
}
Expand Down Expand Up @@ -173,22 +187,35 @@ function op_setup() {
echo "Installing dependencies..."
st="$(date +%s)"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
op_run_command $OPENPILOT_ROOT/tools/ubuntu_setup.sh
SETUP_SCRIPT="tools/ubuntu_setup.sh"
elif [[ "$OSTYPE" == "darwin"* ]]; then
op_run_command $OPENPILOT_ROOT/tools/mac_setup.sh
SETUP_SCRIPT="tools/mac_setup.sh"
fi
if ! op_run_command "$OPENPILOT_ROOT/$SETUP_SCRIPT"; then
echo -e " ↳ [${RED}${NC}] Dependencies installation failed!"
loge "ERROR_DEPENDENCIES_INSTALLATION"
return 1
fi
et="$(date +%s)"
echo -e " ↳ [${GREEN}${NC}] Dependencies installed successfully in $((et - st)) seconds.\n"

echo "Getting git submodules..."
st="$(date +%s)"
op_run_command git submodule update --filter=blob:none --jobs 4 --init --recursive
if ! op_run_command git submodule update --filter=blob:none --jobs 4 --init --recursive; then
echo -e " ↳ [${RED}${NC}] Getting git submodules failed!"
loge "ERROR_GIT_SUBMODULES"
return 1
fi
et="$(date +%s)"
echo -e " ↳ [${GREEN}${NC}] Submodules installed successfully in $((et - st)) seconds.\n"

echo "Pulling git lfs files..."
st="$(date +%s)"
op_run_command git lfs pull
if ! op_run_command git lfs pull; then
echo -e " ↳ [${RED}${NC}] Pulling git lfs files failed!"
loge "ERROR_GIT_LFS"
return 1
fi
et="$(date +%s)"
echo -e " ↳ [${GREEN}${NC}] Files pulled successfully in $((et - st)) seconds.\n"

Expand Down Expand Up @@ -307,6 +334,7 @@ function _op() {
--dry ) shift 1; DRY="1" ;;
-n | --no-verify ) shift 1; NO_VERIFY="1" ;;
-v | --verbose ) shift 1; VERBOSE="1" ;;
-l | --log ) shift 1; LOG_FILE="$1" ; shift 1 ;;
esac

# parse Commands
Expand Down
50 changes: 48 additions & 2 deletions tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ cat << 'EOF'
EOF
}

function sentry_send_event() {
SENTRY_KEY=dd0cba62ba0ac07ff9f388f8f1e6a7f4
SENTRY_URL=https://sentry.io/api/4507726145781760/store/

EVENT=$1
EVENT_TYPE=${2:-$EVENT}
EVENT_LOG=${3:-"NA"}

PLATFORM=$(uname -s)
ARCH=$(uname -m)
if [[ $PLATFORM == "Darwin" ]]; then
OS="macos"
elif [[ $PLATFORM == "Linux" ]]; then
OS="linux"
fi

if [[ $ARCH == armv8* ]] || [[ $ARCH == arm64* ]] || [[ $ARCH == aarch64* ]]; then
ARCH="aarch64"
elif [[ $ARCH == "x86_64" ]] || [[ $ARCH == i686* ]]; then
ARCH="x86"
fi

PYTHON_VERSION=$(echo $(python3 --version 2> /dev/null || echo "NA"))
BRANCH=$(echo $(git -C $OPENPILOT_ROOT rev-parse --abbrev-ref HEAD 2> /dev/null || echo "NA"))
COMMIT=$(echo $(git -C $OPENPILOT_ROOT rev-parse HEAD 2> /dev/null || echo "NA"))

curl -s -o /dev/null -X POST -g --data "{ \"exception\": { \"values\": [{ \"type\": \"$EVENT\" }] }, \"tags\" : { \"event_type\" : \"$EVENT_TYPE\", \"event_log\" : \"$EVENT_LOG\", \"os\" : \"$OS\", \"arch\" : \"$ARCH\", \"python_version\" : \"$PYTHON_VERSION\" , \"git_branch\" : \"$BRANCH\", \"git_commit\" : \"$COMMIT\" } }" \
-H 'Content-Type: application/json' \
-H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=op_setup/0.1" \
$SENTRY_URL 2> /dev/null
}

function check_stdin() {
if [ -t 0 ]; then
INTERACTIVE=1
Expand Down Expand Up @@ -99,6 +131,7 @@ function check_git() {
echo "Checking for git..."
if ! command -v "git" > /dev/null 2>&1; then
echo -e " ↳ [${RED}${NC}] git not found on your system, can't continue!"
sentry_send_event "SETUP_FAILURE" "ERROR_GIT_NOT_FOUND"
return 1
else
echo -e " ↳ [${GREEN}${NC}] git found.\n"
Expand All @@ -117,13 +150,27 @@ function git_clone() {
fi

echo -e " ↳ [${RED}${NC}] failed to clone openpilot!"
sentry_send_event "SETUP_FAILURE" "ERROR_GIT_CLONE"
return 1
}

function install_with_op() {
cd $OPENPILOT_ROOT
$OPENPILOT_ROOT/tools/op.sh install
$OPENPILOT_ROOT/tools/op.sh setup || (echo -e "\n[${RED}${NC}] failed to install openpilot!" && return 1)

LOG_FILE=$(mktemp)

if ! $OPENPILOT_ROOT/tools/op.sh --log $LOG_FILE setup; then
echo -e "\n[${RED}${NC}] failed to install openpilot!"

ERROR_TYPE="$(cat "$LOG_FILE" | sed '1p;d')"
ERROR_LOG="$(cat "$LOG_FILE" | sed '2p;d')"
sentry_send_event "SETUP_FAILURE" "$ERROR_TYPE" "$ERROR_LOG" || true

return 1
else
sentry_send_event "SETUP_SUCCESS" || true
fi

echo -e "\n----------------------------------------------------------------------"
echo -e "[${GREEN}${NC}] openpilot was successfully installed into ${BOLD}$OPENPILOT_ROOT${NC}"
Expand All @@ -132,7 +179,6 @@ function install_with_op() {
}

show_motd

check_stdin
ask_dir
check_dir
Expand Down

0 comments on commit c7cf6f6

Please sign in to comment.