Skip to content

Commit

Permalink
User/hshami/client unique (#32)
Browse files Browse the repository at this point in the history
* code

* print errors from run

* use redirect output

* collect more info on e2e failures

* fg install for edge-runtime

* more logging

* desperation

* desperation - 2

* nm

* use existing sources list?

* PR feedback - pass 1

* latest PR comments

* the quiet choice
  • Loading branch information
mhshami01 committed May 28, 2021
1 parent 634c933 commit c4eaaef
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/azure-iot-edge-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ add_option_args "CORRELATION_VECTOR" -cv --correlation-vector
# parse command line inputs and fetch output from parser
declare -A parsed_cmds="$(cmd_parser $@)"

set_opt_out_selection ${parsed_cmds["TELEMETRY_OPT_OUT"]} $parsed_cmds["CORRELATION_VECTOR"]

# validate that all arguments are acceptable / known
if [[ ${#@} > 0 && ${#parsed_cmds[*]} == 0 ]];
then
Expand All @@ -131,6 +129,8 @@ then
exit ${EXIT_CODES[2]}
fi

set_opt_out_selection ${parsed_cmds["TELEMETRY_OPT_OUT"]} ${parsed_cmds["CORRELATION_VECTOR"]} ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]}

# check if current OS is Tier 1
source validate-tier1-os.sh
is_os_tier1
Expand All @@ -148,7 +148,7 @@ source install-container-management.sh
install_container_management

source install-edge-runtime.sh
install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]}
install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]}

