diff --git a/acceptance/telemetry/upload-fails/test.toml b/acceptance/telemetry/upload-fails/test.toml index e6ac68bd2..a7fa942e4 100644 --- a/acceptance/telemetry/upload-fails/test.toml +++ b/acceptance/telemetry/upload-fails/test.toml @@ -7,5 +7,3 @@ Response.Body = ''' } ''' Response.StatusCode = 501 - -# TODO: Validate that this and the other tests have sane outputs. diff --git a/libs/telemetry/upload.go b/libs/telemetry/upload.go index 44f02a64b..4a74ec029 100644 --- a/libs/telemetry/upload.go +++ b/libs/telemetry/upload.go @@ -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. diff --git a/libs/telemetry/upload_test.go b/libs/telemetry/upload_test.go index 6560fbb4c..76a4b807e 100644 --- a/libs/telemetry/upload_test.go +++ b/libs/telemetry/upload_test.go @@ -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: . 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") +}