mirror of https://github.com/databricks/cli.git
incremental improvements
This commit is contained in:
parent
6492404d38
commit
5a2dcbbfc8
|
@ -7,5 +7,3 @@ Response.Body = '''
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
Response.StatusCode = 501
|
Response.StatusCode = 501
|
||||||
|
|
||||||
# TODO: Validate that this and the other tests have sane outputs.
|
|
||||||
|
|
|
@ -32,27 +32,29 @@ type UploadConfig struct {
|
||||||
Logs []protos.FrontendLog `json:"logs"`
|
Logs []protos.FrontendLog `json:"logs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The API requires the logs to be JSON encoded strings. This function reads the
|
||||||
|
// logs from stdin and returns them as a slice of JSON encoded strings.
|
||||||
func readLogs(stdin io.Reader) ([]string, error) {
|
func readLogs(stdin io.Reader) ([]string, error) {
|
||||||
b, err := io.ReadAll(stdin)
|
b, err := io.ReadAll(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read from stdin: %s\n", err)
|
return nil, fmt.Errorf("failed to read from stdin: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
in := UploadConfig{}
|
in := UploadConfig{}
|
||||||
err = json.Unmarshal(b, &in)
|
err = json.Unmarshal(b, &in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal input: %s\n", err)
|
return nil, fmt.Errorf("failed to unmarshal input: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(in.Logs) == 0 {
|
if len(in.Logs) == 0 {
|
||||||
return nil, fmt.Errorf("No logs to upload: %s\n", err)
|
return nil, fmt.Errorf("No logs to upload")
|
||||||
}
|
}
|
||||||
|
|
||||||
protoLogs := make([]string, len(in.Logs))
|
protoLogs := make([]string, len(in.Logs))
|
||||||
for i, log := range in.Logs {
|
for i, log := range in.Logs {
|
||||||
b, err := json.Marshal(log)
|
b, err := json.Marshal(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to marshal log: %s\n", err)
|
return nil, fmt.Errorf("failed to marshal log: %s", err)
|
||||||
}
|
}
|
||||||
protoLogs[i] = string(b)
|
protoLogs[i] = string(b)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,6 @@ func Upload(ctx context.Context) (*ResponseBody, error) {
|
||||||
|
|
||||||
// Only try uploading logs for a maximum of 3 times.
|
// Only try uploading logs for a maximum of 3 times.
|
||||||
for i := range 3 {
|
for i := range 3 {
|
||||||
// TODO: Confirm that the timeout of a request here is indeed one minute.
|
|
||||||
resp, err = attempt(ctx, apiClient, logs)
|
resp, err = attempt(ctx, apiClient, logs)
|
||||||
|
|
||||||
// All logs were uploaded successfully.
|
// All logs were uploaded successfully.
|
||||||
|
|
|
@ -155,7 +155,7 @@ func TestTelemetryUploadMaxRetries(t *testing.T) {
|
||||||
configureStdin(t)
|
configureStdin(t)
|
||||||
|
|
||||||
_, err := Upload(context.Background())
|
_, err := Upload(context.Background())
|
||||||
assert.EqualError(t, err, "upload did not succeed after three attempts. err: <nil>. response body: &telemetry.ResponseBody{Errors:[]telemetry.LogError(nil), NumProtoSuccess:1}")
|
assert.EqualError(t, err, "upload did not succeed after three attempts")
|
||||||
assert.Equal(t, 3, count)
|
assert.Equal(t, 3, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,3 +194,13 @@ func TestReadFiles(t *testing.T) {
|
||||||
`{"frontend_log_event_id":"2","entry":{"databricks_cli_log":{"cli_test_event":{"name":"DummyCliEnumValue2"}}}}`,
|
`{"frontend_log_event_id":"2","entry":{"databricks_cli_log":{"cli_test_event":{"name":"DummyCliEnumValue2"}}}}`,
|
||||||
}, logs)
|
}, logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadFilesWithNoLogs(t *testing.T) {
|
||||||
|
raw := `{
|
||||||
|
"logs": []
|
||||||
|
}`
|
||||||
|
|
||||||
|
r := strings.NewReader(raw)
|
||||||
|
_, err := readLogs(r)
|
||||||
|
assert.EqualError(t, err, "No logs to upload")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue