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

Initial implementation of go-translate #1

Merged
merged 14 commits into from
Mar 22, 2019
Merged

Initial implementation of go-translate #1

merged 14 commits into from
Mar 22, 2019

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Mar 18, 2019

Needed by brave/brave-browser#208

The translation relay server supports 2 endpoints:

  1. The POST /translate endpoint processes translate requests in Google format, sends corresponding requests in Microsoft format to Microsoft translate server, then returns responses in Google format back to the brave-core client.

  2. The GET /language endpoint processes requests of getting the support language list in Google format, sends corresponding requests in Microsoformat to Microsoft translate server, then returns responses in Google format back to the brave-core client.

There are also a few static resources requested during in-page translation will be handled by go-translate and will be proxied through brave to avoid introducing direct connection to any Google server.

devop PR for deploying to brave.com: https://github.com/brave/devops/pull/785, proxy URLs in this PR will be updated once they're deployed to *.brave.com (Updated)

@yrliou yrliou self-assigned this Mar 18, 2019
@yrliou yrliou force-pushed the go_translate_impl branch 4 times, most recently from 4162c4c to 91548c5 Compare March 19, 2019 06:58
@yrliou yrliou mentioned this pull request Mar 19, 2019
19 tasks
@yrliou yrliou force-pushed the go_translate_impl branch from 91548c5 to d8129d4 Compare March 19, 2019 21:56
@yrliou yrliou marked this pull request as ready for review March 19, 2019 21:59
@yrliou yrliou requested a review from bbondy March 19, 2019 22:03
@yrliou yrliou requested a review from jumde March 20, 2019 16:39
// StartServer starts the translate proxy server on port 8195
func StartServer() {
serverCtx, logger := setupLogger(context.Background())
logger.WithFields(logrus.Fields{"prefix": "main"}).Info("Starting server")
Copy link

Choose a reason for hiding this comment

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

We need to make sure that we are not logging any user identifiable data here.

Copy link
Member Author

@yrliou yrliou Mar 20, 2019

Choose a reason for hiding this comment

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

INFO[4174] request complete                              http_method=POST http_proto=HTTP/1.1 http_scheme=http remote_addr="[::1]:57415" req_id=jocelyn-imacpro.local/aOPC3es7qv-000019 resp_bytes_length=821 resp_elapsed_ms=758.939688 resp_status=200 uri="http://localhost:8195/translate?anno=3&client=te_lib&format=html&v=1.0&sp=smrd&key=...&logld=vTE_20181015_01&sl=fr&tl=en&sp=nmt&tc=4&sr=1&tk=558905.922117&mode=1" user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"

This shares the same pattern as go-update so brave/go-update#22 applies here too.
As @jumde suggested, we should have a log-retention policy enforced on the infra side when we deploy the server.

cc @tomlowenthal

r := chi.NewRouter()

r.Use(chiware.RequestID)
r.Use(chiware.RealIP)
Copy link

Choose a reason for hiding this comment

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

@yrliou - Why do we need RealIP, looks like it sets the X-Forwarded-* headers? https://godoc.org/github.com/go-chi/chi/middleware#RealIP

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is for requests coming in from brave-core, but not the requests we're sending out to Microsoft AFAIK.
And based on the doc, it's setting the remote address in the requests instead of setting the header.
It's a shared pattern from bat-go and go-update btw.

Copy link

Choose a reason for hiding this comment

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

My concern was not about the headers sent to Microsoft, but more in terms of adding more avenues to log user ips on the go-translate server. For now, having a log-retention policy on the infrastructure side sounds like a good idea.

@jumde
Copy link

jumde commented Mar 22, 2019

lgtm

@jumde jumde self-requested a review March 22, 2019 16:46
@yrliou yrliou merged commit fb96fd3 into master Mar 22, 2019
@mihaiplesa mihaiplesa deleted the go_translate_impl branch July 1, 2022 10:35
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.

4 participants