Skip to content

integrate DagQL - #6297

Merged
vito merged 16 commits into
dagger:mainfrom
vito:dagql
Jan 13, 2024
Merged

vito merged 16 commits into
dagger:mainfrom
vito:dagql

Conversation

@vito

@vito vito commented Dec 19, 2023 •

Copy link
Copy Markdown
Contributor

This PR swaps out our GraphQL server infrastructure for DagQL.

notable changes

  • All objects are now ID-able. This is enforced by DagQL itself. They automatically get a FooID scalar type and a loadFooFromID root-level field.
  • IDs are now embedded pipelines (Save & load pipelines #3923), containing instructions for building an object rather than the object's content.
    • In general, IDs can be expected to be much smaller, but there are still cases where they'll get pretty large - so I don't consider this a total fix yet. (More details: add DagQL subtree #6405 (comment))
  • We now have a global query cache! No more ad-hoc caches for e.g. container.import and container.build - instead we use IDs as query cache keys. 🎉
    • Fields that should not be cached must be marked .Impure().
  • The GraphQL schema is now fully derived from core/schema/*.go code at runtime. We no longer need to maintain *.graphqls files.
    • We still commit a generated .graphqls file for our GraphQL schema docs, generated by ./hack/make docs:generate.
    • The docs:lint target ensures this is up-to-date, just like the SDK codegen lints.
    • This should also be pretty helpful for PR review since you can actually see the resulting schema change and review at the API level.
  • Module initialization has been split into two phases:
    • Module.withSource(source: Directory!, subpath: String): Module! installs the source directory and runs codegen
    • Module.initialize: Module! evaluates the entrypoint, which is where all the withObject and such are installed
    • This split was necessary because previously we were passing a ModuleID that literally contained the partially instantiated module content, but now we need an ID that refers to that intermediate state in order to run the entrypoint, so we pass the result of withSource along.
    • This simplified one thing: now if you want to download generated code even if it doesn't compile, you just call withSource.generatedCode.
  • I've started using log/slog in new code. Seems like we could switch to this instead of piggybacking on Buildkit's logging infra. Not sure though since we'll have to coexist with Buildkit's logs either way. Can be talked out of this.

goals

  • better telemetry / visualization
  • a stable, useful format for IDs
  • shorter IDs
  • saving and loading pipelines (Save & load pipelines #3923)
  • global query cache to replace ad-hoc caching (modules, container build/import)
  • a clean purpose-built GraphQL stack to replace our two forks

cleanups along the way

  • sockets now use a URI-like ID like unix:// and tcp:// instead of using a SocketID
  • secrets now use the secret name instead of a SecretID
  • rename TypeDefKind enums to match SHOUTY_GRAPHQL_STYLE
    • we should do this everywhere IMO but didn't want to add any non-Zenith breaking changes
  • added more tests for a couple of interface cases that weren't covered
  • module object fields are now Nullable in the API if they are pointers
  • Go SDK now panics on error instead of fmt.Println + os.Exit so we can tell which line errored
  • found a pre-existing bug with linkDependencyBlobs - not fixed here, opened an issue: 🐞 Blobs referenced by private fields in a module object can disappear #6406

replaces #6158

@sipsma

sipsma commented Dec 19, 2023

Copy link
Copy Markdown
Contributor

One immediate high-level thing: can we just put dagql in this repo too? It can be a separate package and all that, but it's easier to maintain in the long run when changes that require modifications to both this repo and dagql can be done in a single PR relative to splitting up, updating dependencies, etc.

@vito

vito commented Dec 19, 2023 •

Copy link
Copy Markdown
Contributor Author

@sipsma Sure thing - I just don't want to lose the commit history from the other repo. Once we're closer to the finish line I'll figure out all that bookkeeping. (Either a separate PR with DagQL + history, or pulling it into this PR with everything currently here squashed into a single commit on top, but merging un-squashed to preserve the DagQL history.)

@vito
vito requested review from a team as code owners January 13, 2024 01:19
@vito vito changed the title wip: integrate DagQL integrate DagQL Jan 13, 2024
@vito
vito requested review from helderco and jedevc January 13, 2024 01:19
@vito

vito commented Jan 13, 2024

Copy link
Copy Markdown
Contributor Author

Marked ready + requested reviews mostly as a "hey check this out if you have time + desire" - not trying to multiply the cost of reviewing such a huge PR, but you're more than welcome to obviously. 😅

Comment thread core/secret.go Outdated
Comment on lines 67 to 69

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.

I guess this whole doc string can be updated now since it's only ever a name thanks to the other changes

Comment thread core/typedef.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.

if possible would be better as an error just so we can avoid taking down everything, though admittedly it's hard to imagine this case getting hit, so not a big deal if changing to return an error is some huge wrench in everything.

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'd like to leave this as a panic for the sake code readability. We do these conversions in a few places and IMO it's nice for it to feel like this is a routine operation in a fully defined system, i.e. there's always a 1:1 conversion available from core.TypeDef to dagql.Typed/dagql.Input.

As a compromise I added a unit test that will run for every TypeDefKind and fail if a new Kind isn't handled. This should really only happen during dev/test time when we add a new Kind but haven't added integration test coverage yet, but covering everything at an integration level can be tricky, so these unit tests should be a decent safety net.

Comment thread core/typedef.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.

same as prev comment about avoiding panic if feasible

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

guessing this is just temporary, but in case not then probably want to prefix it with DAGGER_ and such

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

Haven't heard of this before, sounds neat 😄

Comment thread core/moddeps.go Outdated
Comment on lines 44 to 54

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.

What's the need for both of these? The order previously was irrelevant (at least, I thought it was) so curious if something changed

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.

It might not actually matter - but I noticed we were sometimes appending and sometimes prepending and assumed it might be significant, so I just did a quick refactor so I could identify it more easily while figuring out how everything worked.

This kinda sorta feels like a delegation hierarchy to me, and usually those are in some kind of precedence order, but yeah given how everything is namespaced without any overlap it really shouldn't matter.

Comment thread core/modfunc.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.

That's implemented now right?

@vito vito Jan 13, 2024 •

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.

Kind of - there's a prospective (*ID).Canonical() implementation but none of the fields set Meta() yet so nothing's impacted either way. I've also noticed Canonical() is pretty slow, so I'm wondering if we need a faster way to calculate it. Which also ties into whether/when we make IDs smaller by deduping them into a map[digest]ID where ID refers to its parent/arg/module IDs by digest instead of by embedding them, and the trade-offs involved. So it's a bit of a rabbit hole. 😅

More broadly I think there's a bit more to figure out with the whole 'canonicalizing IDs' mechanism - like whether/when it even makes sense to use a non-canonicalized ID, and whether loading an ID should attempt a cache store lookup against the canonicalized digest instead of just evaluating it and letting each selection hit the cache. (Pros: faster cache hits, cons: some of those "meta" fields work by installing state into the object, such as the current pipeline and focused state, so fields marked 'meta' are actually significant in a query cache, which makes me think they're actually more relevant when thinking about blobstore cache keys and such.)

I've been punting on this for now since the scope is pretty big already and the only immediate implication is busting the query cache, and right now they're not cached at all. Would definitely want to address all this sooner rather than later though.

Comment thread core/schema/sdk.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.

We previously allowed codegen and moduleRuntime to actually be cached (set Cache: true in CallOpts). IIUC that's probably not happening anymore because we now model this as a real module function call (which is great in and of itself, super cool we can do that now), but those are never cached (https://github.com/vito/dagger/blob/ce640898f4510fb82ece3c6a3f4ca33b8cbb268a/core/object.go#L337-L337)

I don't think this a huge blocking deal, but if I'm following everything correctly then it's probably somewhat of a performance hit. If it's possible to make these cached again would be nice.

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.

Ahh good catch, will take a look at this!

I also noticed the container.import call from the Go SDK is pretty slow, but I think it was slow before for the same reason - it's cached (previously in our one-off import cache, now in the query cache), but only locally to a session, and our integration tests use a bunch of different sessions so it's importing a ton of times. Would be pretty nice if we could somehow do that once on startup and base future calls on it. Or find a way to speed up the import when the content is already in the store. (I think we're mostly just paying a .tar streaming penalty.)

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.

Fixed in #6629

Comment thread core/query.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.

I'm not totally grok-ing what's going on here and it's usage, comment would be helpful.

e.g. the usage in ModuleObjectType.ConvertToSDKInput, you set baseDeps to the module deps + itself, then you provide this id and append all of it's modules too (plus including the core mod via default deps). Are you duplicating modules in the list? Or are they non-overlapping sets of modules?

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.

Turns out we don't need the baseDeps arg anymore! 🎉 It always felt fishy that it needed effort on both sides of the call.

In a nutshell, this is the secret sauce that allows IDs to bring-their-own-dependencies, so you can take an ID returned by a module and pass it to any other module where it'll be loaded using a throw-away *dagql.Server with all of the ID's dependencies installed.

This must have been fixed when I moved the dependency-tracking Module *idproto.ID field from dagql.Class[T] to dagql.FieldSpec, which allows fields like impl - which come from a different module than the class it's being installed onto - to correctly declare its dependent module.

Comment thread core/schema/host.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.

should be args.Uncompressed right?

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.

🤦‍♂️ yep

vito added 3 commits January 12, 2024 22:23
Signed-off-by: Alex Suraci <[email protected]>
The bang for your buck here, documentation wise, seems pretty good.
Would also help prevent copy-pasta.

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

@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.

Gonna preliminarily approve since everything left is either minor or do-able as follow ups. Want to get this out sooner than later so we can get the rebasing of everything else out of the way :-)

And as a general comment that really goes without saying, everything here is just incredibly cool and useful, amazing job. Getting control+specialization for our use case on this level of the stack up cleans up so much and sets us up for so much great stuff down the line 🚀

@vito

vito commented Jan 13, 2024

Copy link
Copy Markdown
Contributor Author

@sipsma Thanks so much for the thorough review despite the PR size - it definitely surfaced some valuable topics. 🙏

Since we just shipped yesterday, I'll go ahead and merge this so we can start the joyous process of rebasing other work in flight.

For continuity, here the high-level follow-ups I can gleam from the discussion so far:

@vito
vito merged commit d48f75a into dagger:main Jan 13, 2024
Comment thread core/schema/git.go
Comment on lines +133 to +134
SSHKnownHosts dagql.Optional[dagql.String] `name:"sshKnownHosts" deprecated:"This option should be passed to git() instead."`
SSHAuthSocket dagql.Optional[core.SocketID] `name:"sshAuthSocket" deprecated:"This option should be passed to git() instead."`

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.

Somehow these deprecated options don't end up propagating into dagger.gen.go. These two fields also don't have docs in Install, so there's no information on them.

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.

good catch, taking a look!

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.

Looks like this wasn't making it to the client before, either; the introspection query it uses doesn't select the isDeprecated or deprecationReason fields.

Weirdly enough neither does the Apollo GraphQL sandbox explorer (left is v0.9.6, right is local dev):

image

(Placeholder docs added on the right just to suss out any "maybe it only shows directives if there are docs" nonsense)

Seems like we need to either update SDK codegen to look for @deprecated or manually set a description. The latter seems like less work for everyone in the grand scheme of things. Maybe setting something to deprecated could default its description to DEPRECATED: <deprecation reason>?

@jedevc jedevc added this to the v0.9.7 milestone Jan 15, 2024
@vito
vito deleted the dagql branch January 15, 2024 17:40
@vito vito mentioned this pull request Jan 15, 2024
Comment thread sdk/python/src/dagger/client/gen.py Resolved
zeroware pushed a commit to zeroware/dagger that referenced this pull request Jan 18, 2024
* integrate DagQL

* all schemas now execute using a dagql.Server, which replaces the
  previous GraphQL stack (built upon two forks)
  * all objects are now ID-able, and all objects now have loadFooFromID
* a single query cache is shared between all dagql.Servers within a
  session
* most dependencies have now moved to Query, which is embedded by all
  objects and dramatically improves code quality
  * Objects are now self-contained; no more passing around millions of
    arguments (s.bk, s.svcs)
  * Query effectively represents the "root" of the Dagger session.
* use a connection URL for Buildkit socket IDs
  * Untying this knot lets us move socket code back into the regular
    core package.
* core API schema is fully derived from runtime definitions
  * the generated schema SDL is still commit for documentation purposes.
    each PR that changes the API must update it with docs:generate for
    the docs:lint to pass.
* wire up experimental ID-based telemetry
  * run CLI with IDS=true to see it
  * telemetry is skipped for introspection resolvers (__schema,
    current*) because they're too expensive (many, many paths). a test
    actually failed because of the perf hit here. obviously worth
    optimizing to the point where it's not a concern.
* add blob() API, used by host.directory() and host.file()
  * Previously host.directory would return a core.Directory that embeds
    a blob:// LLB reference. This made sense before because the
    core.Directory's content was used as a key.
  * In DagQL, IDs no longer embed the content itself, so this no longer
    works. The solution here is to have an impure API that returns a
    pure ID blob (host.directory(path:...) => blob(digest:...)).
* rework Zenith module initialization flow
  * Previously the module entrypoint would be executed with
    currentModule() set to a ModuleID that embeds the
    partially-instantiated core.Module.
  * Same as before, this no longer works because IDs are now recipes,
    not content.
  * The fix here is to split module initialization into two steps:
    * Module.withSource which loads the module config, sets up metadata
      (name, description, sourceDirectory, etc) and assigns the
      generatedCode and runtime.
    * Module.initialize which executes the module's entrypoint with the
      previous result available as currentModule(), since it has a
      proper ID.
    * dagger mod sync now fetches the generated code from the result of
      Module.withSource; Module.initialize is allowed to simplfy fail if
      code doesn't compile.
* fixed a few tests that seemed to be testing modules that take list of
  strings, but were passing a single string in GraphQL.
  * This seems like it was a bug, where our query parsing was way too
    permissive, but our tests were consistently written this way, so I'm
    not 100% sure.
* reimplement Go SDK in terms of external API
  * Previously the Go SDK was implemented by directly calling internal
    core/ APIs. Now it strings together APIs from the "outside" using
    dagql.Select.
  * This allows us to leverage caching, at least locally to each server,
    but it still isn't quite a silver bullet; the container image still
    gets imported for each Dagger server, which seems slow, but I think
    it's just as slow as before, since each container import cache was
    also per-server.
* renames the TypeDefKinds to use SHOUTY_ENUM syntax.
  * we should do this for all of our enums, but that'd be breaking, not
    worth doing now
  * sdk/rust: use PascalCase enums that serialize to their original enum
    value.
* prevents secret values from ending up in IDs, using ArgSecret()
* sdk/nodejs: don't bother using ID type
  * this doesn't exist in DagQL, but it might someday. but we can just
    use a string here anyway.
* sdk/elixir: handle lists of objects, loadFoorFromID
* sdk/elixir: stop using deprecated secret API.
* sdk/java: avoid second-order exception when failing to parse fields.
* allow object fields to be optional
* added more tests for interfaces.

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

* mark Container.export impure

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

* fmt imports

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

* wire slog up to logrus

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

* add ID-centric progrock frontend

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

* fix Java SDK handling of list of objects

and update README to make generated code easier to find

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

* clarify labels.LabelUncompressed usage

Co-authored-by: Erik Sipsma <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>

* nix extra clones

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

* blob(): validate digests

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

* setSecretFile is impure, returns pure Secret

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

* dagql: Impure() requires a reason

The bang for your buck here, documentation wise, seems pretty good.
Would also help prevent copy-pasta.

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

* add basic test to catch TypeDef conversion panics

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

* rename NullableType fields for clarity

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

* simplify/clarify SourceMod checks

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

* update GetSecret doc string

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

* document + clean up IDDeps

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

---------

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
@helderco helderco mentioned this pull request Apr 3, 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