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

v3.2.0 No Longer Supports Proxy Settings #198

Merged
merged 12 commits into from
Nov 7, 2022
Merged

Conversation

bendbennett
Copy link
Contributor

Closes: #197

@@ -163,6 +163,7 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
caCertificate := model.CaCertificate

tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Copy link

@dcaswell-square dcaswell-square Nov 1, 2022

Choose a reason for hiding this comment

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

I'm not sure this is the most complete way to handle behavior differences that were introduced in v3.2.0, as the Proxy is only one of several properties that are set on the DefaultTransport (https://github.com/golang/go/blob/f3c39a83a3076eb560c7f687cbb35eef9b506e7d/src/net/http/transport.go#L38-L54) that are no longer going to be consistent with the previous version behavior. Ignoring the proxy values was the most immediately noticeable to users, but what about all of the timeouts, MaxIdleConns, and ForceAttemptHTTP2 which will also default to different values than those from older provider versions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also recommend using http.DefaultTransport to prevent other potential behavior changes. There could also be consideration for using https://pkg.go.dev/github.com/hashicorp/go-cleanhttp similar to other HashiCorp maintained Go modules to prevent potential issues with multiple host connections across data sources or other regressions involving a mutated http.DefaultTransport.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have switched to using http.DefaultTransport. I took a look at https://pkg.go.dev/github.com/hashicorp/go-cleanhttp but it seems that there are differences in the configuration of the Transport so in order to avoid changes in behaviour this has not been used at this time.

Comment on lines 481 to 484
p := goproxy.NewProxyHttpServer()

proxy := httptest.NewServer(p)
defer proxy.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Over in the terraform-provider-tls acceptance testing, all the testing HTTP servers, including the proxies, have connection counting:

https://github.com/hashicorp/terraform-provider-tls/blob/b9cbb62bc2a8b90f6af91e86047082a5357e8c2f/internal/provider/testutils/local_server.go#L38-L46

Then there is a TestCheckFunc which ensures that the "real" HTTP server and proxy HTTP server have matching connection counts:

https://github.com/hashicorp/terraform-provider-tls/blob/b9cbb62bc2a8b90f6af91e86047082a5357e8c2f/internal/provider/testutils/local_server.go#L117-L127

I think we'll need something similar here to verify that the proxy is correctly being used, unless there is a better testing strategy.

Copy link
Contributor Author

@bendbennett bendbennett Nov 2, 2022

Choose a reason for hiding this comment

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

I'm looking into the current test failures (e.g., https://github.com/hashicorp/terraform-provider-http/actions/runs/3376234811/jobs/5603729486).

Check 2/2 error: expected server and proxy active connection count to match: server was 1, while proxy was 0

I can't reproduce this failure locally, I see a different failure.

Check 2/2 error: expected server and proxy active connection count to match: server was 3, while proxy was 1

Copy link
Contributor Author

@bendbennett bendbennett Nov 2, 2022

Choose a reason for hiding this comment

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

I see the same failures in CI (e.g., https://github.com/hashicorp/terraform-provider-http/actions/runs/3376368850/jobs/5604018894) when using

	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
	}
Check 2/2 error: expected server and proxy active connection count to match: server was 1, while proxy was 0

But all tests pass when running locally with this configuration.

@@ -163,6 +163,7 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
caCertificate := model.CaCertificate

tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also recommend using http.DefaultTransport to prevent other potential behavior changes. There could also be consideration for using https://pkg.go.dev/github.com/hashicorp/go-cleanhttp similar to other HashiCorp maintained Go modules to prevent potential issues with multiple host connections across data sources or other regressions involving a mutated http.DefaultTransport.

