-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: add lifecycle and endpoint customization #203
Conversation
This is still a work in progress. Enables function developers to export `init()`, `shutdown()`, `liveness()` and `readiness()` functions from the function file, enabling startup behaviors such as a connection to a database or other persistent store, clean shutdowns, and customizable liveness and readiness checks. Signed-off-by: Lance Ball <lball@redhat.com>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
==========================================
- Coverage 92.39% 90.90% -1.49%
==========================================
Files 9 9
Lines 263 286 +23
==========================================
+ Hits 243 260 +17
- Misses 20 26 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist I've marked it as a draft, but any feedback you have now is welcome. |
about a month ago i took a quick look at doing something similar here: lholmquist@628fac0 With the quick glance i just took of this PR, it looks like we had the same thoughts, so that's good :) i'll try to take a better look at comment today |
A thought i just had regarding the |
Not much that's for sure. I think, however, instead of adding a listener to the server shutdown event, it would be better handled in the way the CLI is doing |
Also cleans up shutdown handling and adds some comments. Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist ok I think this is ready for a first look when you have a chance. |
Signed-off-by: Lance Ball <lball@redhat.com>
@@ -22,7 +22,39 @@ at `localhost:8080`. The incoming request may be a | |||
just a simple HTTP GET/POST request. The invoked user function can be | |||
`async` but that is not required. | |||
|
|||
## Function Signatures | |||
## The Function Interface |
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.
It should probably be documented that you can also change the health checks path using either environment variables are the liveness.path/readiness.path
properties in the function
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.
Oh right - I forgot about that. At the moment, the Function.liveness.path
property will override any environment setting. I wonder if it should be the other way around.
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.
hmmm, good question. i don't have to strong of feelings either way, but probably leaning more towards the way it currently is. function code overrides env variables
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 might also want to add port
and logLevel
as properties on the Function
object so that the behavior is the same in terms of precedence. Default is superseded by configuration (in func.yaml, on the command line, or passed options to start()
), which is superseded by environment variables.
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.
hmmm, good question. i don't have to strong of feelings either way, but probably leaning more towards the way it currently is. function code overrides env variables
I think the motivation for env variables overriding function config is that the configuration would typically be set up for production environments, and coded into bash scripts or other pipeline tooling. For local development this can be overridden without changing the production settings by adjusting env vars - therefore no changes to the code.
Signed-off-by: Lance Ball <lball@redhat.com>
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.
@lance except for my previous comments LGTM!
Awesome - but please hold off on merging as I have some additional changes locally that I am still working on. I should get those added tomorrow. |
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist OK, I think this is probably good for a final review. I've updated README.md and the TypeScript types. |
lib/health-check.js
Outdated
module.exports = function healthCheck(opts) { | ||
return (fastify, _, done) => { | ||
// Handle health checks | ||
fastify.get(opts?.readiness?.path || readinessURL, { logLevel: 'warn' }, opts.readiness || callProtect); |
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.
should these default to warn? or should they be whatever is in the config?
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.
@lholmquist done - good catch! Hopefully this PR is good to go now.
Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist @matejvasek ptal |
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.
Sorry for the delay, i was on PTO last week
LGTM!!
This is still a work in progress. Enables function developers to export
init()
,shutdown()
,liveness()
andreadiness()
functions from the function file, enabling startup behaviors such as a connection to a database or other persistent store, clean shutdowns, and customizable liveness and readiness checks.Still needed:
hack/run.js
to provide a better example (and maybe move fromhack/run.js
tosample/index.js
types.d.ts
to make sure we're doing enough typingFunction
objectsFixes: #142