Skip to content

propagate progrock parents - #6456

Merged
vito merged 10 commits into
dagger:mainfrom
vito:progrock-parents
Jan 26, 2024
Merged

vito merged 10 commits into
dagger:mainfrom
vito:progrock-parents

Conversation

@vito

@vito vito commented Jan 19, 2024

Copy link
Copy Markdown
Contributor

These are the necessary changes for the Zenith visualization experiments I've been working on. I figure we can sneak these out even if we don't have anything that uses them yet, just to have the ability to record a journal file and test the new UI/TUI against it.

The only real change is that Progrock now supports parent/child vertex relationships, which are analogous to parent/child spans in OpenTelemetry. The DagQL telemetry now uses this instead of the weird group-that's-really-a-vertex from before, which was also contributing to a lot of noisy output. Now when a resolver performs a self-call or runs something with Buildkit, the resulting vertices will be children of the calling vertex.

Most of the effort is just getting the parent vertex ID plumbed through all the right places for nesting/modules. If/when we want to add support for OpenTelemetry, this is a good breadcrumb trail to follow. I took a swing at it but couldn't quite get it to work how I wanted to so I backed out for now.

@vito
vito force-pushed the progrock-parents branch from ba44e0a to b3afa96 Compare January 19, 2024 20:47
@vito
vito requested a review from sipsma January 21, 2024 19:17
@vito

vito commented Jan 22, 2024

Copy link
Copy Markdown
Contributor Author

Weird that the tests seem to be timing out from this. Happened on a re-run too. 🤔 Investigating locally!

Comment thread engine/client/client.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.

It seems like this is what we were doing before so not a big deal, but I did just realize we set c.Recorder both here and above on line 147 and am confused now why (or if we actually need to in both places).

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.

Yeah I can't see a good reason to, and I obviously just kept pattern-matching here, guessing it ended up this way through little changes over time. I think at one point there was a local recorder := var involved, and it was consolidated to just c.Recorder since it ended up being assigned to it anyway. Will clean up

@vito
vito force-pushed the progrock-parents branch from b3afa96 to 8317455 Compare January 24, 2024 15:10
@vito

vito commented Jan 24, 2024 •

Copy link
Copy Markdown
Contributor Author

Still a bit confounded by the CI failures for this one.

TestDirectoryMerge in particular seems to consistently fail as it sees a different inode post-MergeOp:

Beyond that I've been seeing failed to compute cache key: context canceled on seemingly random tests. All of these tests seem pretty unrelated to these changes. 🤔

edit: whoa, nevermind, I can repro TestDirectoryMerge locally 👀

@vito
vito force-pushed the progrock-parents branch from 8317455 to 9b89f88 Compare January 24, 2024 19:45
@vito

vito commented Jan 24, 2024

Copy link
Copy Markdown
Contributor Author

Ok, weird, the TestDirectoryDirectMerge test failure is legit, and stems from this change which just adds the parent Progrock vertex ID to the ftp_proxy shim (ContainerExecUncachedMetadata):

ProgParent: progrock.FromContext(ctx).Parent,

I thought changes within that value wouldn't bust any caches, since that's the whole point of the ftp_proxy trick, but it seems to be the case. If I put a time.Now().String() in there it also busts the cache, and it seems like that shouldn't happen either.

Does this mean we're actually busting caches across sessions right now, since ContainerExecUncachedMetadata contains all kinds of ephemeral stuff? Wouldn't that mean basically no cache hits for execs in Dagger Cloud?

Maybe there's something in the Buildkit plumbing that's caching by Op digest instead of by CacheKey? But that should have been an issue before, too... cc @jedevc @sipsma to check my sanity

@sipsma

sipsma commented Jan 24, 2024

Copy link
Copy Markdown
Contributor

@vito very very confused right now too, can repro the same thing of putting random data in the FtpProxy settings causing TestDirectoryDirectMerge to fail (even on main), but I at least believe that it's not completely broken in the sense that I can see caching working across sessions.

The existing TestRemoteCache* tests implicitly cover this and out of caution I also added a dumb test locally off main:

