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

Container logs sync enhancement #35

Merged
merged 4 commits into from
Dec 20, 2023
Merged

Container logs sync enhancement #35

merged 4 commits into from
Dec 20, 2023

Conversation

yhabteab
Copy link
Member

This PR introduces quite significant changes in how Pod -> Container -> Container_{*} are synced. Namely, all container related, like ContainerDevices, ContainerMounts etc. are now no longer pod event driven being synced, but rather the respective containers. Specifically, this means that the containers themselves are no longer allowed to be automatically deleted cascading. Instead, the container events are now processed separately. Towards this end, this PR introduces two new sync channels upsertPods and deletePods. These operate roughly like the following:

  • main() invokes the schemav1#SyncContainers() function and passes through the two new chans, which are then polled simultaneously.

  • For all uploaded v1.Pods, this function goes over each of their containers and schedules/cancels the container log synchronisation depending on the container state. These jobs are currently rescheduled every 5 minutes for each individual container and are allowed to run a maximum of 60 jobs at a time. These numbers are randomly chosen by me and will certainly change or become configurable in the future.

  • However, for all deleted v1.Pods, the flow control looks a bit different. Since we are just passing through the entity checksums for all the deletion streams, we first need to load all the containers for each streamed pod ID from the database. This process is done concurrently for each pod ID, and thereafter the containers are passed to the next stage where the deletion stream is triggered for them. This deletion process first removes all container references such as Container_{device, mounts, logs} from the database before deleting the container itself.

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jun 29, 2023
@yhabteab yhabteab requested a review from lippserd June 29, 2023 13:32
@yhabteab yhabteab force-pushed the container-logs branch 2 times, most recently from 7914b81 to 96e0535 Compare June 30, 2023 07:56
@@ -645,7 +645,7 @@ func (db *Database) query(ctx context.Context, query string, scope ...interface{
if len(scope) == 1 && IsStruct(scope[0]) {
rows, err = db.NamedQueryContext(ctx, query, scope[0])
} else {
rows, err = db.QueryxContext(ctx, query, scope...)
rows, err = db.QueryxContext(ctx, db.Rebind(query), scope...)
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain that change please? And why it's only needed in the else branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you explain that change please?

I just noticed that by accident. Right now there's no problem with it because the ? placeholders for mysql don't need a rebind, db.Rebind() is also a no-op for mysql driver. This is only relevant for PostgreSQL.

And why it's only needed in the else branch?

Named queries are rebound by the library itself.

@lippserd lippserd merged commit 5851244 into main Dec 20, 2023
6 of 7 checks passed
@lippserd lippserd deleted the container-logs branch December 20, 2023 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants