Skip to content

add DagQL subtree - #6405

Merged
vito merged 100 commits into
dagger:mainfrom
vito:add-dagql
Jan 12, 2024
Merged

vito merged 100 commits into
dagger:mainfrom
vito:add-dagql

Conversation

@vito

@vito vito commented Jan 11, 2024 •

Copy link
Copy Markdown
Contributor

This PR merges in the full DagQL repository as a toplevel dagql/ subdirectory, keeping its history intact.

I know we usually do squashed commits for PRs but this feels like a bit of a special case where I'd prefer to keep the git blame since some of the commits have a lot of explanation. In total it's 💯 commits which is pretty nice.

prerequisite for #6297

vito added 30 commits January 11, 2024 10:22
Signed-off-by: Alex Suraci <[email protected]>
* start using github.com/vektah/gqlparser/v2 and adopting its types
* build up a schema as types are installed
* start introducing Class/Object terminology
* throw abstractions around until things fall into place
* think I may have gone overboard with generics, but committing for now
* start establishing boundaries
  * new Typed interface for keeping track of a value's type
    * including Builtins (int -> Int, TODO Boolean/String/etc.)
  * Node is Typed
  * Server queries a Node Field and returns a tree of Typed values
    * no more returning primitives
    * we'll handle marhsaling back to JSON somewhere else
* switch to gotest.tools/v3/assert since it has nice equality helpers
  with cmp (and protocmp)

up next:

* meta and pure/cache-mode should be schema directives, figure out how
  functions indicate this
* speaking of directives, support deprecated fields
* instead of Install + ObjectFields + Func helper, consider just
  installing a type and crawling its public methods.
* write GraphQL queries in tests, start testing more things once that
  high-level API exists
* support descriptions on everything
* figure out how scalars actually work, may need to relate to ast.Value

Signed-off-by: Alex Suraci <[email protected]>
this isn't perfect, but feels like a good boundary for implementation.

Signed-off-by: Alex Suraci <[email protected]>
we're skipping over the nicely abstracted Server boundary here, but it's
worth it for the brevity

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* ID selectors may now specify an *nth* field (1 indexed) to return an
  object from an array return value.
  * This approach builds on the fact that array results should also be
    deterministic, so that we can safely refer to any value.
* refactor Typed to return full *ast.Type
* Resolver > Node rather than Node > Resolver
* ObjectNode -> Object

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* Server installs introspection types + fields
* implement Nullable resolver semantics

need to go on a detour to implement fragments

Signed-off-by: Alex Suraci <[email protected]>
* support fragment spreads
* fix subtle nil vs [] behavior
* fix FooID type not actually being installed into schema
* Resolver -> Selectable, idk, wanted to avoid clash with Server but
  then ended up adding Select there too, needs another look
* move introspection code to introspection/ package
* implement more JSON marshalers

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
got a little ahead of myself

Signed-off-by: Alex Suraci <[email protected]>
this is a fundamental building block, otherwise even loadFooFromID would
return the right value but with an ID that referring to loadFooFromID
itself

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* get rid of nonsensical TypeResolver interface in favor of distinct
  Scalar and Class interfaces
* get rid of Literal Marshaler/Unmarshaler interface
* Literal type is gone; Typed and Scalar take its place

Signed-off-by: Alex Suraci <[email protected]>
Instead of requiring all Scalar types to implement Kind, we use the
Literate interface, and define how to translate this bounded domain to
an ast.Value

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

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
not really fully baked yet, haven't tried passing them as inputs

Signed-off-by: Alex Suraci <[email protected]>
* allows you to pre-define var values instead of using strings
  everywhere
* allows you to defer Scalar implementation to a single common
  implementation (Enum[T])
* split ScalarClass out of Scalar
* Instantiator -> ObjectClass for symmetry

Signed-off-by: Alex Suraci <[email protected]>
* Scalar has Class() instead of always implementing it
  * builtins just return their zero value
  * enums define this to return their class, which is defined separately
  * possible refactors here now that an Enum can just get its Class.
* ScalarClass.New is now used to parse defaults, which just makes so
  much more sense, and removes the coupling to JSON
* bad ArgSpec is now a runtime error, which means you'll hit the error
  later, but that seems OK since you should really have tests for all
  this anyway.
* test builtin defaults, which is currently surfacing a lot of
  verbosity, could be worth refactoring

Signed-off-by: Alex Suraci <[email protected]>
* add a toSelectable helper so ObjectClass.New never has to deal with
  other types (in keeping with the custom around Nullable values)
* move some code around to better homes

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* use github.com/sourcegraph/conc which also handles panics for us
* test parallelism, and test returning all errors instead of first
* misc refactors

Signed-off-by: Alex Suraci <[email protected]>
GraphQL schemas make more sense when the fields are returned in the
order intended by the schema designer, so this type must preserve it.

As a positive side effect, funcs and FieldSpecs know their own name now,
which could be helpful for error messages.

