Skip to content

Conversation

@k-yomo
Copy link
Contributor

@k-yomo k-yomo commented Jan 24, 2023

Resolves #258

httputil.DumpRequestOut is actually executing dummy RondTrip and it causes following error since the schema and host is not set at the point.
request dump error: &errors.errorString{s:"unsupported protocol scheme \"\""}

This PR changes the method to use httputil.DumpRequest which can work with an incomplete url.

2023-01-25T01:36:36.976+0900 [DEBUG] provider.terraform-provider-elasticstack: elasticsearch API Request Details:
---[ REQUEST ]---------------------------------------
GET /products?flat_settings=true HTTP/1.1


-----------------------------------------------------: @module=elasticstack tf_mux_provider=*schema.GRPCProviderServer tf_provider_addr=registry.terraform.io/elastic/elasticstack tf_rpc=ApplyResourceChange @caller=/Users/k-yomo/go/src/github.com/k-yomo/terraform-provider-elasticstack/internal/clients/debug.go:46 tf_req_id=6f651534-de0f-0549-41c9-ce9789c53b9f tf_resource_type=elasticstack_elasticsearch_index timestamp=2023-01-25T01:36:36.976+0900

Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

I know this is a super quick fix, but we could simplify the tf provider by using the go-elasticsearch Logger interface.

func (d *debugTransport) Perform(r *http.Request) (*http.Response, error) {
ctx := r.Context()
reqData, err := httputil.DumpRequestOut(r, true)
reqData, err := httputil.DumpRequest(r, true)
Copy link
Member

Choose a reason for hiding this comment

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

From the docs

It should only be used by servers to debug client requests

I think that we should be either using the build in go-elasticsearch loggers or if using tflog.* was important implementing a custom logger

@tobio tobio requested a review from webfella February 15, 2023 04:05
@tobio
Copy link
Member

tobio commented Feb 15, 2023

@webfella are you able to take a look at my changes here?

@tobio tobio enabled auto-merge (squash) February 15, 2023 04:06
@tobio tobio disabled auto-merge February 15, 2023 04:15
webfella
webfella previously approved these changes Feb 15, 2023
Copy link

@webfella webfella left a comment

Choose a reason for hiding this comment

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

LGTM 🥟

@tobio tobio enabled auto-merge (squash) February 15, 2023 04:22
@tobio tobio merged commit 9ab6c41 into elastic:main Feb 15, 2023
@k-yomo k-yomo deleted the fix-request-log branch February 15, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Dump request is not working when debug mode

3 participants