oras-project / oras

OCI registry client - managing content like artifacts, images, packages
https://oras.land
Apache License 2.0
1.52k stars 181 forks source link

feat: improve the format of --debug logs #1559

Open Wwwsylvia opened 19 hours ago

Wwwsylvia commented 19 hours ago

What this PR does / why we need it:

  1. Add a full timestamp to each log entry
  2. Include the response body in logs, if applicable
  3. Make the logs more readable

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged): Fixes #1535

This PR is still WIP. Pending items:

Please check the following list:

codecov[bot] commented 19 hours ago

Codecov Report

Attention: Patch coverage is 90.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.07%. Comparing base (2703462) to head (38e30fd).

Files with missing lines Patch % Lines
internal/trace/text_formatter.go 64.28% 4 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1559 +/- ## ========================================== + Coverage 84.02% 84.07% +0.04% ========================================== Files 119 120 +1 Lines 5315 5361 +46 ========================================== + Hits 4466 4507 +41 - Misses 602 606 +4 - Partials 247 248 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Wwwsylvia commented 24 minutes ago

Examples

BEFORE

Logs of oras repo ls localhost:7000 -d in TTY mode:

DEBU[0000] Request #0
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "User-Agent": "oras/1.2.0"
DEBU[0000] Response #0
< Response Status: "401 Unauthorized"
< Response headers:
   "Www-Authenticate": "Basic realm=\"Authorization Required\""
   "Date": "Wed, 04 Dec 2024 07:58:55 GMT"
   "Content-Length": "253"
   "Content-Type": "application/json"
DEBU[0000] Request #1
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "Authorization": "*****"
   "User-Agent": "oras/1.2.0"
DEBU[0000] Response #1
< Response Status: "200 OK"
< Response headers:
   "Content-Type": "application/json"
   "Date": "Wed, 04 Dec 2024 07:58:56 GMT"
   "Content-Length": "931"
   "Access-Control-Allow-Credentials": "true"
   "Access-Control-Allow-Headers": "Authorization,content-type,X-ZOT-API-CLIENT"
   "Access-Control-Allow-Methods": "GET,OPTIONS"
   "Access-Control-Allow-Origin": "*"

Logs of oras repo ls localhost:7000 -d in non-TTY mode:

time=2024-12-04T07:54:36Z level=debug msg=Request #0
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "User-Agent": "oras/1.2.0"
time=2024-12-04T07:54:36Z level=debug msg=Response #0
< Response Status: "401 Unauthorized"
< Response headers:
   "Date": "Wed, 04 Dec 2024 07:54:36 GMT"
   "Content-Length": "253"
   "Content-Type": "application/json"
   "Www-Authenticate": "Basic realm=\"Authorization Required\""
time=2024-12-04T07:54:36Z level=debug msg=Request #1
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "Authorization": "*****"
   "User-Agent": "oras/1.2.0"
time=2024-12-04T07:54:37Z level=debug msg=Response #1
< Response Status: "200 OK"
< Response headers:
   "Access-Control-Allow-Headers": "Authorization,content-type,X-ZOT-API-CLIENT"
   "Access-Control-Allow-Methods": "GET,OPTIONS"
   "Access-Control-Allow-Origin": "*"
   "Content-Type": "application/json"
   "Date": "Wed, 04 Dec 2024 07:54:37 GMT"
   "Content-Length": "931"
   "Access-Control-Allow-Credentials": "true"

AFTER

Logs of oras repo ls localhost:7000 -d in both TTY and non-TTY mode:

[2024-12-04T08:01:24.471325738Z][DEBUG]: --> Request #0
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "User-Agent": "oras/1.2.0+unreleased"

[2024-12-04T08:01:24.493880792Z][DEBUG]: <-- Response #0
< Response Status: "401 Unauthorized"
< Response headers:
   "Content-Length": "253"
   "Content-Type": "application/json"
   "Www-Authenticate": "Basic realm=\"Authorization Required\""
   "Date": "Wed, 04 Dec 2024 08:01:24 GMT"
< Response body:
{"code":"UNAUTHORIZED","message":"authentication required","detail":{"description":"The access controller was unable to authenticate the client. Often this will be accompanied by a WWW-Authenticate HTTP response header indicating how to authenticate."}}

[2024-12-04T08:01:24.643566125Z][DEBUG]: --> Request #1
> Request URL: "http://localhost:7000/v2/_catalog"
> Request method: "GET"
> Request headers:
   "Authorization": "*****"
   "User-Agent": "oras/1.2.0+unreleased"

[2024-12-04T08:01:25.415100341Z][DEBUG]: <-- Response #1
< Response Status: "200 OK"
< Response headers:
   "Access-Control-Allow-Headers": "Authorization,content-type,X-ZOT-API-CLIENT"
   "Access-Control-Allow-Methods": "GET,OPTIONS"
   "Access-Control-Allow-Origin": "*"
   "Content-Type": "application/json"
   "Date": "Wed, 04 Dec 2024 08:01:25 GMT"
   "Content-Length": "931"
   "Access-Control-Allow-Credentials": "true"
< Response body:
{"repositories":["command/artifacts","command/blob/push/1733206914/invalid-stdin-digest","command/blob/push/1733206914/invalid-stdin-size","command/blob/push/1733206915/invalid-stdin-digest","command/blob/push/1733206915/invalid-stdin-size","command/blob/push/1733207040/invalid-stdin-digest","command/blob/push/1733207040/invalid-stdin-size","command/blob/push/1733207128/invalid-stdin-digest","command/blob/push/1733207128/invalid-stdin-size","command/blob/push/1733207328/invalid-stdin-digest","command/blob/push/1733207328/invalid-stdin-size","command/blob/push/1733207364/invalid-stdin-digest","command/blob/push/1733207364/invalid-stdin-size","command/blob/push/1733207584/invalid-stdin-digest","command/blob/push/1733207584/invalid-stdin-size","command/images","command/manifest/delete/1733197330/descriptor-without-confirm","command/manifest/delete/1733197330/no-confirm","command/manifest/delete/1733197330/no-reference"]}