better debug logs

This commit is contained in:
Shreyas Goenka 2025-03-02 17:36:10 +01:00
parent 30a582a5e3
commit efdb977470
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 8 additions and 23 deletions

View File

@ -1,10 +1,4 @@
attempt 0: Attempt 0 failed due to a server side error. Retrying status code: 501
err: Endpoint not implemented. Attempt 1 failed due to a server side error. Retrying status code: 501
response body: (*telemetry.ResponseBody)(nil) Attempt 2 failed due to a server side error. Retrying status code: 501
attempt 1:
err: Endpoint not implemented.
response body: (*telemetry.ResponseBody)(nil)
attempt 2:
err: Endpoint not implemented.
response body: (*telemetry.ResponseBody)(nil)
error: upload did not succeed after three attempts error: upload did not succeed after three attempts

View File

@ -1,10 +1,4 @@
attempt 0: Attempt 0 was a partial success. Number of logs uploaded: 1 out of 2
err: %!s(<nil>) Attempt 1 was a partial success. Number of logs uploaded: 1 out of 2
response body: &telemetry.ResponseBody{Errors:[]telemetry.LogError{}, NumProtoSuccess:1} Attempt 2 was a partial success. Number of logs uploaded: 1 out of 2
attempt 1:
err: %!s(<nil>)
response body: &telemetry.ResponseBody{Errors:[]telemetry.LogError{}, NumProtoSuccess:1}
attempt 2:
err: %!s(<nil>)
response body: &telemetry.ResponseBody{Errors:[]telemetry.LogError{}, NumProtoSuccess:1}
error: upload did not succeed after three attempts error: upload did not succeed after three attempts

View File

@ -89,13 +89,9 @@ func Upload(ctx context.Context) (*ResponseBody, error) {
return resp, nil return resp, nil
} }
// Log API output if the upload failed for debugging purposes.
fmt.Fprintf(os.Stderr, "attempt %d:\n", i)
fmt.Fprintf(os.Stderr, "err: %s\n", err)
fmt.Fprintf(os.Stderr, "response body: %#v\n", resp)
// Partial success. Retry. // Partial success. Retry.
if err == nil && resp.NumProtoSuccess < int64(len(logs)) { if err == nil && resp.NumProtoSuccess < int64(len(logs)) {
fmt.Fprintf(os.Stderr, "Attempt %d was a partial success. Number of logs uploaded: %d out of %d\n", i, resp.NumProtoSuccess, len(logs))
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
continue continue
} }
@ -105,6 +101,7 @@ func Upload(ctx context.Context) (*ResponseBody, error) {
// ref: https://github.com/databricks/databricks-sdk-go/blob/cdb28002afacb8b762348534a4c4040a9f19c24b/apierr/errors.go#L91 // ref: https://github.com/databricks/databricks-sdk-go/blob/cdb28002afacb8b762348534a4c4040a9f19c24b/apierr/errors.go#L91
var apiErr *apierr.APIError var apiErr *apierr.APIError
if errors.As(err, &apiErr) && apiErr.StatusCode >= 500 && apiErr.StatusCode != 503 { if errors.As(err, &apiErr) && apiErr.StatusCode >= 500 && apiErr.StatusCode != 503 {
fmt.Fprintf(os.Stderr, "Attempt %d failed due to a server side error. Retrying status code: %d\n", i, apiErr.StatusCode)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
continue continue
} }