source validate-post-install.sh
validate_post_install
Expand Down
2 changes: 1 addition & 1 deletion src/install-edge-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function install_edge_runtime() {

# create .toml from template
log_info "Create instance configuration .toml from template."
cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml &>/dev/null
cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
exit_code=$?
if [[ $exit_code != 0 ]];
then
Expand Down
63 changes: 41 additions & 22 deletions src/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare -a EXIT_CODES=(0 # success
)

CORRELATION_VECTOR=""
DEVICE_UNIQUE_ID=""

######################################
# set_opt_out_selection
Expand All @@ -44,6 +45,9 @@ CORRELATION_VECTOR=""
#
# ARGUMENTS:
# does_the_user_NOT_consent_to_sending_telemetry
# correlation vector specific to the run
# scope id
# registration id
#
# OUTPUTS:
# Write output to stdout
Expand All @@ -52,23 +56,25 @@ CORRELATION_VECTOR=""
######################################

function set_opt_out_selection() {
if [ $1 == true ];
if [[ "$LOCAL_E2E" == "1" || $1 == true ]];
then
OPT_IN=false
log_info "The user has opted out of sending usage telemetry."
else
OPT_IN=true
log_info "The user has opted in for sending usage telemetry."
fi

# handle correlation vector
if [ -z $2 ];
then
CORRELATION_VECTOR=$(generate_uuid)
else
CORRELATION_VECTOR=$2
fi
# handle correlation vector
if [ -z $2 ];
then
CORRELATION_VECTOR=$(generate_uuid)
else
CORRELATION_VECTOR=$2
fi

local ret_value=$(openssl dgst -hmac $INSTRUMENTATION_KEY <<< `echo $3$4`)
DEVICE_UNIQUE_ID=${ret_value##* }
fi
}
function get_opt_in_selection() {
Expand Down Expand Up @@ -284,15 +290,15 @@ function prepare_apt() {
sources="https://packages.microsoft.com/config/"$platform"/multiarch/prod.list"
# sources list
log_info "Adding'%s' to package sources lists." $sources
log_info "Adding '%s' to package sources lists." $sources
wget $sources -q -O /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
local exit_code=$?
if [[ $exit_code != 0 ]];
then
log_error "prepare_apt() step 1 failed with error: %d" exit_code
exit ${EXIT_CODES[4]}
fi
log_info "Added'%s' to package sources lists." $sources
log_info "Added '%s' to package sources lists." $sources
log_info "Downloading key"
local tmp_file=$(echo `mktemp -u`)
Expand All @@ -301,25 +307,25 @@ function prepare_apt() {
if [[ $exit_code != 0 ]];
then
log_error "prepare_apt() step 2 failed with error %d" exit_code
rm -f /etc/apt/sources.list.d/microsoft-prod.list &> /dev/null
rm -f /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
exit ${EXIT_CODES[5]}
fi
# unpack the key
local gpg_file=/etc/apt/trusted.gpg.d/microsoft.gpg
if [[ -f $gpg_file ]];
then
rm -f $gpg_file &> /dev/null
rm -f $gpg_file 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
fi
gpg --dearmor --output $gpg_file $tmp_file
exit_code=$?
rm -f $tmp_file &> /dev/null
rm -f $tmp_file 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
if [[ $exit_code != 0 ]];
then
log_error "prepare_apt() step 2 failed with error %d" $exit_code
rm -f /etc/apt/sources.list.d/microsoft-prod.list &> /dev/null
rm -f /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
exit ${EXIT_CODES[6]}
fi
log_info "Downloaded key"
Expand Down Expand Up @@ -364,13 +370,14 @@ function long_running_command() {
local MYPS=$(ps -a | awk '/'$BG_PROCESS_ID'/ {print $1}')
if [ "$MYPS" == "" ];
then
BG_PROCESS_ID=-1
BG_PROCESS_ACTIVE=false
break
fi
done
done
echo -en " \b"
wait $BG_PROCESS_ID
BG_PROCESS_ID=-1
fi
}
Expand Down Expand Up @@ -437,6 +444,19 @@ function handle_exit() {
log_info "Removed temporary directory files for iot-edge-installer."
fi
if [[ "$LOCAL_E2E" == "1" ]];
then
if [[ $e_code != 0 ]];
then
echo errors-file -----------------------------
cat $STDERR_REDIRECT
echo errors-file -----------------------------
fi
echo stdout-file -----------------------------
cat $STDOUT_REDIRECT
echo stdout-file -----------------------------
fi
announce_my_log_file "All logs were appended to" $OUTPUT_FILE
}
Expand Down Expand Up @@ -487,11 +507,10 @@ function generate_uuid() {
}
# Constants
InstrumentationKey="d403f627-57b8-4fb0-8001-c51b7466682d"
IngestionEndpoint="https://dc.services.visualstudio.com/v2/track"
EventName="Azure-IoT-Edge-Installer-Summary"
DeviceUniqueID="xinzedPC"
SchemaVersion="1.0"
INSTRUMENTATION_KEY="d403f627-57b8-4fb0-8001-c51b7466682d"
INGESTION_POINT="https://dc.services.visualstudio.com/v2/track"
TELEMETRY_EVENT_NAME="Azure-IoT-Edge-Installer-Summary"
TELEMETRY_SCHEMA_VERSION="1.0"
######################################
# send_appinsight_event_telemetry
Expand Down Expand Up @@ -520,7 +539,7 @@ function send_appinsight_event_telemetry ()
log_info "Ready to send telemetry to AppInsights endpoint with wget"
local CurrentTime=$(echo `date --utc '+%Y-%m-%dT%H:%M:%S.%N'`)
wget --header='Content-Type: application/json' --header='Accept-Charset: UTF-8' --post-data '{"name":"Microsoft.ApplicationInsights.'$InstrumentationKey'.Event","time": "'$CurrentTime'","iKey": "'$InstrumentationKey'","tags":{"ai.cloud.roleInstance": "'$DeviceUniqueID'"},"data":{"baseType": "EventData","baseData": {"ver": "'$SchemaVersion'","name": "'$EventName'","cv": "'$CORRELATION_VECTOR'","properties":{'$customPropertiesObj'},"measurements":{'$customMeasurementsObj'}}}}' $IngestionEndpoint 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
wget --header='Content-Type: application/json' --header='Accept-Charset: UTF-8' --post-data '{"name":"Microsoft.ApplicationInsights.'$INSTRUMENTATION_KEY'.Event","time": "'$CurrentTime'","iKey": "'$INSTRUMENTATION_KEY'","tags":{"ai.cloud.roleInstance": "'$DEVICE_UNIQUE_ID'"},"data":{"baseType": "EventData","baseData": {"ver": "'$TELEMETRY_SCHEMA_VERSION'","name": "'$TELEMETRY_EVENT_NAME'","cv": "'$CORRELATION_VECTOR'","properties":{'$customPropertiesObj'},"measurements":{'$customMeasurementsObj'}}}}' $INGESTION_POINT 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT
log_info "Finished sending telemetry to AppInsights endpoint with wget"
fi
Expand Down
6 changes: 3 additions & 3 deletions vsts_ci/azure-pipelines-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stages:
- job: SetupScript
steps:
- script: |
sudo apt update
sudo apt install jq
sudo apt-get update
sudo apt-get install jq
displayName: 'Install jq'
- task: AzureCLI@2
inputs:
Expand All @@ -30,7 +30,7 @@ stages:
az --version
az account set -s $(AzureSubscriptionId)
displayName: 'Set Azure resources'

- job: LinuxE2ETests
pool:
vmImage: ubuntu-18.04
Expand Down

0 comments on commit c4eaaef

Please sign in to comment.