-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
4162c4c
to
91548c5
Compare
91548c5
to
d8129d4
Compare
// 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
r := chi.NewRouter() | ||
|
||
r.Use(chiware.RequestID) | ||
r.Use(chiware.RealIP) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lgtm |
Needed by brave/brave-browser#208
The translation relay server supports 2 endpoints:
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.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)