-
Notifications
You must be signed in to change notification settings - Fork 224
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
Remove leaking logs from CLI proxy package #853
Comments
@viveksyngh could you pick this up next please? |
Yes |
Today we have:
But the example on the call (GitHub) looked like:
|
This commit removes leaking logs from the SDK (proxy package) of the CLI by removing custom print statements within proxy package. It updates method signature for DeployFunction which now returns deployOutput text along with status code. Fixes: openfaas#853 Signed-off-by: Vivek Singh <[email protected]>
I was looking into making CLI response consistent and I was thinking of following approach. Every API from SDK can return three output which are as following
Response struct looks something as below
For errors I looked at few of the SDK and looks like if there in any response which is not in the range of 200 to 299, then they consider it as an error and respond with error message for example One challenge I found is some of our API's like DeployFunction or DeleteFunction do not return anything in response body. We need to return something for these interfaces to make them consistent with other interfaces. I am not sure what we information we can return, may be we can return empty struct for now and update it later if required. |
@viveksyngh a couple thoughts
Overall, I would support/approve your proposal. For the sake of historical completeness. There are two other options I have seen. A. I have also seen is having both the structured Response types and a structured Error type that implement type Responser interface {
GetResponse() *http.Response
} so that you can embed the raw The advantage is that the SDK is less noisy for the happy path use cases. Most of the time you don't need the function, _, err := sdk.Operation(req) Embedding the function, err := sdk.Operation(req)
// oh no i need the raw response to inspect an header
resp := function.Respone() There are two downside. First, of course, is that accessing the This leads to the other option I have send B. To alleviate both downsides from option (A), we can create type FunctionResponse struct {
Function types.FunctionDeployment
Response *http.Response
} It is very clear that this is wrapping a structured payload and that it provides access to the raw Response object. It is also not going to be a valid input for any other sdk method. This also does something that you might like, it gives you something to always return, even for Delete requests, for example type DeleteResponse struct {
Response *http.Response
} |
Could we get a couple of brief scenarios showing happy path / sad path / error and the populated values for:
happy = 200 deploys OK From @LucasRoesler - consider using a "typed error" such as Can we take any inspiration from the K8s API? https://pkg.go.dev/k8s.io/apimachinery/pkg/api/errors Such as |
Response format for different scenarios.
For example
Then we can also define some method as below which unwrap an error and check if the reason is matching with corresponding Reason message
3.can't open HTTP connection or timed out
Is this case err will be |
Discussed on the call with the contributors group. Please can you go ahead and do a PR for the one method you were working on - deploy/update? |
Let's make sure the middle parameter httpRes isn't wrapped. We don't need that today because we have nothing additional to add, so stdlib is less surprising for consumers. |
@Waterdrips do you want to pick up the secrets changes? |
PR Raised #885 |
@alexellis @Waterdrips and @utsavanand2 continuing from the zoom discussion yesterday I had a thought this morning about the 3 legged response from the sdk, I actually think it introduces an awkwardness around when to read the
There are of course ways to handle all of this, but we probably need to be very clear in the documentation about how to actually work with the response object: sometimes you read it, sometimes you don't, and sometimes you need to check the error for the body We can say this is ok, but I think it is worth considering if we like this DX The alternative that we discussed, a typed error
in both cases, the body is already handled correctly. |
@viveksyngh what are your thoughts on what Lucas said about the body, closing it and making it available to the end user? |
@LucasRoesler this is something that I hadn't considered. Can someone look into the way the github-go library does this? Since we've been looking at it as a sort of example of how to do things. |
The example for creating a repo ignores the response: https://github.com/google/go-github/blob/master/example/newrepo/main.go#L44 Here's the create repo function: Which calls "Do" and it closes the body, then caches a copy for reading at a later time if needed: Either an io.Writer can be passed in, or a typed JSON object for decoding the response. |
I looked closely at the example and implementation of the go-github library. To fix issue issues mentioned by @LucasRoesler we can read the response body, check for the errors and try to parse the response body. After that , we can rewrite the response body, so that It can be read by the consumer of the SDK again. This is how it has been also, handled by the But looks like in case of success it does not rewrite the response body, rather takes input ( However, I would like community members to decide and have consensus on which way we want to implement this, have 3 responses or embed these details in errors. In my opinion, we would also need to provide additional documentation if we embed http related information in the error object that, what informations we are embedding and how can someone consume it. Providing an http response object is more intuitive. |
Most people seem happy with the 3 return values instead of 2. Go with that. |
As proxy package is used as SDK it should remove all logging and should return those outputs as results from those API
Expected Behaviour
It should not leak logs when SDK are called.
Current Behaviour
It is having some print/log statements like
faas-cli/proxy/deploy.go
Line 75 in 693a50d
Possible Solution
Remove these print statements
Standardised API results to provide more information to the callers
TODO - Share API format results
Steps to Reproduce (for bugs)
Context
Your Environment
FaaS-CLI version ( Full output from:
faas-cli version
):Docker version ( Full output from:
docker version
):Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)?
Operating System and version (e.g. Linux, Windows, MacOS):
Link to your project or a code example to reproduce issue:
The text was updated successfully, but these errors were encountered: