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: introducing the fleet package #3105

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

TBonnin
Copy link
Collaborator

@TBonnin TBonnin commented Dec 3, 2024

The fleet package will be used to managed the lifecycle of runners

This commit includes:

  • migration for deployments and nodes tables
  • deployments and nodes models (with tests)

This commit DOESN'T include (I though that would be enough for a first PR):

  • the control loop to handle nodes state transition
  • the routing logic

How to test

The code is not used so it is not possible to run it manually. There is tests though :)

@TBonnin TBonnin requested a review from a team December 3, 2024 21:23
Copy link

linear bot commented Dec 3, 2024

Comment on lines 32 to 33
routing_id varchar(255) NOT NULL,
deployment_id char(40) NOT NULL REFERENCES deployments(commit_id) ON DELETE CASCADE,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need a unique index for those two no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed

Copy link
Collaborator Author

@TBonnin TBonnin Dec 4, 2024

Choose a reason for hiding this comment

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

I now remember why I didn't make it unique. Because any node can end up in ERROR state and therefore several entry can have the same routingId/deploymentId.
Ex:

  1. Node is created as PENDING
  2. Request to Render to start the new runner fails for some reason. Node is set to ERROR
  3. A new node with same routingID and deploymentId is created as PENDING

Another example: if runner is idled because of inactivity, another runner might potentially be created with the same routingId/deployment

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, could be nice to have this clarified somewhere in the models 👍🏻

export class Fleet {
private dbClient: DatabaseClient;
constructor({ fleetId, dbUrl }: { fleetId: string; dbUrl: string }) {
this.dbClient = new DatabaseClient({ url: dbUrl, schema: fleetId });
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not passing the DBClient directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because I want the db schema to reflect the name/id of the fleet. I could set the schema for the DBClient and then pass the client but it is more encapsulated this way

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you thinking we would have multiple fleet schemas in production?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not planning to have multiple fleet anytime soon no but nothing would prevent it in the code

packages/fleet/lib/models/deployments.ts Show resolved Hide resolved
packages/fleet/lib/models/deployments.ts Outdated Show resolved Hide resolved
packages/fleet/lib/models/nodes.integration.test.ts Outdated Show resolved Hide resolved
packages/fleet/lib/models/nodes.ts Outdated Show resolved Hide resolved
packages/fleet/lib/models/nodes.ts Outdated Show resolved Hide resolved
packages/fleet/lib/models/nodes.ts Outdated Show resolved Hide resolved
packages/fleet/lib/models/nodes.ts Outdated Show resolved Hide resolved
@bodinsamuel
Copy link
Collaborator

let me know when you want another pass

@TBonnin
Copy link
Collaborator Author

TBonnin commented Dec 4, 2024

let me know when you want another pass

I have addressed all your comments I think so happy to get another pass

Copy link
Contributor

@nalanj nalanj left a comment

Choose a reason for hiding this comment

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

Pretty cool to see it taking shape. None of the things I commented on were things that I feel too too strongly about, more just asking questions and pondering.

});

describe('deploy', () => {
it('should create a new deployment', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not 100% sure about the right way for us to isolate this, and it's certainly a philosophical thing, but this test effectively runs the same code as the other deployment creation test. It might be a nice spot for us to use a test stub knowing that fleet can trust that deploy is well tested.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. On the other hand stub everywhere could introduce more issues down the line when underlying logic is changed.

I've added this test to bootstrap the fleet.integration.test file but I might remove it since it is not very useful

export class Fleet {
private dbClient: DatabaseClient;
constructor({ fleetId, dbUrl }: { fleetId: string; dbUrl: string }) {
this.dbClient = new DatabaseClient({ url: dbUrl, schema: fleetId });
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you thinking we would have multiple fleet schemas in production?

packages/fleet/lib/models/deployments.ts Show resolved Hide resolved
Copy link
Collaborator

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

Looking good 🦖

@@ -0,0 +1,23 @@
type Jsonable = string | number | boolean | null | undefined | readonly Jsonable[] | { readonly [key: string]: Jsonable } | { toJSON(): Jsonable };
Copy link
Collaborator

Choose a reason for hiding this comment

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

could be type-fest or could be stored globally in types/utils

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

didn't want to bring type-fest just for that. Where in types/utils would you put it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

packages/types/lib/utils.ts

The fleet package will be used to managed the lifecycle of runners
This commit includes:
- migration for deployments and nodes tables
- deployments and nodes models (with tests)
This commit DOESN'T include:
- the control loop to handle nodes state transistion
- the routing logic
Ex:
in case of error, a new node with same routingId/deploymentId will be
created
in case of runner idled because of inactivity, a new node with same
routingId/deploymentId will be created
@TBonnin TBonnin force-pushed the tbonnin/nan-2301/fleet-init-models branch from 544a1c3 to 0a2ded7 Compare December 5, 2024 14:01
@TBonnin TBonnin enabled auto-merge (squash) December 5, 2024 14:29
@TBonnin TBonnin merged commit 17f68e6 into master Dec 5, 2024
21 checks passed
@TBonnin TBonnin deleted the tbonnin/nan-2301/fleet-init-models branch December 5, 2024 14:36
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.

3 participants