serverless / serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
Apache License 2.0
303 stars 80 forks source link

Is it possible to get error logging? #125

Open alexander-alvarez opened 6 years ago

alexander-alvarez commented 6 years ago

I didn't trust the deployment so I intentionally broke it to see what would happen below is what showed up in the console

~/dev/serverless$ serverless deploy 
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Unable to find any running pod for capitalize. Retrying...
Serverless: Unable to find any running pod for capitalize. Retrying...
Serverless: Unable to find any running pod for capitalize. Retrying...
Serverless: Unable to find any running pod for capitalize. Retrying...
Serverless: Giving up, unable to retrieve the status of the capitalize deployment. 

Which isn't very helpful for debugging purposes. Through searching I found https://github.com/serverless/serverless-kubeless/issues/85 which led me to this command:

kubectl logs -n kubeless $(kubectl get pods -n kubeless -l kubeless=controller -o=name)

Which showed me exactly why my function is broken

time="2018-06-04T20:25:05Z" level=info msg="Processing change to Function default/capitalize" pkg=function-controller
time="2018-06-04T20:25:05Z" level=error msg="Function can not be created/updated: failed: incorrect handler format. It should be module_name.handler_name" pkg=function-controller
time="2018-06-04T20:25:05Z" level=error msg="Error processing default/capitalize (giving up): failed: incorrect handler format. It should be module_name.handler_name" pkg=function-controller

I'm curious if this is something we could bubble up to stderr?

andresmgot commented 6 years ago

There are several problems with that:

What we could do is to print some tips (like the command you mention) for people to find the problem without the need to google the issue.

alexander-alvarez commented 6 years ago

Alright, that makes sense.

Not sure if related, but I'm getting deceptive messages when the handler is defined incorrectly.

What the user sees:

~/dev/serverless$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying Kafka trigger: echo-hellotopic
Serverless: Updating existing Kafka trigger
$

(you would think it was successful) What is actually happening

time="2018-06-06T20:27:10Z" level=error msg="Function can not be created/updated: failed: incorrect handler format. It should be module_name.handler_name" pkg=function-controller
time="2018-06-06T20:27:10Z" level=error msg="Error processing default/echo (will retry): failed: incorrect handler format. It should be module_name.handler_name" pkg=function-controller

To that effect I'm struggling to define a handler within a folder e.g the main in dist/index.js I was trying hander: dist.index.main which doesn't seem to work

I just came across https://github.com/open-bot/open-bot/blob/master/handlers.js#L7..L12 but it seems super hacky, but maybe what I'm trying to do isn't supported

andresmgot commented 6 years ago

mm, I see, I assume that's the output of an upgrade and I also assume that the first deployment was successfully performed. The problem with that is that the client submits the changes and see that there is a working deployment so it assumes that is has been successfully updated. We should fix that.

Regarding your problem with the handler, it is not possible to use folders, the serverless.yaml file should be in the same directory than the function code. See #121. Note that you can still use an index.js file in the root folder (something like the link you posted but more simple):

index.js

module.exports = {
  main: require('./lib/index').main,
}

And define the handler as index.main.

alexander-alvarez commented 6 years ago

mm, I see, I assume that's the output of an upgrade and I also assume that the first deployment was successfully performed

Those assumptions are correct.

Thanks for the snippet -- In the above example are all files in lib automatically packaged or do we have to supply package: include: - lib/ also? Happy to improve documentation on this front if I'm told where would be best appropriate

andresmgot commented 6 years ago

yes, all the files in the directory of the serverless.yaml are packaged except node_modules by default.

We have documentation in both the serverless repo (more related to the serverless plugin) and in the kubeless one. Happy to have contributions in any of those sites if you want to clarify something.