-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async logger for telemetry #2278
base: main
Are you sure you want to change the base?
Changes from 54 commits
ab10720
3964d8d
01d63dd
155fe7b
acd64fa
ee3568c
8f8463f
f092e21
5d75c3f
427c755
b83e576
f09a780
90148d8
259a21a
e4a1f42
d7bf1dc
382efe4
c412eb7
da0cf95
8801587
5385faf
c1a3225
4f97900
a8b366e
5c2205a
dc0ab30
2cd25e3
2cbc39f
f3e7594
403f612
0423b09
981dbf7
918af62
39ff290
33ff865
17698a5
5b6ffd5
963022a
9e2a689
0abba86
407e9e0
414a94d
d5e03f0
8c90ad0
1bb4537
c9ebc82
fd6b129
73fac82
5e2e03a
0253039
369faff
e43a0a0
f88db77
a6e8e92
23b42e9
9d65761
c8ac08c
58bf931
79fad7a
4cdcbd6
f98369d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
wait_file() { | ||
local file_path="$1" | ||
local max_attempts=100 | ||
local attempt=0 | ||
|
||
while [ $attempt -lt $max_attempts ]; do | ||
if [ -e "$file_path" ]; then | ||
echo "File $file_path exists" | ||
return 0 | ||
fi | ||
sleep 0.1 | ||
attempt=$((attempt + 1)) | ||
done | ||
|
||
echo "Timeout: File $file_path did not appear within 10 seconds" | ||
return 1 | ||
} | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 <file_path>" | ||
exit 1 | ||
fi | ||
|
||
wait_file "$1" | ||
exit $? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
|
||
# wait <pid> in bash only works for processes that are direct children to the calling | ||
# shell. This script is more general purpose. | ||
wait_pid() { | ||
local pid=$1 | ||
local max_attempts=100 # 100 * 0.1 seconds = 10 seconds | ||
local attempt=0 | ||
local sleep_time=0.1 | ||
|
||
while [ $attempt -lt $max_attempts ]; do | ||
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then | ||
# Windows approach | ||
if ! tasklist | grep -q $pid; then | ||
echo "Process has ended" | ||
return 0 | ||
fi | ||
else | ||
# Linux/macOS approach | ||
if ! kill -0 $pid 2>/dev/null; then | ||
echo "Process has ended" | ||
return 0 | ||
fi | ||
fi | ||
|
||
sleep $sleep_time | ||
attempt=$((attempt + 1)) | ||
done | ||
|
||
echo "Timeout: Process $pid did not end within 10 seconds" | ||
return 1 | ||
} | ||
|
||
# Usage | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 <PID>" | ||
exit 1 | ||
fi | ||
|
||
wait_pid $1 | ||
exit $? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"method":"POST","path":"/telemetry-ext","body":{"uploadTime":"UNIX_TIME_MILLIS","items":[],"protoLogs":["{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[UUID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"telemetry_dummy\",\"operating_system\":\"OS\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"cli_test_event\":{\"name\":\"VALUE1\"}}}}","{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[UUID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"telemetry_dummy\",\"operating_system\":\"OS\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"cli_test_event\":{\"name\":\"VALUE2\"}}}}"]}} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: Failed to upload telemetry logs: Endpoint not implemented. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
>>> [CLI] telemetry dummy | ||
waiting for telemetry process to finish | ||
File ./telemetry.pid exists | ||
Process has ended |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid | ||
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload.txt | ||
|
||
# This test ensures that the main CLI command does not error even if | ||
# telemetry upload fails. | ||
trace $CLI telemetry dummy | ||
|
||
echo "waiting for telemetry process to finish" | ||
|
||
# Wait for the child telemetry process to finish | ||
wait_file ./telemetry.pid | ||
wait_pid $(cat ./telemetry.pid) | ||
|
||
# cleanup the pid file | ||
rm -f ./telemetry.pid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
LocalOnly = true | ||
RecordRequests = true | ||
|
||
[[Server]] | ||
Pattern = "POST /telemetry-ext" | ||
Response.Body = ''' | ||
{ | ||
"error_code": "ERROR_CODE", | ||
"message": "Endpoint not implemented." | ||
} | ||
''' | ||
Response.StatusCode = 501 | ||
|
||
[[Repls]] | ||
Old = '17\d{11}' | ||
New = '"UNIX_TIME_MILLIS"' | ||
|
||
[[Repls]] | ||
Old = 'execution_time_ms\\\":\d{1,5},' | ||
New = 'execution_time_ms\":\"SMALL_INT\",' | ||
|
||
[[Repls]] | ||
Old = 'darwin|linux|windows' | ||
New = 'OS' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"method":"POST","path":"/telemetry-ext","body":{"uploadTime":"UNIX_TIME_MILLIS","items":[],"protoLogs":["{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[UUID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"telemetry_dummy\",\"operating_system\":\"OS\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"cli_test_event\":{\"name\":\"VALUE1\"}}}}","{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[UUID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"telemetry_dummy\",\"operating_system\":\"OS\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"cli_test_event\":{\"name\":\"VALUE2\"}}}}"]}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Telemetry logs uploaded successfully | ||
Response: | ||
{"errors":null,"numProtoSuccess":2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
>>> [CLI] telemetry dummy | ||
waiting for telemetry process to finish | ||
File ./telemetry.pid exists | ||
Process has ended |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid | ||
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload.txt | ||
|
||
trace $CLI telemetry dummy | ||
|
||
echo "waiting for telemetry process to finish" | ||
|
||
# Wait for the child telemetry process to finish | ||
wait_file ./telemetry.pid | ||
wait_pid $(cat ./telemetry.pid) | ||
|
||
# cleanup the pid file | ||
rm -f ./telemetry.pid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
LocalOnly = true | ||
RecordRequests = true | ||
|
||
[[Server]] | ||
Pattern = "POST /telemetry-ext" | ||
Response.Body = ''' | ||
{ | ||
"numProtoSuccess": 2 | ||
} | ||
''' | ||
|
||
[[Repls]] | ||
Old = '17\d{11}' | ||
New = '"UNIX_TIME_MILLIS"' | ||
|
||
[[Repls]] | ||
Old = 'execution_time_ms\\\":\d{1,5},' | ||
New = 'execution_time_ms\":\"SMALL_INT\",' | ||
|
||
[[Repls]] | ||
Old = 'darwin|linux|windows' | ||
New = 'OS' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"method":"POST","path":"/telemetry-ext","body":{"uploadTime":"UNIX_TIME_MILLIS","items":[],"protoLogs":["{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"cli_test_event\":{\"name\":\"VALUE1\"}}}}","{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"cli_test_event\":{\"name\":\"VALUE2\"}}}}"]}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR, but this prompted me to check if we can pretty print it but keep storing it without the outside array -- it seems that it works fine with jq:
So maybe you could do a separate PR to adopt this format? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll send a followup PR after this is merged There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The output requests log file is only written after the script is generated. Maybe we need to introduce some new hook to make it work? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Telemetry logs uploaded successfully | ||
Response: | ||
{"errors":null,"numProtoSuccess":2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
>>> [CLI] telemetry upload |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload.txt | ||
|
||
# This command / test cannot be run in inprocess / debug mode. This is because | ||
# it does not go through the [root.Execute] function. | ||
trace $CLI telemetry upload < stdin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"logs": [ | ||
{ | ||
"frontend_log_event_id": "BB79BB52-96F6-42C5-9E44-E63EEA84888D", | ||
"entry": { | ||
"databricks_cli_log": { | ||
"cli_test_event": { | ||
"name": "VALUE1" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"frontend_log_event_id": "A7F597B0-66D1-462D-824C-C5C706F232E8", | ||
"entry": { | ||
"databricks_cli_log": { | ||
"cli_test_event": { | ||
"name": "VALUE2" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
LocalOnly = true | ||
RecordRequests = true | ||
|
||
[[Server]] | ||
Pattern = "POST /telemetry-ext" | ||
Response.Body = ''' | ||
{ | ||
"numProtoSuccess": 2 | ||
} | ||
''' | ||
|
||
|
||
[[Repls]] | ||
Old = '17\d{11}' | ||
New = '"UNIX_TIME_MILLIS"' | ||
|
||
[[Repls]] | ||
Old = 'darwin|linux|windows' | ||
New = 'OS' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2329 will make this easier to review.