url = "%s"
}
`, svr.URL),
Check: resource.TestCheckResourceAttr("data.http.http_test", "status_code", "200"),
Copy link
Contributor

Choose a reason for hiding this comment

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

This test looks correct to me, but for some reason is unhappy on Terraform version 0.14:

=== RUN   TestDataSource_HTTPViaProxyWithEnv
    data_source_http_test.go:489: Step 1/1 error: Check failed: Not found: data.http.http_test in [root]
--- FAIL: TestDataSource_HTTPViaProxyWithEnv (0.40s)

I'll try to do some investigative work with my end of day.

Copy link
Contributor

Choose a reason for hiding this comment

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

The quirk with Terraform version 0.14.x is that it will not set the Terraform state for a data source which returns a warning diagnostic. The warning being generated here is:

2022-11-01T16:50:56.310-0400 [TRACE] sdk.proto: Received downstream response: diagnostic_error_count=0 diagnostic_warning_count=1 tf_req_duration_ms=0 tf_data_source_type=http tf_req_id=5887d459-0e1a-5aa1-0241-13d21f8698ca tf_provider_addr=registry.terraform.io/hashicorp/http tf_proto_version=5.3 tf_rpc=ReadDataSource
2022-11-01T16:50:56.310-0400 [WARN]  sdk.proto: Response contains warning diagnostic: tf_provider_addr=registry.terraform.io/hashicorp/http tf_proto_version=5.3 tf_rpc=ReadDataSource tf_data_source_type=http diagnostic_severity=WARNING diagnostic_summary="Content-Type is not recognized as a text type, got \"\"" diagnostic_detail="If the content is binary data, Terraform may not properly handle the contents of the response." tf_req_id=5887d459-0e1a-5aa1-0241-13d21f8698ca
2022-11-01T16:50:56.310-0400 [TRACE] sdk.proto: Served request: tf_provider_addr=registry.terraform.io/hashicorp/http tf_proto_version=5.3 tf_rpc=ReadDataSource tf_data_source_type=http tf_req_id=5887d459-0e1a-5aa1-0241-13d21f8698ca

The data source correctly does not exit early in this case. The testing fix for this is to ensure the HTTP response also includes a valid Content-Type header, e.g.

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
}))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the investigation. Have added the fix you suggested.

@github-actions github-actions bot added size/L and removed size/S labels Nov 2, 2022
@bendbennett bendbennett requested a review from bflad November 3, 2022 12:47
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

One more little consideration, otherwise looks good to me 🚀

internal/provider/data_source_http.go Outdated Show resolved Hide resolved
return httpproxy.FromEnvironment().ProxyFunc()(req.URL)
}

if clonedTr.TLSClientConfig == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: To further prevent any differences due version to 3.2.0 changes, it is mentioned in the TLSClientConfig documentation that:

// If nil, the default configuration is used.
// If non-nil, HTTP/2 support may not be enabled by default.

I think we may want to consider moving this nil check inside each of the !IsNull() branches below to prevent any sort of further HTTP/2 oddities when there is no custom TLS configuration.

internal/provider/data_source_http.go Show resolved Hide resolved
internal/provider/data_source_http.go Show resolved Hide resolved
@bflad bflad added the bug label Nov 3, 2022
@bflad
Copy link
Contributor

bflad commented Nov 3, 2022

My editor is also prompting to run go mod tidy, which moves golang.org/x/net v0.0.0-20220708220712-1185a9018129 to the direct dependencies. While we're doing that, we may want to consider updating it to its first tagged release (v0.1.0; go get golang.org/x/net@v0.1.0), so dependabot can appropriately prompt us for updates. I'm not seeing anything in golang/net@1185a90...v0.1.0 that gives me pause.

@RaphaelDucay
Copy link

Any date in mind for the release of the fix ? Thx in advance

@bendbennett
Copy link
Contributor Author

Any date in mind for the release of the fix ? Thx in advance

Hi @RaphaelDucay 👋
We are currently finalising the changes and hope to have the fix released in the next few days.

@bendbennett bendbennett added this to the v3.2.1 milestone Nov 7, 2022
@bendbennett bendbennett merged commit bdf31bd into main Nov 7, 2022
@bendbennett bendbennett deleted the bendbennett/issues-197 branch November 7, 2022 15:17
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2024
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.

v3.2.0 No Longer Supports Proxy Settings
4 participants