Skip to content

Better errors, cached states, pending states, duration accounting, fewer spans - #8442

Merged
vito merged 128 commits into
dagger:mainfrom
vito:status-symbols
Nov 13, 2024
Merged

vito merged 128 commits into
dagger:mainfrom
vito:status-symbols

Conversation

@vito

@vito vito commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

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 like 1.3s become X.Xs).

To update the expected test output, run:

dagger call test telemetry --update -o .

General TUI polish

  • Calls will now be rendered as chained pipelines when possible, with gaps in between for legibility.
  • Indent guides are now displayed.

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

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:

asciicast

After:

asciicast

Cached state

The CACHED state is back! Thanks to @jedevc for getting started on this in #8016. 🙏

This involved quite a few tricks:

  • Translating load cache: spans to a plain span with dagger.io/dag.cached: true.
  • Keeping track of all Buildkit ops that we have seen so we can deeply inspect them in the telemetry pipeline.
  • Using that info, for any completed Buildkit span, emit an additional attribute containing all deep vertex digests that were an input to the span.
  • When we see a cache hit for vertex A, we also infer that input vertices B, C, and D were cached.

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:

asciicast

After:

asciicast

Pending state

We now pay closer attention to which 'effects' a span like Container.withExec claims 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 CACHED state (the "vouching" bit).

Before:

asciicast

After:

asciicast

More accurate duration accounting (via span links)

Previously withExec would 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

  • Most Buildkit spans are now treated as an implementation detail of the span that they link to. They contribute to the linked span's status and duration, and just hide out of view by setting dagger.io/ui.passthrough.
  • The sync span is now treated as if it's dagger.io/ui.passthrough in the UI - it's never interesting on its own. (Similar to id calls.)

Exceptions to this rule:

  • resolving docker.io/library/alpine:latest - this is a synchronous action that is useful to show
  • Dockerfile spans ([1/5] FROM alpine, etc.) - these spans have a "one-to-many" relationship to the install site (Container.build) and are obviously valuable to show

More 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:

func (b *Bass) Integration() *dagger.Container

This function returns a *dagger.Container, and if that container fails to run, we actually want to treat Integration() 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:

asciicast

After:

asciicast

Service logs

Service logs are now always directed to the asService span, instead of a separate start ... 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 a withExec.

As an implementation detail, there is still a separate exec ... span, but it links to the asService span and correlates to the withExec span.

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 sync won't propagate the canceled state to the things it runs, and since the sync call 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.

@vito
vito force-pushed the status-symbols branch 2 times, most recently from d614d7e to dda05d6 Compare September 13, 2024 19:09
@vito

vito commented Sep 16, 2024 •

Copy link
Copy Markdown
Contributor Author

@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 Error type as opposed to just a string. By using a proper type we can support interesting things like adding stack traces, file/line information, maybe even a Directory containing screenshots, etc.

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 returnError write the ErrorID to a file in the caller's filesystem, so the same way that returnValue works. I briefly got stuck on the whole "Buildkit can't fail and return something" - but then remembered we already dealt with this when collecting the Stdout/Stderr for ExecError, so it just uses the same trick: when we fail to evaluate the function, we rescue that value from the mount by directly loading it from the snapshot.

End result:

image

v0.13.0 for comparison:

image

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 Error type? Or, do we think this is fundamentally off-base and we actually need to support 'arbitrary type + error' returns?

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 Error API. But, that's just my current thinking - I see this more like the start of a beautiful bikeshed. 😄

There's also a lot of inspiration from Go's "errors ARE values" idea here - we could even have *Error satisfy error interface, and whatever else makes sense for other SDKs.

Connecting dots:

(edit: let's bikeshed there to keep this PR focused on the minimal change, will copy/paste)

cc @sipsma

@vito vito changed the title More gooder OTel Better errors, cached states, pending states, duration accounting, fewer spans Sep 16, 2024
Comment thread dagql/idtui/golden_test.go Outdated
Comment on lines +136 to +149
// 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)

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.

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

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.

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?

@vito vito Sep 24, 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.

@sipsma Thanks for taking a look!

Can you easily repro this with some dagger calls on 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.

@vito vito Sep 24, 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.

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); end

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

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.

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.

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
}

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.

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

@vito
vito force-pushed the status-symbols branch 4 times, most recently from ffd395b to c1dc7bf Compare September 25, 2024 14:31
@vito
vito marked this pull request as ready for review September 25, 2024 14:58
@vito
vito requested review from a team as code owners September 25, 2024 14:58
@vito
vito requested review from jedevc and sipsma September 25, 2024 18:53
@vito vito mentioned this pull request Sep 25, 2024
@vito
vito force-pushed the status-symbols branch 2 times, most recently from 30831a6 to 5590da4 Compare September 26, 2024 13:44
@vito

vito commented Nov 6, 2024 •

Copy link
Copy Markdown
Contributor Author

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

  • 3983067 - which removes the Stdout:\n\nStderr:\n\n appending to exec errors in module code paths.

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.

Comment thread .dagger/test.go
// +optional
verbose bool,
) (*dagger.Directory, error) {
engine := t.Dagger.Engine().

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: a lot of this logic seems shared with testCmd?

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

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.

No worries, I'll probably take a look at it at "some point in the future" if that's okay with you 🫡

Comment thread dagql/dagui/opts.go
Comment on lines +89 to +95
// 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
// }

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.

So just to confirm - we now always show previous "spammy" spans? Since not showing them could result in broken chains?

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 - 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)
}

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.

Sorry, struggling to understand what the effect of calling this actually is 😅

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.

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.

@jedevc

jedevc commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

FYI - I think some of #8442 (comment) might have gotten buried, specifically noticing

Somehow HTTP HEAD errors have started flashing in very quickly:

(I was showing this to @levlaz who pointed this out as well)

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