incremental improvements

This commit is contained in:
Shreyas Goenka 2025-03-02 17:31:11 +01:00
parent 6492404d38
commit 5a2dcbbfc8
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 17 additions and 8 deletions

View File

@ -7,5 +7,3 @@ Response.Body = '''
}
'''
Response.StatusCode = 501
# TODO: Validate that this and the other tests have sane outputs.

View File

@ -32,27 +32,29 @@ type UploadConfig struct {
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) {
b, err := io.ReadAll(stdin)
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{}
err = json.Unmarshal(b, &in)
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 {
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))
for i, log := range in.Logs {
b, err := json.Marshal(log)
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)
}
@ -80,7 +82,6 @@ func Upload(ctx context.Context) (*ResponseBody, error) {
// Only try uploading logs for a maximum of 3 times.
for i := range 3 {
// TODO: Confirm that the timeout of a request here is indeed one minute.
resp, err = attempt(ctx, apiClient, logs)
// All logs were uploaded successfully.

View File

@ -155,7 +155,7 @@ func TestTelemetryUploadMaxRetries(t *testing.T) {
configureStdin(t)
_, 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)
}
@ -194,3 +194,13 @@ func TestReadFiles(t *testing.T) {
`{"frontend_log_event_id":"2","entry":{"databricks_cli_log":{"cli_test_event":{"name":"DummyCliEnumValue2"}}}}`,
}, logs)
}
func TestReadFilesWithNoLogs(t *testing.T) {
raw := `{
"logs": []
}`
r := strings.NewReader(raw)
_, err := readLogs(r)
assert.EqualError(t, err, "No logs to upload")
}