Signed-off-by: Alex Suraci <[email protected]>
* types can now bring their own Definition() or Description()
* Scheme() now builds the *ast.Scheme on-the-fly
* dependence on gqlparser prelude is gone
* TODO: make schema-building + installing thread-safe
* TODO: cache schema-building between installs
* TODO: stable field order

Signed-off-by: Alex Suraci <[email protected]>
need for this was removed and amended into commit

Signed-off-by: Alex Suraci <[email protected]>
vito added 3 commits January 11, 2024 10:22
just about every SDK was blowing up if a null value was present here, so
let's just enforce empty string instead

Signed-off-by: Alex Suraci <[email protected]>
also fix pesky slog import

Signed-off-by: Alex Suraci <[email protected]>
vito added 2 commits January 11, 2024 10:32
out of date, we can decide whether to switch later

Signed-off-by: Alex Suraci <[email protected]>
Comment thread dagql/idproto/id.proto Outdated

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 we'll want to change this pretty soon to be more compact. It's really easy to have arguments or parents that depend on the same ID by carrying it around wholesale, inflating the ID payload through repetition. This is especially common now that IDs contain a reference to their originating module.

We should probably restructure this using a flat map[digest.Digest]ID and have embedded IDs reference digests instead.

@vito vito mentioned this pull request Jan 11, 2024
Comment thread dagql/server.go Outdated

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.

There's some low-hanging-fruit optimizations possible here, e.g. when we're loading an ID we could do a direct cache lookup for the final ID instead of re-evaluating it and going through N cache hits for the depth of the ID. Just kept it simple for now.

@sipsma

sipsma commented Jan 11, 2024

Copy link
Copy Markdown
Contributor

(Gonna leave comments one by one so you can get back as I continue to review, so sorry if there's a lot of notification noise)

Comment thread dagql/README.md 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.

This includes IDs with local dir blobs, in memory secrets, etc.? If so, then I guess while it can be loaded on a server, that doesn't mean it necessarily works right? Just checking

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 true

Comment thread dagql/ioctx/ioctx.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.

This is only used for pipes and the demo right? Just checking whether it's purely that or if you think this has more general utility

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 there's general utility, but nothing important hinges on it at the moment. We can use this in Dagger to allow a resolver to write arbitrary logs to telemetry. As an alternative we could put the full *progrock.Vertex in context.Context and access its .Stdout and .Stderr instead, but reducing that down to stdout/stderr streams felt slightly better/more future-proof.

Comment thread dagql/server.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.

nit: having looked at this for ~5 seconds it's not clear to me what it's purpose is, which is my approximate threshold for a comment on it being helpful :-)

Comment thread dagql/server.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.

To clarify, this is saying that Query itself isn't id-able 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!

Comment thread dagql/server.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 guessing this is for the SetSecret case? And there's no problems with the value here not being part of the ID? It can still make its way to the actual implementation that stores the secret in the store even when not in the ID?

@vito vito Jan 11, 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.

Yep exactly.

So for SetSecret there's a particular dance you have to do to get it all to work.

  1. User calls SetSecret with spooky plaintext credentials. DagQL avoids putting those into an ID, so we can be sure it never ends up being sent over the wire or busting cache keys.
  2. The SetSecret field is marked Impure(), so we don't have to worry about that "redacted" ID resulting in a cache hit if you call SetSecret twice with different credentials.
  3. But that also means any IDs depending on SetSecret would become impure. So instead the SetSecret resolver performs its side-effect (installing the secret) and then returns the result of querying secret(name:...) instead. So this is a case of an impure resolver returning a pure result.

Comment thread dagql/idproto/id.proto 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 think the comment is cut off here maybe? Which left me waiting in anticipation because I was wondering about whether Enumerable values were indexed starting at 1 or 0 😄

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.

lol, yes unfortunately they are indexed starting with 1. 😂 I regret that decision, we should probably undo it.

Comment thread dagql/types.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.

still needed?

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, removed

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

Very far from thorough review but got enough of a gist, all super cool and extremely glad we have more control on this level of things now (rather than fighting an eternal war against the other graphql server implementation). Seems like it will unlock all sorts of cool things in the long term besides the immediate benefits 😎

@vito
vito merged commit 674feb3 into dagger:main Jan 12, 2024
@vito
vito deleted the add-dagql branch January 12, 2024 15:39
Comment thread dagql/objects.go
Comment on lines +117 to +123
// Definition returns the schema definition of the class.
//
// The definition is derived from the type name, description, and fields. The
// type may implement Definitive or Descriptive to provide more information.
//
// Each currently defined field is installed on the returned definition.
func (cls Class[T]) TypeDefinition() *ast.Definition {

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.

nit: here, and quite a few other places in this file the doc-string refers to the wrong method name. Definition => TypeDefinition.

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.

woops, will patch that up - thanks!

@vito vito mentioned this pull request Jan 15, 2024
Comment thread dagql/cachemap.go

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.

How is this file different to the one in core/cachemap.go?

Can we deduplicate them somehow into one common set of utils?

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.

Oh yeah these can be deduped. Only issue is that we'd have a circular dependency between core/ and dagql/ so we'd need to move it elsewhere.

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.

3 participants