func TestTODO(t *testing.T) {
	t.Parallel()
	c1, ctx1 := connect(t)
	_, err := c1.Container().From(alpineImage).
		WithMountedDirectory("/src", c1.Directory()).
		WithExec([]string{"sleep", "5"}).
		WithExec([]string{"sleep", "5"}).
		Sync(ctx1)
	require.NoError(t, err)
	c1.Close()

	c2, ctx2 := connect(t)
	_, err = c2.Container().From(alpineImage).
		WithMountedDirectory("/src", c2.Directory()).
		WithExec([]string{"sleep", "5"}).
		WithExec([]string{"sleep", "5"}).
		Sync(ctx2)
	require.NoError(t, err)
}

And can see that even if I put completely random data in the ftp proxy settings, starting w/ empty cache it only runs just over 10s (i.e. second client is cached) and re-running the test only takes a little over 1s.

So at least we have that 😮‍💨

I'll dig a bit more into what could be happening in that DirectMerge test case specifically.

@sipsma

sipsma commented Jan 24, 2024 •

Copy link
Copy Markdown
Contributor

@vito Hit my current timebox but will revisit ASAP, what I've found so far:

Caching across sessions, even with completely random data in ftp proxy is working completely as expected. E.g. if you do a local run of TestDirectoryDirectMerge on main to warm the cache, then make a change to have ftp proxy have random data and re-run the test (without clearing the cache), it passes just fine.

The problem I'm seeing is that having random data in there that changes within the session appears to invalidate the cache of any other calls in the session. So with a change to have random data in ftp proxy that changes each solve call, then there won't be cache hits on the WithExec and the Stdout calls to a container...? Unless they were already cached from a previous session, in which case it works?

Not sure what's going on here. Feel somewhat reassured that our existing usage is okay because all the stuff we put in there was unchanging within the context of a single session, but it makes no sense to me yet that data changing in a session (like the use case here) would impact this...

@sipsma

sipsma commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Picked this back up for a while.

Basically, within the context of a single session buildkit's solver does not seem to de-duplicate two vertices that have different digests but resolve to the same cache map. Across sessions it's fine, just doesn't work within one session it seems. You only get de-duping within the session if the vertex digests exactly match.

It checks whether it can re-use an existing state here based on the vertex digest. In our case, we have ExecOps with differing vertex digests but some deps with static vertex digests (the base image, the meta mount), so the solver gets into a state where some of the states of deps are re-used but not the ExecOp itself.

As far as I can tell, this just isn't handled in the solver logic. When the exec op is supposed to probe cache of deps here, I'm seeing that the edgeState always have 0 keys, so it doesn't probe. That results in dep.keys to be of length 0, which also results the other call to probeCache here to always exit early because there are no keys.

Disclaimer: I have fairly low confidence in this. It's too convoluted to know anything.

If I'm on the right track, this feels like a bug. I gave a shot at fixing by updating e.keys and e.cacheRecords in execOp (different than the LLB ExecOp btw) here, but while it resulted in probeCache being called when I'd expect it to, it was with keys that didn't return results. Did not dig in any further than that.

cc @jedevc (know you have been looking in this area, just in case you have any ideas).


@vito in the spirit of abandoning all hope, we may want to assume that the limit of the ftp proxy hack is data that doesn't change across a session, unfortunately...

I can imagine at least one way to maybe get this to work without radical changes, which would be that you continue to store the ProgrockParent in the CallerContext, but then set up plumbing so that the progrock server has access to that and when it receives messages it checks the grpc metadata, figures out the caller context and then sets the parent based on that (if that makes any sense).

Obviously we need a new general approach here. I thought through a few other things that might be possible in the short-ish term, but they didn't pan out. Clearly on thin ice at the moment though.

@jedevc

jedevc commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heads up - some of the failures could definitely be related to having taken #6481 yesterday. I've seen the same kind of deadlocks as before - unfortunately this one seems persistently tricky to repro locally, so I'm going to spend some time improving our engine deadlock handling.

If I'm on the right track, this feels like a bug. I gave a shot at fixing by updating e.keys and e.cacheRecords in execOp (different than the LLB ExecOp btw) here, but while it resulted in probeCache being called when I'd expect it to, it was with keys that didn't return results. Did not dig in any further than that.

