Repository navigation
Better errors, cached states, pending states, duration accounting, fewer spans - #8442
Conversation
d614d7e to
dda05d6
Compare
|
@shykes @marcosnils I implemented a minimal API for error returns from functions. It was either that or keep doing janky workarounds so I figured I'd take a swing at it - which I was originally going to do in #7833 before getting stuck on other things. The basic idea is to have functions return a proper type Query {
# Construct an Error value to be returned by a function.
error(message: String!): Error!
}
type Error {
id: ErrorID!
# A brief description of the error.
message: String!
}
type FunctionCall {
# Return an error from the function.
returnError(error: ErrorID!): Void
}Internally this works by having End result: v0.13.0 for comparison: The main question (for this PR): is this API agreeable enough to ship as an MVP? Broader question: can we envision building on this to satisfy the "error reports" use case? For example, by supporting multiple errors, or hierarchical errors, or other extensions to the Putting my cards on the table: sticking with "return a value OR an error" seems familiar and conventional to me, so it'd be pretty convenient if every use case that motivated #8421 (lints, tests, ???) neatly fit into a rich There's also a lot of inspiration from Go's "errors ARE values" idea here - we could even have Connecting dots: (edit: let's bikeshed there to keep this PR focused on the minimal change, will copy/paste) cc @sipsma |
8e8972c to
2b39b21
Compare
| // FIXME: there appears to be some delay before a cache is able to be hit | ||
| // by a separate session. no clue where this comes from (sorry) but a 10 | ||
| // second wait passed 25 times in a row. | ||
| time.Sleep(10 * time.Second) |
There was a problem hiding this comment.
@sipsma Any idea what might be causing this? tl;dr if you run two dagger call commands back to back quickly enough it's very possible for the second call to have cache misses, but if you wait ~10+ seconds you'll get cache hits.
There was a problem hiding this comment.
No immediate clue, that's very surprising and a great find. I don't see us doing anything asynchronously in our session shutdown: https://github.com/sipsma/dagger/blob/22e6902807be2bcb6f1503d9e1643494d9f578c5/engine/server/session.go#L283-L283
Highly possibly buildkit is throwing some cleanup into an async goroutine, but even then I didn't think there was any part of the caching specifically that would only kick in async like that... 🤔
Can you easily repro this with some dagger calls on your host?
There was a problem hiding this comment.
@sipsma Thanks for taking a look!
Can you easily repro this with some
dagger callson your host?
Strangely enough, I can't. 🤔 And if I run these tests outside of Dagger against ./hack/dev they pass just fine without the 10 second sleep. It only fails when running in Dagger, against an engine running in Dagger.
I'm gonna keep poking at this since it's causing the tests to fail in CI. Will let you know if I find anything.
There was a problem hiding this comment.
Seems to be related to concurrency, somehow, even with seemingly non-overlapping pipelines. (edit: one caveat being that they're the same module, so there's overlap up until the actual function call)
Fails immediately without the 10 second wait:
# runs use-exec-service and use-no-exec-service in parallel
#
dagger-dev call test telemetry --run '//service'Passes repeatedly:
# using a loop instead of --count to ensure a fresh engine each time
while dagger-dev call test telemetry --run '//use-exec-service'; and sleep 1; echo ok: (date); endThese two pipelines do not overlap at all - one descends from redis and the other descends from alpine and busybox:
func (*Viztest) NoExecService() *dagger.Service {
return dag.Container().
From("redis").
WithExposedPort(6379). // TODO: would be great to infer this
AsService()
}
func (v *Viztest) UseNoExecService(ctx context.Context) (string, error) {
return dag.Container().
From("redis").
WithServiceBinding("redis", v.NoExecService()).
WithEnvVariable("NOW", time.Now().String()).
WithExec([]string{"redis-cli", "-h", "redis", "ping"}).
Stdout(ctx)
}func (*Viztest) ExecService() *dagger.Service {
return dag.Container().
From("busybox").
WithExec([]string{"echo", "im cached for good"}).
WithExec([]string{"echo", "im also cached for good"}).
WithExec([]string{"echo", "im a buster", time.Now().String()}).
WithExec([]string{"sleep", "1"}).
WithExec([]string{"echo", "im busted by that buster"}).
WithNewFile("/srv/index.html", "<h1>hello, world!</h1>").
WithExec([]string{"httpd", "-v", "-h", "/srv", "-f"}).
WithExposedPort(80).
AsService()
}
func (v *Viztest) UseExecService(ctx context.Context) error {
_, err := dag.Container().
From("alpine").
WithServiceBinding("exec-service", v.ExecService()).
WithEnvVariable("NOW", time.Now().String()).
WithExec([]string{"wget", "-q", "-O-", "http://exec-service"}).
Sync(ctx)
return err
}Despite that, the issue only happens when they both run. And it fails reliably.
Overall there should be four sessions involved:
- A: use-exec-service warmup
- B: use-no-exec-service warmup
- C: use-exec-service test
- D: use-no-exec-service test
Normally A and B warm the cache so that when C and D run they have a predictable view of things for test assertions. Timing wise the two are within the same ballpark, one doesn't seem decidedly faster or slower than the other.
Still no idea what would cause this to happen, seems like parallel sessions is the only clue. CI has been failing even with the 10 second sleep, so it doesn't seem like I'm out of the woods yet.
There was a problem hiding this comment.
Seems interesting that I'm able to run these two pending examples in parallel just fine, but not in parallel with either of the service examples. Adding a service test to the mix makes both of them see cache misses.
- ✅ pending, ✅ pending-duped
- ❌ pending, ❌ pending-duped, ✅ use-no-exec-service
- ❌ pending, ❌ pending-duped, ❌ use-exec-service
Maybe something gateway-related?
func (*Viztest) Pending(ctx context.Context) error {
_, err := dag.Container().
From("alpine").
WithExec([]string{"echo", "pending cached for good"}).
WithExec([]string{"echo", "im also cached for good"}).
WithEnvVariable("NOW", time.Now().String()).
WithExec([]string{"sleep", "1"}). // wait a bit to help eyeballing
WithExec([]string{"false"}). // fail the pipeline
WithExec([]string{"sleep", "1"}). // will be pending at the end
Sync(ctx)
return err
}
func (*Viztest) PendingDuped(ctx context.Context) error {
_, err := dag.Container().
From("alpine").
WithExec([]string{"echo", "pending duped cached for good"}).
WithExec([]string{"echo", "im also cached for good"}).
WithEnvVariable("NOW", time.Now().String()).
WithExec([]string{"sleep", "1"}). // wait a bit to help eyeballing
WithExec([]string{"false"}). // fail the pipeline
WithExec([]string{"sleep", "1"}). // will be pending at the end
Sync(ctx)
return err
}There was a problem hiding this comment.
For now, I've refactored the CACHED state tests out into separate examples (prob the right thing to do anyway) and configured them to just skip if a failure is detected (Flaky: true).
ffd395b to
c1dc7bf
Compare
30831a6 to
5590da4
Compare
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
|
@sipsma This should be good to go. There's more polish I could do but I think this PR has gone long enough at this point. 😅 Probably worth pointing out this change in particular:
Tried some other approaches, for example unwrapping in the OTel plumbing so that span errors are only the base error without stdout/stderr, but we lose the wrapping type info when returning an API error from a function, since it just gets marshalled to a string. In the end I think just ripping off this band-aid (in a controlled manner that doesn't break non-module use cases) is necessary for getting a less noisy error UI. |
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
| // +optional | ||
| verbose bool, | ||
| ) (*dagger.Directory, error) { | ||
| engine := t.Dagger.Engine(). |
There was a problem hiding this comment.
nit: a lot of this logic seems shared with testCmd?
There was a problem hiding this comment.
Yeah could probably be refactored or done differently - I didn't want all of testCmd because I wanted a faster feedback loop and that does some other stuff I don't need, like building an engine tarball. I spent time trying to figure out how to dedupe but think I ended up wasting too much time on silly things and decided to just duplicate for now.
There was a problem hiding this comment.
No worries, I'll probably take a look at it at "some point in the future" if that's okay with you 🫡
| // TODO: avoid breaking chains | ||
| // if opts.TooFastThreshold > 0 && | ||
| // span.ActiveDuration(time.Now()) < opts.TooFastThreshold && | ||
| // opts.Verbosity < ShowSpammyVerbosity { | ||
| // // ignore fast steps; signal:noise is too poor | ||
| // return false | ||
| // } |
There was a problem hiding this comment.
So just to confirm - we now always show previous "spammy" spans? Since not showing them could result in broken chains?
There was a problem hiding this comment.
Yeah - now that we have a "pending" state we actually want to show most spammy spans, otherwise you wouldn't see the pending state.
I'm going to experiment more with this - I think we probably want to hide entire pipeline chains that took less than some threshold, instead of individual spans.
| mc := propagation.MapCarrier{} | ||
| telemetry.Propagator.Inject(ctx, mc) | ||
| return llb.WithDescription(mc) | ||
| } |
There was a problem hiding this comment.
Sorry, struggling to understand what the effect of calling this actually is 😅
There was a problem hiding this comment.
This stores the OTel propagation data directly into the LLB description, which we then extract later and connect back to with an OTel span link in the buildkit.Worker. This way we can know exactly which span installed a vertex rather than trying to guess based on vertex digests.
|
FYI - I think some of #8442 (comment) might have gotten buried, specifically noticing
(I was showing this to @levlaz who pointed this out as well) |


