Skip to content

solver: fix duplicate logs on export - #2267

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:log-dupe-simpler
Apr 26, 2022
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:log-dupe-simpler

Conversation

@sipsma

@sipsma sipsma commented Apr 22, 2022

Copy link
Copy Markdown
Contributor

This is a simple fix for the issue of logs being duplicated when an
export is performed. The issue is caused by Buildkit's behavior of
"backfilling" newly connected clients on the progress so far of vertices
referenced by their build. This addresses it in the simplest way
possible by just filtering out progress log events from these separate
builds.

This works but is fragile. It works because we currently always set
Evaluate to true when running solves, which means that any progress logs
will already have been sent to the main solve channel and any that are
sent to the separate channel created for the export must be duplicates.

If we ever want to enable Evaluate being set to false, we will need a
different fix. I wrote that fix out, but it's a tangled web of
synchronization and to fully understand that it actually covers every
race-condition you need to know details about BuildKit's internal
implementation. Therefore, for now I just left a comment about all this
above the line where we set Evaluate to true and linked to the more
complicated fix in case it's ever needed.

The long-term, non-hacky fix to this is to add support for Export to the
GatewayAPI. For now though, this is our best option and is in fact what
Buildkit developers did when facing the same issue in buildx.

One last note, there technically are some logs that we may be dropping
due to this as it turns out buildkitd uses the progress log streams to
write temporary errors encountered during registry operations. I think
this is okay for now because retriable errors are a rare case and if
retries are exhausted the actual error message does get returned to the
client. We will only be missing out on some intermediary ones.

Signed-off-by: Erik Sipsma [email protected]

Fixes #449

Opening as a draft because I am running into issues writing a test case but I want to get feedback on the simple approach here vs the more complicated one I mention in the commit message and code comments.

Comment thread solver/solver.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah! Parking this conversation for another time, but I've been meaning to ask your opinion on this Evaluate true.

The reason it's here is two fold:

  • Make sure the LLB is actually evaluated. Without this, unless the LLB is re-used by something else (another LLB, a read file, an export), it gets thrown again. Recently, we've changed client to do an AddRef for every single Solve ever made in order for export cache to work, so this reason is no longer valid (https://github.com/dagger/dagger/blob/main/client/client.go#L231)
  • Log Coordination. Without this, every "task" would be marked as completed immediately. And then asynchronously, eventually, it will actually run when references by another task. If no task references it, then it would be executed at the very end (because of the AddRef).

I'm wondering if this approach makes sense, in your opinion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think for now this is the right approach because it keeps things simpler for the reasons you said. The only downside I can think of is that it's possible Buildkit's solver won't be able to parallelize as effectively when vertex DAGs are sent one by one, with each solve blocking due to Evaluate being true.

However, we have the cue/flow solver layered on top of the Buildkit solver and it knows how to schedule vertices on the "task level" efficiently. As long as we have a 1-to-1 correspondence between LLB vertices and cue/flow tasks this should be good enough I think. If we ever deviate from that model significantly (i.e. we end up with cue tasks that create a bunch of LLB vertices that don't correspond to other cue tasks) then this could be worth revisiting.

This is a subtle issue though, these are just my immediate thoughts, worth considering more.

@sipsma
sipsma force-pushed the log-dupe-simpler branch 3 times, most recently from 95ff831 to 7d89188 Compare April 25, 2022 20:22
@sipsma
sipsma marked this pull request as ready for review April 25, 2022 20:33
@sipsma
sipsma requested a review from a team as a code owner April 25, 2022 20:33
@sipsma
sipsma requested review from dolanor and jpadams April 25, 2022 20:33
This is a simple fix for the issue of logs being duplicated when an
export is performed. The issue is caused by Buildkit's behavior of
"backfilling" newly connected clients on the progress so far of vertices
referenced by their build. This addresses it in the simplest way
possible by just filtering out progress log events from these separate
builds.

This works but is fragile. It works because we currently always set
Evaluate to true when running solves, which means that any progress logs
will already have been sent to the main solve channel and any that are
sent to the separate channel created for the export must be duplicates.

If we ever want to enable Evaluate being set to false, we will need a
different fix. I wrote that fix out, but it's a tangled web of
synchronization and to fully understand that it actually covers every
race-condition you need to know details about BuildKit's internal
implementation. Therefore, for now I just left a comment about all this
above the line where we set Evaluate to true and linked to the more
complicated fix in case it's ever needed.

The long-term, non-hacky fix to this is to add support for Export to the
GatewayAPI. For now though, this is our best option and is in fact what
Buildkit developers did when facing the same issue in buildx.

One last note, there technically are some logs that we may be dropping
due to this as it turns out buildkitd uses the progress log streams to
write temporary errors encountered during registry operations. I think
this is okay for now because retriable errors are a rare case and if
retries are exhausted the actual error message does get returned to the
client. We will only be missing out on some intermediary ones.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the log-dupe-simpler branch from 7d89188 to 1aa31ee Compare April 25, 2022 20:34
@sipsma
sipsma merged commit 2bcd0ac into dagger:main Apr 26, 2022
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.

Duplicate log messages

2 participants