upbound / up

The @upbound CLI
Apache License 2.0
52 stars 41 forks source link

Add repeatable --debug (short -d) enabling API request logging #339

Closed sttts closed 1 year ago

sttts commented 1 year ago

We had 3 cases (to my knowledge in Slack) internally recently where up didn't behave well and it was hard to debug the case. This output is inspired by kubectl --v=9, printing all http requests and a curl command for further trial and error.

Side-effect: this is better than API documentation that nobody reads.

In contrast to kubectl, we use -v for version. Hence, --debug, DEBUG or -d.


$ go run ./cmd/up controlplane -a upbound list -d -d
I0628 14:45:09.624049   48350 round_trippers.go:466] curl -v -XGET  -H "User-Agent: up-cli" -H "Cookie: SID=eyJhbG..." 'https://api.upbound.io/v1/controlPlanes/upbound?size=100'
I0628 14:45:09.661393   48350 round_trippers.go:495] HTTP Trace: DNS Lookup for api.upbound.io resolved to [{34.107.172.99 }]
I0628 14:45:09.671660   48350 round_trippers.go:510] HTTP Trace: Dial to tcp:34.107.172.99:443 succeed
I0628 14:45:10.001813   48350 round_trippers.go:553] GET https://api.upbound.io/v1/controlPlanes/upbound?size=100 200 OK in 377 milliseconds
I0628 14:45:10.001889   48350 round_trippers.go:570] HTTP Statistics: DNSLookup 37 ms Dial 10 ms TLSHandshake 19 ms ServerProcessing 310 ms Duration 377 ms
I0628 14:45:10.001911   48350 round_trippers.go:577] Response Headers:
I0628 14:45:10.001936   48350 round_trippers.go:580]     X-Request-Id: daa528bf-83c0-4a99-8dba-9ba90bd27bb7
I0628 14:45:10.001955   48350 round_trippers.go:580]     Date: Wed, 28 Jun 2023 12:45:09 GMT
I0628 14:45:10.001979   48350 round_trippers.go:580]     X-Envoy-Upstream-Service-Time: 134
I0628 14:45:10.001998   48350 round_trippers.go:580]     Via: 1.1 google
I0628 14:45:10.002016   48350 round_trippers.go:580]     Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
I0628 14:45:10.002035   48350 round_trippers.go:580]     Content-Type: application/json; charset=utf-8
I0628 14:45:10.002053   48350 round_trippers.go:580]     Vary: Accept-Encoding
I0628 14:45:10.002219   48350 round_trippers.go:580]     Strict-Transport-Security: max-age=31536000; includeSubDomains
I0628 14:45:10.002243   48350 round_trippers.go:580]     Server: istio-envoy
NAME                    ID                                     STATUS   DEPLOYED CONFIGURATION     CONFIGURATION STATUS
bh2                     84cab9e2-d55d-4301-8865-e85bedaaea41   ready    gcp-provider-testing       ready
borrelli-bug-test       064b6e2d-7b64-42c2-974c-562ca0cdf6c3   ready    configuration-rds-prod     ready
AlainRoy commented 1 year ago

I have a couple of small questions/nits, but I think this looks really useful -- thank you!

sttts commented 1 year ago

Have seen that pattern in a number of places, e.g. git clean -f -f -f to really force it.

sttts commented 1 year ago

Double checked that go run ./cmd/up controlplane -a upbound list --debug=3 also works.