add skip functionality

This commit is contained in:
Shreyas Goenka 2025-02-18 16:47:47 +01:00
parent a98993abfc
commit 3cfeb640e1
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
11 changed files with 41 additions and 2 deletions

View File

@ -1,5 +1,5 @@
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload.txt
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload_process.txt
# This test ensures that the main CLI command does not error even if
# telemetry upload fails.

View File

@ -0,0 +1,3 @@
>>> [CLI] selftest send-telemetry
telemetry process not started. No pid file found

View File

@ -0,0 +1,12 @@
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload_process.txt
export DATABRICKS_CLI_DISABLE_TELEMETRY="true"
trace $CLI selftest send-telemetry
if [ -f ./telemetry.pid ]; then
echo "telemetry process was started"
exit 1
else
echo "telemetry process not started. No pid file found"
fi

View File

@ -0,0 +1,11 @@
[[Server]]
Pattern = "POST /telemetry-ext"
Response.Body = '''
{
"numProtoSuccess": 2
}
'''
[[Repls]]
Old = 'execution_time_ms\\\":\d{1,5},'
New = 'execution_time_ms\":\"SMALL_INT\",'

View File

@ -1,5 +1,5 @@
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.send_telemetry.txt
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload_process.txt
trace $CLI selftest send-telemetry

View File

@ -181,6 +181,11 @@ func uploadTelemetry(ctx context.Context, cmdStr string, start, end time.Time, e
return
}
// Telemetry is disabled. We don't upload logs.
if _, ok := os.LookupEnv(telemetry.DisableEnvVar); ok {
return
}
telemetry.SetExecutionContext(ctx, protos.ExecutionContext{
CmdExecID: cmdExecId,
Version: build.GetInfo().Version,

View File

@ -21,6 +21,10 @@ const (
// File containing the PID of the telemetry upload process.
PidFileEnvVar = "DATABRICKS_CLI_TELEMETRY_PID_FILE"
// Environment variable to disable telemetry. If this is set to any value, telemetry
// will be disabled.
DisableEnvVar = "DATABRICKS_CLI_DISABLE_TELEMETRY"
)
type UploadConfig struct {

View File

@ -14,6 +14,10 @@ import (
"github.com/stretchr/testify/require"
)
// TODO: Add flag to allow skipping telemetry.
// TODO: Add verification that the telemetry process uses the correct authentication
// credentials.
func TestTelemetryUploadRetries(t *testing.T) {
server := testserver.New(t)
t.Cleanup(server.Close)