mirror of https://github.com/databricks/cli.git
add test for timeout
This commit is contained in:
parent
f11f5895ff
commit
0d37654735
|
@ -0,0 +1,12 @@
|
||||||
|
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid
|
||||||
|
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload_process.txt
|
||||||
|
|
||||||
|
trace $CLI selftest send-telemetry
|
||||||
|
|
||||||
|
echo "waiting for telemetry process to finish"
|
||||||
|
|
||||||
|
# Wait for the child telemetry process to finish
|
||||||
|
wait_pid $(cat ./telemetry.pid)
|
||||||
|
|
||||||
|
# cleanup the pid file
|
||||||
|
rm -f ./telemetry.pid
|
|
@ -0,0 +1 @@
|
||||||
|
error: Failed to flush telemetry log due to timeout
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
>>> [CLI] selftest send-telemetry
|
||||||
|
waiting for telemetry process to finish
|
||||||
|
[wait_pid] process has ended
|
|
@ -0,0 +1,16 @@
|
||||||
|
export DATABRICKS_CLI_TELEMETRY_PID_FILE=./telemetry.pid
|
||||||
|
export DATABRICKS_CLI_TELEMETRY_UPLOAD_LOGS_FILE=./out.upload_process.txt
|
||||||
|
|
||||||
|
# Configure a timeout of 0 seconds. This ensures that the timeout is respected and the
|
||||||
|
# telemetry process does not try to upload logs.
|
||||||
|
export DATABRICKS_CLI_TELEMETRY_UPLOAD_TIMEOUT="0s"
|
||||||
|
|
||||||
|
trace $CLI selftest send-telemetry
|
||||||
|
|
||||||
|
echo "waiting for telemetry process to finish"
|
||||||
|
|
||||||
|
# Wait for the child telemetry process to finish
|
||||||
|
wait_pid $(cat ./telemetry.pid)
|
||||||
|
|
||||||
|
# cleanup the pid file
|
||||||
|
rm -f ./telemetry.pid
|
|
@ -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\",'
|
|
@ -186,8 +186,7 @@ func workspaceClientOrPrompt(ctx context.Context, cfg *config.Config, allowPromp
|
||||||
return w, err
|
return w, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make upload with oauth work.
|
// TODO: Run as integration tests?
|
||||||
// TODO: Move env var inheritance to the daemon library.
|
|
||||||
func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
|
func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
|
||||||
cfg := &config.Config{}
|
cfg := &config.Config{}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ func flagErrorFunc(c *cobra.Command, err error) error {
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute(ctx context.Context, cmd *cobra.Command) error {
|
func Execute(ctx context.Context, cmd *cobra.Command) error {
|
||||||
|
// TODO: deferred panic recovery
|
||||||
ctx = telemetry.WithNewLogger(ctx)
|
ctx = telemetry.WithNewLogger(ctx)
|
||||||
ctx = dbr.DetectRuntime(ctx)
|
ctx = dbr.DetectRuntime(ctx)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
|
@ -25,6 +25,9 @@ const (
|
||||||
// Environment variable to disable telemetry. If this is set to any value, telemetry
|
// Environment variable to disable telemetry. If this is set to any value, telemetry
|
||||||
// will be disabled.
|
// will be disabled.
|
||||||
DisableEnvVar = "DATABRICKS_CLI_DISABLE_TELEMETRY"
|
DisableEnvVar = "DATABRICKS_CLI_DISABLE_TELEMETRY"
|
||||||
|
|
||||||
|
// Max time to try and upload the telemetry logs. Useful for testing.
|
||||||
|
UploadTimeout = "DATABRICKS_CLI_TELEMETRY_UPLOAD_TIMEOUT"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UploadConfig struct {
|
type UploadConfig struct {
|
||||||
|
@ -68,8 +71,16 @@ func Upload() (*ResponseBody, error) {
|
||||||
return nil, fmt.Errorf("Failed to create API client: %s\n", err)
|
return nil, fmt.Errorf("Failed to create API client: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxUploadTime := 30 * time.Second
|
||||||
|
if v, ok := os.LookupEnv(UploadTimeout); ok {
|
||||||
|
maxUploadTime, err = time.ParseDuration(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to parse time limit %s: %s\n", UploadTimeout, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set a maximum total time to try telemetry uploads.
|
// Set a maximum total time to try telemetry uploads.
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), maxUploadTime)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp := &ResponseBody{}
|
resp := &ResponseBody{}
|
||||||
|
|
Loading…
Reference in New Issue