-
-
Notifications
You must be signed in to change notification settings - Fork 959
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: Courier foreground worker with "kratos courier watch" #1033
feat: Courier foreground worker with "kratos courier watch" #1033
Conversation
Hey @aeneasr, would you happen to know the source of this error? |
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.
The error you get is caused by https:/ory/x/blob/87359d96f1cf9eb327949f693077968a50ecc283/configx/provider.go#L162-L166
Because of that, you have to add the flag to the config schema, just like it is done with e.g. the dev
or help
flag:
kratos/.schema/config.schema.json
Lines 1168 to 1184 in af200d1
"dev": { | |
"type": "boolean" | |
}, | |
"help": { | |
"type": "boolean" | |
}, | |
"sqa-opt-out": { | |
"type": "boolean", | |
"default": false | |
}, | |
"config": { | |
"type": "array", | |
"items": { | |
"type": "string" | |
} | |
} | |
}, |
We should probably adjust the flag loading, but it will be possible to put that value in the config file as well 😉
Looks good otherwise 👍
Thanks! |
48997fb
to
8e3c74d
Compare
What would we be looking for in terms of added material in the user guide docs? |
d642442
to
71f4e83
Compare
Hmm, I'm failing the |
|
I believe you need to update the e2e config to reflect the new changes as the mail tests are probably failing! |
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.
This looks great!
I think it would make sense to explain this in the docs a bit:
- https://www.ory.sh/kratos/docs/concepts/email-sms
- https://www.ory.sh/kratos/docs/guides/account-activation-email-verification - a small sentence and a link will be enough - something along the lines of "set up mail worker (link)".
- https://www.ory.sh/kratos/docs/guides/high-availability-ha - explain that with multiple nodes you need one worker node to handle the mail queue
Thank you!
cmd/courier/watch.go
Outdated
Run: func(cmd *cobra.Command, args []string) { | ||
d := driver.New(cmd.Context(), configx.WithFlags(cmd.Flags())) | ||
|
||
go ServeHealth(d, cmd, args) |
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 having health and metrics servers is honorable :) But we don't really need them IMO. It would make sense if this would handle HTTP API requests. Then, the LB needs to know if the service is up (health) and prometheus would want to know how much latency we have (for example).
So in my opinion, this can be removed!
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.
Thanks for the review!
Yeah, after doing some more reading, I think we can do without liveness probes in this case, and just rely on k8s restarting the pod if the courier crashes. I'll remove this
On the metrics front, you're quite right that latency metrics wouldn't be very relevant here since it isn't handling HTTP requests, but we would like to be able to monitor the go runtime related metrics, particularly since we'd like to be able to measure how well it's performing as we add load and potentially tune things like the number of concurrent goroutines and batch fetch size in response to our observations.
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 will work on these additional docs today
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.
Ok draft of doc updates are in, take a read and don't hesitate to suggest improvements
8ffbd5b
to
326bfea
Compare
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.
Awesome, thank you for your contribution! This looks pretty good and I have some ideas how to improve it further :)
f2befe9
to
c9b7f63
Compare
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.
Great! Now we need a bit of testing and we're good to go! :)
cmd/courier/watch.go
Outdated
@@ -0,0 +1,82 @@ | |||
package courier |
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.
Can you please add a test to see if this works (e.g. health port) as expected?
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.
Yes, much needed. Where would the best place be to add it?
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.
Two options: you extract as much from the cobra handler as possible (e.g. as a function) and then set it up, or you use the cobra test framework to run the command.
I would opt for the first option. Regarding courier tests and the SMTP integration, check out:
Cobra commands can be controlled from tests using:
import "github.com/ory/x/cmdx"
// ...
ce := &cmdx.CommandExecuter{New: func() *cobra.Command {
return cmd.RootCmd // might need to be exported in kratos
}, Ctx: ctx}
ce.ExecNoErr(t, "your", "command")
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.
Added some tests in cmd/courier/watch_test.go
, let me know what you think!
d4bd510
to
c4ca6ad
Compare
hm, the
Can't imagine it's related to my PR |
cmd/courier/watch.go
Outdated
} | ||
}() | ||
<-ctx.Done() | ||
return server.Shutdown(ctx) |
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.
Added this so the server can be shutdown by cancelling the context (eg in unit tests).
Let me know if there's a better way.
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 looks ok
@mattbonnell , great work! The current problem for the tests is not your fault. I'll be trying to fix that now! |
BREACKING CHANGES: This patch moves the courier watcher (responsible for sending mail) to its own foreground worker, which can be executed as a, for example, Kubernetes job. It is still possible to have the previous behaviour which would run the worker as a background task when running `kratos serve` by using the `--watch-courier` flag. To run the foreground worker, use `kratos courier watch -c your/config.yaml`. Closes #1033 Closes #1024 Co-authored-by: Matt Bonnell <[email protected]>
Related issue
#652 #732
Proposed changes
Following the discussion in #1024, this PR defines a new
kratos courier watch
command which runs the message courier in the foreground, as well as disabling the background courier by default whenkratos serve
is executed.The
--watch-courier
flag can be passed to theserve
command to execute the courier in the background as is the current behavior.Checklist
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further comments