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

Use retriable HTTP client in proxy mode #883

Merged
merged 3 commits into from
Sep 21, 2022
Merged

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Sep 21, 2022

Fixes: #882

This PR replaces the original HTTP client with go-retryablehttp client. It uses a custom retry policy to additionally check the content type header.

Testing:

EPR_LOG_LEVEL=debug go run . -feature-proxy-mode -proxy-to https://elastic.co # not EPR endpoint

Logs:

{"log.level":"debug","@timestamp":"2022-09-21T15:12:59.342+0200","log.origin":{"file.name":"proxymode/proxymode.go","file.line":116},"message":"Proxy /search request","request.uri":"https://elastic.co/search?prerelease=true","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-21T15:12:59.342+0200","log.origin":{"file.name":"proxymode/logger.go","file.line":29},"message":"performing request","method":"GET","url":"https://elastic.co/search?prerelease=true","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-21T15:13:00.285+0200","log.origin":{"file.name":"proxymode/logger.go","file.line":29},"message":"retrying request","request":"GET https://elastic.co/search?prerelease=true (status: 200)","timeout":1000000000,"remaining":4,"ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-21T15:13:01.484+0200","log.origin":{"file.name":"proxymode/logger.go","file.line":29},"message":"retrying request","request":"GET https://elastic.co/search?prerelease=true (status: 200)","timeout":2000000000,"remaining":3,"ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-21T15:13:03.697+0200","log.origin":{"file.name":"proxymode/logger.go","file.line":29},"message":"retrying request","request":"GET https://elastic.co/search?prerelease=true (status: 200)","timeout":4000000000,"remaining":2,"ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-21T15:13:07.899+0200","log.origin":{"file.name":"proxymode/logger.go","file.line":29},"message":"retrying request","request":"GET https://elastic.co/search?prerelease=true (status: 200)","timeout":8000000000,"remaining":1,"ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2022-09-21T15:13:16.102+0200","log.origin":{"file.name":"package-registry/search.go","file.line":51},"message":"proxy mode: search failed","error":{"message":"can't proxy search request: GET https://elastic.co/search?prerelease=true giving up after 5 attempt(s): unexpected content type: text/html; charset=utf-8","stack_trace":"\ngithub.com/elastic/package-registry/proxymode.(*ProxyMode).Search\n\t/Users/marcin.tojek/go/src/github.com/elastic/package-registry/proxymode/proxymode.go:119\nmain.searchHandlerWithProxyMode.func1\n\t/Users/marcin.tojek/go/src/github.com/elastic/package-registry/search.go:49\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/Cellar/go/1.19.1/libexec/src/net/http/server.go:2109\ngo.elastic.co/apm/module/apmhttp.(*handler).ServeHTTP\n\t/Users/marcin.tojek/go/pkg/mod/go.elastic.co/apm/module/apmhttp@v1.15.0/handler.go:74\ngithub.com/felixge/httpsnoop.CaptureMetrics.func1\n\t/Users/marcin.tojek/go/pkg/mod/github.com/felixge/httpsnoop@v1.0.3/capture_metrics.go:29\ngithub.com/felixge/httpsnoop.(*Metrics).CaptureMetrics\n\t/Users/marcin.tojek/go/pkg/mod/github.com/felixge/httpsnoop@v1.0.3/capture_metrics.go:84\ngithub.com/felixge/httpsnoop.CaptureMetricsFn\n\t/Users/marcin.tojek/go/pkg/mod/github.com/felixge/httpsnoop@v1.0.3/capture_metrics.go:39\ngithub.com/felixge/httpsnoop.CaptureMetrics\n\t/Users/marcin.tojek/go/pkg/mod/github.com/felixge/httpsnoop@v1.0.3/capture_metrics.go:28\ngithub.com/elastic/package-registry/util.captureZapFieldsForRequest\n\t/Users/marcin.tojek/go/src/github.com/elastic/package-registry/util/logging.go:120\ngithub.com/elastic/package-registry/util.logRequest\n\t/Users/marcin.tojek/go/src/github.com/elastic/package-registry/util/logging.go:114\ngithub.com/elastic/package-registry/util.LoggingMiddleware.func1.1\n\t/Users/marcin.tojek/go/src/github.com/elastic/package-registry/util/logging.go:105\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/Cellar/go/1.19.1/libexec/src/net/http/server.go:2109\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\t/Users/marcin.tojek/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/Cellar/go/1.19.1/libexec/src/net/http/server.go:2947\nnet/http.(*conn).serve\n\t/usr/local/Cellar/go/1.19.1/libexec/src/net/http/server.go:1991\nruntime.goexit\n\t/usr/local/Cellar/go/1.19.1/libexec/src/runtime/asm_amd64.s:1594"},"ecs.version":"1.6.0"}

@mtojek mtojek requested a review from a team September 21, 2022 13:23
@mtojek mtojek self-assigned this Sep 21, 2022
@elasticmachine
Copy link

elasticmachine commented Sep 21, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-09-21T13:25:13.874+0000

  • Duration: 5 min 34 sec

Test stats 🧪

Test Results
Failed 0
Passed 213
Skipped 0
Total 213

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

👍

proxymode/proxymode.go Show resolved Hide resolved
@mtojek mtojek merged commit 56ea032 into elastic:main Sep 21, 2022
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.

Error: can't proxy search request: invalid character '<' looking for beginning of value
3 participants