Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/google: Log HTTP requests and responses in DEBUG mode #14281

Merged
merged 1 commit into from
May 10, 2017

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented May 8, 2017

This is to allow easier debugging of the Google provider and create a transparently logging RoundTripper which we can use in other providers that use SDKs which allow passing a custom transport or http.Client (which should be most of them) to get a similar behaviour.

Snippet from debug log

2017/05/08 09:55:24 [DEBUG] Google API Request Details:
---[ REQUEST ]---------------------------------------
POST https://www.googleapis.com/compute/v1/projects/terraform-testing/regions/us-central1/addresses?alt=json HTTP/1.1
Host: www.googleapis.com
Content-Type: application/json
User-Agent: google-api-go-client/0.5 (darwin amd64) Terraform/0.9.5-dev

{"name":"address-test-j7idu01jis"}

-----------------------------------------------------
2017/05/08 09:55:30 [DEBUG] Google API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Alt-Svc: quic=":443"; ma=2592000; v="37,36,35"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=UTF-8
Date: Mon, 08 May 2017 07:55:28 GMT
Etag: "v4wxzBlixxu7uZ08oFMb8_FmBGc/1gCxrHTRN8pmcWYp-XollYtqIfs"
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
Vary: Origin
Vary: X-Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

{
 "kind": "compute#operation",
 "id": "7108038085358492319",
 "name": "operation-1494230127968-54efe8ffd7f00-b2784eec-3529555d",
 "operationType": "insert",
 "targetLink": "https://www.googleapis.com/compute/v1/projects/terraform-testing/regions/us-central1/addresses/address-test-j7idu01jis",
 "targetId": "5174079380724226719",
 "status": "PENDING",
 "user": "radeksimko@terraform-testing.iam.gserviceaccount.com",
 "progress": 0,
 "insertTime": "2017-05-08T00:55:28.363-07:00",
 "selfLink": "https://www.googleapis.com/compute/v1/projects/terraform-testing/regions/us-central1/operations/operation-1494230127968-54efe8ffd7f00-b2784eec-3529555d",
 "region": "https://www.googleapis.com/compute/v1/projects/terraform-testing/regions/us-central1"
}

-----------------------------------------------------

Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be very helpful for development, thanks @radeksimko!


func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if IsDebugOrHigher() {
reqData, err := httputil.DumpRequest(req, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an outgoing request we should probably use DumpRequestOut (I'm not sure what the practical difference is but the godoc seems to point to using this one instead)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course, you're absolutely right. I'll fix that prior to merging

@ghost
Copy link

ghost commented Apr 12, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants