Repository navigation
solver: fix duplicate logs on export - #2267
Conversation
There was a problem hiding this comment.
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
clientto do anAddReffor every singleSolveever 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
completedimmediately. 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 theAddRef).
I'm wondering if this approach makes sense, in your opinion?
There was a problem hiding this comment.
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.
95ff831 to
7d89188
Compare
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]>
7d89188 to
1aa31ee
Compare
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.