Skip to content
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: ModuleContext periodically refreshed on the controller #1865

Merged
merged 11 commits into from
Jun 26, 2024

Conversation

jonathanj-square
Copy link
Contributor

fixes #1699

GetModuleContext will stream updated ModuleContext to the runner.

@jonathanj-square jonathanj-square requested review from a team and matt2e and removed request for a team June 24, 2024 20:41
@ftl-robot ftl-robot mentioned this pull request Jun 24, 2024
`GetModuleContext` will stream updated `ModuleContext` to the runner.
@jonathanj-square jonathanj-square force-pushed the jonathanj/controller-dynamic-module-context branch from f48ae05 to 331d44f Compare June 25, 2024 19:27
worstell and others added 9 commits June 26, 2024 11:52
ensure controller is live and db container is provisioned before
executing startup tasks
`.Abs()` will return a clone with all paths made absolute. This avoids a
bunch of manual and error prone joining.
There are two commands:

`ftl box build <image>` builds a self-contained Docker container with a
set of modules.

`ftl box run` runs modules inside an ftl-in-a-box container (currently
does nothing).
- Looking into why we are getting ASM sync errors on staging and it is
hard to tell whether the error is happening in the leader or the
follower. These error changes should help this.
- `secretsCache` should not have any mention of ASM as it is meant to be
generic
By design, `RetryStreamingServerStream()` reissues the underlying RPC
whenever the stream terminates, and `GetModuleContext()` was exiting
immediately after sending its first response, resulting in a busy loop.
This required some changes to how the build engine works, in that build
and deploy can now be run separately.

Building the box:

```
🐚 ~/dev/ftl $ ftl box echo examples/go
info:time: Building module
info:echo: Building module
info: Building image echo
```

Running locally:

```
🐚 ~/dev/ftl $ ftl box-run --dsn="postgres://postgres:secret@localhost:15432/ftl?sslmode=disable" examples/go/
info: Web console available at: http://0.0.0.0:8892
info: HTTP ingress server listening on: http://0.0.0.0:8891
info:time: Deploying module
info: Reusing deployment: dpl-time-xpun6vddce07f5s
info: Deployed dpl-echo-1bd1tvnmig06767u
info: Deployed dpl-time-xpun6vddce07f5s
info:echo: Deploying module
info: Reusing deployment: dpl-echo-1bd1tvnmig06767u
info: All modules deployed
```

Running the resulting image works but we need to set up Docker compose
with PG:

```
🐚 ~/dev/ftl $ docker run --platform linux/amd64 echo
ftl: error: failed to create database: database not ready after 10 tries: failed to connect to `user=postgres database=`:
             127.0.0.1:5432 (localhost): dial error: dial tcp 127.0.0.1:5432: connect: connection refused
             [::1]:5432 (localhost): dial error: dial tcp [::1]:5432: connect: connection refused
```
Comment on lines +699 to +700
checksum = (checksum * 115163) + configurationMapChecksum(secrets)
checksum = (checksum * 454213) + configurationDatabaseChecksum(databases)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanj-square what are these 115163 and 454213 numbers?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: just use sha256 for everything, there's no need to truncate it and switch to a manual 64-bit checksum. Pass around the hash.Hash from sha256.New() to generate the checksum, then just compare checksum.Sum() results with bytes.Compare()

@jonathanj-square jonathanj-square merged commit 4a30e97 into main Jun 26, 2024
43 checks passed
@jonathanj-square jonathanj-square deleted the jonathanj/controller-dynamic-module-context branch June 26, 2024 19:23
// This operation is used to detect configuration change.
func configurationMapChecksum(m map[string][]byte) int64 {
sum := int64(0)
for k, v := range m {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ranging over a map is not ordered, you'll need to use maps.Keys(m) and sort.Slice().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make these adjustments in the follow-up PR. I went with a sum of hashes to avoid having to worry about ordering; after adopting the suggestions the randomized ordering will matter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I realised after that you were adding the values to avoid the sort, but I think just using sha256 directly will be clearer and simpler.

// This operation is used to detect configuration change.
func configurationDatabaseChecksum(m map[string]modulecontext.Database) int64 {
sum := int64(0)
for k, v := range m {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Push changes to ModuleContext down to the runner
5 participants