This definitely feels strange. Don't have context for this exact convoluted code path but my prior observations:

  • The solver de-deupes vertexes with the same digest - we never hit this for exec ops because of our FTP proxy hack. This seems to be at the solver level, not per-job.
  • The scheduler merges edges that have the same cache key. This also seems to be at the solver level - I know this because in my fixes in scheduler: always edge merge in one direction moby/buildkit#4559, we do this all in the context of one job. This is what we rely on for all of our deduping behavior for exec ops.

@sipsma

sipsma commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

The scheduler merges edges that have the same cache key. This also seems to be at the solver level - I know this because in my fixes in moby/buildkit#4559, we do this all in the context of one job. This is what we rely on for all of our deduping behavior for exec ops.

Yeah that's the other thing, I do see edges being merged in the logs, but only after the duplicated exec has already run 🤷‍♂️

@vito

vito commented Jan 25, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks both of you for investigating! I'll see what I can do.

We've also been having lurking issues with Progrock events not draining properly, and I've been meaning to get around to that, so I'll look for an opportunity to clean that up along the way (knowing full well that might be another pandora's box...).

@vito
vito force-pushed the progrock-parents branch from 1d09d70 to c2ec68e Compare January 25, 2024 20:18
@vito

vito commented Jan 25, 2024 •

Copy link
Copy Markdown
Contributor Author

Turns out we can just delete the accursed Progrock socket forwarding from the shim entirely!

I'm not sure when exactly this became possible, but it turns out 99% of the progress output is making its way out via the API server anyway, which the shim already connects to using ModuleCallerDigest, which already points core/schema/schema.go to the ProgrockParent via the ClientCallContext.

I did a diff of vertex name occurrences between journals before/after this change (c2ec68e), and this is the only delta:

11,12c11
<       2 check hut14q0g6ablk.ei5211547ktm4.dagger.local 1234/tcp
<      12 checkVersionCompatibility
---
>       2 check hut14q0g6ablk.b51rbqli15fg4.dagger.local 1234/tcp
14c13
<      40 connect
---
>       2 connect
22c21
<      16 defaultPlatform
---
>       2 defaultPlatform
  • checkVersionCompatibility was coming from the dagger.Connect in cmd/codegen
    • this is no big loss, especially since these codegen calls are already bundled with the engine; we could probably just skip the check entirely
  • connect and defaultPlatform were coming from engine/client/client.go and are just part of connecting + health-checking
    • also no big loss, it's kind of confusing seeing these at all really

So it seems completely worth just nuking this hairy progress forwarding code path from orbit.

The biggest difference is that codegen progress just goes to stdout of the codegen command, which is a whole lot simpler. Kind of surprised I even bothered with all the progrock forwarding before. 🤷‍♂️

@sipsma sipsma left a comment

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.

Looks great, glad we could tear out all that plumbing!

vito added 10 commits January 25, 2024 20:13
progrock now supports parent/child vertex relationships which are
mechanically very similar to groups, but which result in otel-style span
semantics instead.

this change adopts it for the DagQL telemetry func and propagates the
value through module function calls.

Signed-off-by: Alex Suraci <[email protected]>
not worth the perf hit yet, but this seems like code we might want
someday

Signed-off-by: Alex Suraci <[email protected]>
rather than making an 'init' group and putting a singleton
'starting-engine' vertex in it, now we have a separate vertex for each
time we call connect, which happens repeatedly with nesting scenarios
like Zenith; feels weird to lie about it by making them all have the
same vertex ID.

Signed-off-by: Alex Suraci <[email protected]>
expected comes first

Signed-off-by: Alex Suraci <[email protected]>
turns out we don't actually need this anymore! the only events it's been
forwarding are internal engine calls, i.e. the following vertices:

* connect
* checkVersionCompatibility(...)
* defaultPlatform

all of the juicy progress is actually already forwarded and associated
to the correct parent via the ClientCallContext plumbing in
core/schema/schema.go

Signed-off-by: Alex Suraci <[email protected]>
not worth whatever amount of time this spends since we're guaranteed to
be pointing to a compatible version anyway.

Signed-off-by: Alex Suraci <[email protected]>
purely DX driven. otherwise loadModuleFromID shows up in the progress
output which feels kinda clunky.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 2beae4e into dagger:main Jan 26, 2024
@vito
vito deleted the progrock-parents branch January 26, 2024 02:59
@gerhard gerhard added this to the v0.9.8 milestone Jan 26, 2024
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.

4 participants