openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 226 forks source link

Proposal: add --debug flag to `deploy` (print out HTTP request) #636

Open ewilde opened 5 years ago

ewilde commented 5 years ago

During provider development i've found it helpful to log the the entire request/response sent from the CLI to the gateway.

Expected Behaviour

faas cli deploy --debug

Current behaviour

$faas deploy 
Deploying: echo.
Unexpected status: 400, message: Please provide a valid route /function/function_name.

Function 'echo' failed to deploy with status code: 400

Future behaviour with debug flag

$ faas deploy --debug                                    
Deploying: echo.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
2019/05/10 18:54:21
-------- deploy request:echo --------
PUT /system/functions HTTP/1.1
Host: 127.0.0.1:8080
Authorization: Basic YWRtaW46OGFmYzg4N2YxMjM3NGViZmMwN2I0ZTZjMTQ3MzY5Y2Y1NzQ5MGNmZTA1N2ZkOGIyYTE1ZTk2MWEwZjc2Y2ZhNQ==

{"service":"echo","image":"ewilde/echo:latest","network":"","envProcess":"python index.py","envVars":{},"constraints":null,"secrets":[],"labels":{},"annotations":{},"limits":null,"requests":null,"readOnlyRootFilesystem":false}
-------------------------------------
2019/05/10 18:54:21
-------- deploy response:echo --------
HTTP/1.1 400 Bad Request
Content-Length: 53
Content-Type: text/plain; charset=utf-8
Date: Fri, 10 May 2019 17:54:21 GMT

Please provide a valid route /function/function_name.
-------------------------------------

Unexpected status: 400, message: Please provide a valid route /function/function_name.

I have a private fork with the above functionality, if it's something the community wants I can PR it in / or adapt based on feedback.

Alternatives

Extensions

burtonr commented 5 years ago

I'm not against this at all, but perhaps a better DX might be simply adding the error message to the output.

Rather than Function 'echo' failed to deploy with status code: 400

Function 'echo' failed to deploy. Bad Request. Message: 'Please provide a valid route /function/function_name.'

That would be in addition to your suggestion for the --debug command. Perhaps -v --verbose instead?

It would be good to be able to also get the full request and response output to diagnose an issue better. Generally speaking, at least from my experience, just having the error message returned would greatly improve the experience.

ewilde commented 5 years ago

@burtonr apologies if it wasn’t clear, my proposal is to add full request/response logging with debug flag

alexellis commented 5 years ago

I can see how this might be useful, but what about using a simple intercepting proxy instead?

You'll get complete logs of request and response with the ability to replay etc.

ewilde commented 5 years ago

@alexellis I agree that at the CLI level this can be achieved with a proxy. I mentioned this in the issue under ‘alternatives’.

Couple of draw backs:

alexellis commented 5 years ago

Hi what about https://mitmproxy.org/ ?