This PR is a revamp of a bunch of status-related things. I'll give each one its own section.
New Telemetry test suite
First off - everything in this PR (I think) is now covered by a nice high-level test suite that will show us when there are regressions in the TUI. There are about a million moving parts involved with getting it to look right, so I'm super happy to finally have a safety net for all that.
Reviewer advice: there's a lot of change piled together here and it's all pretty inter-dependent. Would personally recommend mostly relying on the test coverage / golden output examples here and otherwise trying out the CLI by hand, though I certainly wouldn't mind reviewing the code too!
The tests work via an additional TUI progress format,
report, which tells it to just print the final TUI render. We then apply a million regexes to stabilize the output for future comparison (so things like1.3sbecomeX.Xs).To update the expected test output, run:
General TUI polish
(No Before/After since it's visible in all subsequent screenshots.)
Better errors
Functions can now return nice error messages, instead of just printing to stderr and exiting. No more
process /runtime did not complete successfully: exit status 2. Instead we show the actual error returned by the function.ReturnErrorwith anErrorvalue containing the desired message. Until that's done they'll just keep the same behavior as today.Also, the TUI (and upcoming web UI) will now bubble up error logs to the top-level so you don't need to deep-dive anymore. I decided to only bubble up spans that have logs, since it seems to have exceptionally good signal:noise. This is compared to bubbling up all errors, which the web UI currently does, and often just leads to a sea of red without any idea of what to click on.
Before:
After:
Cached state
The
CACHEDstate is back! Thanks to @jedevc for getting started on this in #8016. 🙏This involved quite a few tricks:
load cache:spans to a plain span withdagger.io/dag.cached: true.The last part is important because Buildkit doesn't emit a span for each and every vertex involved - only as far as it needs to look. But the UI still needs to know the fate of vertices B, C, and D, so we have other spans "vouch" for them.
Before:
After:
Pending state
We now pay closer attention to which 'effects' a span like
Container.withExecclaims it installed, and will mark the span "pending" (empty circle) until all of its effects have completed.This also builds on the work needed to implement
CACHEDstate (the "vouching" bit).Before:
After:
More accurate duration accounting (via span links)
Previously
withExecwould just say "I installed effect A" and then the Buildkit span (exec foo) would arrive saying "I am effect A" - but this broke down in some cases where it was possible for an effect to run multiple times (e.g. our integration tests). Now each Buildkit span directly links to its specific installer span, so we don't have to guess.Fewer spans
dagger.io/ui.passthrough.syncspan is now treated as if it'sdagger.io/ui.passthroughin the UI - it's never interesting on its own. (Similar toidcalls.)Exceptions to this rule:
resolving docker.io/library/alpine:latest- this is a synchronous action that is useful to show[1/5] FROM alpine, etc.) - these spans have a "one-to-many" relationship to the install site (Container.build) and are obviously valuable to showMore accurate failure propagation
Even though we have span links now, there are still scenarios where we want to use effect IDs to determine a span's status in the TUI.
Consider this example:
This function returns a
*dagger.Container, and if that container fails to run, we actually want to treatIntegration()as if it failed - even though it "successfully" returned the failed container, that's not very meaningful.So, now in addition to span links we'll bubble up errors to any sites that installed a failed effect. As part of this, spans only report newly installed effects by comparing to effects installed by the parent.
Before:
After:
Service logs
Service logs are now always directed to the
asServicespan, instead of a separatestart ...span.In the current model this is the only thing that really makes sense. You might think it makes sense to send logs to the service's
withExec, but the issue is there's not always awithExec.As an implementation detail, there is still a separate
exec ...span, but it links to theasServicespan and correlates to thewithExecspan.Canceled state (...kind of)
Sorry, don't get too excited. I added a freebie here - the API will detect a canceled request and mark the request span canceled - but in practice there's more work to be done to reflect this in some scenarios. For example, canceling a
syncwon't propagate the canceled state to the things it runs, and since thesynccall itself is hidden, you don't actually see a canceled state anywhere.Shorter exec errors for modules
Exec errors in modules no longer collect and return their stdout/stderr. With the TUI and Cloud UI these giant error messages are noisy and redundant. They are kept for the non-module code path (
dagger session) because it's still a reasonable thing to do when you can't make as many assumptions about the UI.