Skip to content

Journal file support - #4300

Merged
aluzzardi merged 2 commits into
dagger:mainfrom
aluzzardi:dagger-journal
Jan 11, 2023
Merged

aluzzardi merged 2 commits into
dagger:mainfrom
aluzzardi:dagger-journal

Conversation

@aluzzardi

Copy link
Copy Markdown
Contributor

Add support for _EXPERIMENTAL_DAGGER_JOURNAL. This will dump raw
events to a log file, useful for post analysis.

Currently this will only be used internally and is subject to removal.

Related: #4248

@aluzzardi
aluzzardi requested review from gerhard, sipsma and vito January 4, 2023 14:16
@aluzzardi
aluzzardi marked this pull request as ready for review January 4, 2023 14:16
@aluzzardi
aluzzardi force-pushed the dagger-journal branch 5 times, most recently from da4dc92 to ed68828 Compare January 4, 2023 17:02

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

lgtm!

Comment thread engine/engine.go Resolved
Comment thread engine/engine.go Resolved
@gerhard

gerhard commented Jan 6, 2023

Copy link
Copy Markdown
Contributor

I am just about to open a PR which will confirm that this change works as expected. FTR: https://github.com/dagger/tools/pull/29#issuecomment-1373878073

Add support for `_EXPERIMENTAL_DAGGER_JOURNAL`. This will dump raw
events to a log file, useful for post analysis.

Currently this will only be used internally and is subject to removal.

Related: dagger#4248

Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
@aluzzardi
aluzzardi merged commit 9fbadb3 into dagger:main Jan 11, 2023
@aluzzardi
aluzzardi deleted the dagger-journal branch January 11, 2023 16:44
@gerhard

gerhard commented Jan 11, 2023 •

Copy link
Copy Markdown
Contributor

I don't think that this works as expected.

Given the following diffs:

diff --git a/internal/mage/sdk/nodejs.go b/internal/mage/sdk/nodejs.go
index bc0c8412..3a73f849 100644
--- a/internal/mage/sdk/nodejs.go
+++ b/internal/mage/sdk/nodejs.go
@@ -32,6 +32,7 @@ func (t Nodejs) Lint(ctx context.Context) error {

        eg.Go(func() error {
                _, err = base.
+                       WithExec([]string{"env"}).
                        WithExec([]string{"yarn", "lint"}).
                        ExitCode(gctx)
                return err
@@ -70,7 +71,7 @@ func (t Nodejs) Test(ctx context.Context) error {
        _, err = nodeJsBase(c).
                WithMountedDirectory("/root/.docker", util.HostDockerDir(c)).
                WithExec([]string{"yarn", "test"}).
-               ExitCode(ctx)
+               File("/engine.log").Export(ctx, "engine.log")
        return err
 }
❯ git diff internal/mage/util/util.go
diff --git a/internal/mage/util/util.go b/internal/mage/util/util.go
index 288e2c09..95ea8f65 100644
--- a/internal/mage/util/util.go
+++ b/internal/mage/util/util.go
@@ -62,11 +62,12 @@ func RepositoryGoCodeOnly(c *dagger.Client) *dagger.Directory {
        })
 }

func WithDevEngine(c *dagger.Client, ctr *dagger.Container) *dagger.Container {
        // the cli bin is statically linked, can just mount it in anywhere
        dockerCli := c.Container().From("docker:cli").File("/usr/local/bin/docker")

        cliBinPath := "/.dagger-cli"
+       engineLog := "/engine.log"
        return ctr.
                // Mount in the docker cli + socket, this will be used to connect to the dev engine
                // container
@@ -80,7 +81,9 @@ func WithDevEngine(c *dagger.Client, ctr *dagger.Container) *dagger.Container {
                WithMountedFile(cliBinPath, DaggerBinary(c)).
                // Point the SDKs to use the dev engine via these env vars
                WithEnvVariable("_EXPERIMENTAL_DAGGER_CLI_BIN", cliBinPath).
-               WithEnvVariable("_EXPERIMENTAL_DAGGER_RUNNER_HOST", "docker-container://"+TestContainerName)
+               WithEnvVariable("_EXPERIMENTAL_DAGGER_RUNNER_HOST", "docker-container://"+TestContainerName).
+               WithEnvVariable("_EXPERIMENTAL_DAGGER_JOURNAL", engineLog)
+
 }

 func goBase(c *dagger.Client) *dagger.Container {

The engine.log file produced for ./hack/make sdk:nodejs:test is empty:

image

I have noticed that only a subset of these tests run in the dev engine - the ones under NodeJS SDK Connect:

image

I have also noticed that yarn test runs in the stable dev engine, specifically dagger-engine-9ad18aca71b1b1ba which currently uses ghcr.io/dagger/engine:v0.3.7

While digging into this, I noticed that we use dagger.io/dagger v0.4.2 in our tests. This means that we provision the engine which our pipelines run differently than we do in the main branch. We are currently using the behaviour before #4194 was merged, specifically https://github.com/dagger/dagger/blob/sdk/go/v0.4.2/sdk/go/internal/engineconn/dockerprovision/image.go#L35-L146 . This is somewhat confusing, but more importantly it means that we cannot use this journal file feature in the engine where the majority of our pipelines run.

I think that all our CI workflows should use the dev SDK - replace go.dagger.io/dagger => ../../sdk/go in internal/mage/go.mod is my suggestion - and connect to the dev engine by default. In specific cases, we should use the latest released engine version (but not by default). This is a diagram of what I am proposing:

flowchart LR
    make(./hack/make sdk:node:lint)
    sdk_node_test(go run main.go -w ../.. sdk:node:test)
    engine_dev(go run main.go -w ../.. engine:dev)

    make --> engine_dev --> engine_dev_localhost --> test-dagger-engine
    engine_dev -.- sdk_node_test
    
    src["./sdk/nodejs"] --> |COPY| workdir

    subgraph Docker
        subgraph dagger-engine-SHA:v0.3.7
            engine_dev_localhost[/BUILD A DEV ENGINE/]
        end
        subgraph test-dagger-engine
            workdir["/workdir"]
            lint[yarn lint]
        end
    end

    sdk_node_test --> |_EXPERIMENTAL_DAGGER_RUNNER_HOST| test-dagger-engine
Loading

This is what is happening today:

flowchart LR
    make(./hack/make sdk:node:lint)
    sdk_node_test(go run main.go -w ../.. sdk:node:test)
    engine_dev(go run main.go -w ../.. engine:dev)

    make --> engine_dev --> engine_dev_localhost --> test-dagger-engine
    engine_dev -.- sdk_node_test
    
    src["./sdk/nodejs"] --> |COPY| workdir

    subgraph Docker
        subgraph dagger-engine-SHA:v0.3.7
            workdir["/workdir"]
            lint[yarn lint]
            engine_dev_localhost[/BUILD A DEV ENGINE/]
        end
        subgraph test-dagger-engine
            connect_via[[_EXPERIMENTAL_DAGGER_RUNNER_HOST]]
        end
    end

    sdk_node_test --> dagger-engine-SHA:v0.3.7
Loading

@sipsma

sipsma commented Jan 12, 2023

Copy link
Copy Markdown
Contributor

I think that all our CI workflows should use the dev SDK - replace go.dagger.io/dagger => ../../sdk/go in internal/mage/go.mod is my suggestion - and connect to the dev engine by default.

Use of a go mod replace like that will create catch-22s in cases where we are making a backwards incompatible change to how dagger session communicates w/ the runner. We won't have a dev engine already running, so we need to build it, but in order to build it we will be using the Go SDK, which in this case is incompatible with the previous stable engine, so we will be stuck. In a previous state of our CI this catch-22 was possible and actually happened here.

Other possible solutions (discussed some of these w/ @aluzzardi earlier today too):

  1. The "stable" engine doesn't have to be an official release. Once the journal file feature is merged into main then we can update internal/mage/go.mod to point to that.
    • We'll also need to update ./hack/* scripts to use _EXPERIMENTAL_DAGGER_RUNNER_HOST and download the right CLI for use w/ _EXPERIMENTAL_DAGGER_CLI_BIN, which is a bit annoying but not the utter end of the world. Can also simplify this part a bit by updating the engine images to push to tags for each git commit (rather than just :main) and some other tweaks.
  2. Split out the code so that the stable SDK+engine are used only for building+running the dev engine; after that all other steps use the dev engine.
    • This is totally possible but when discussed previously (buried somewhere in the threads here) it was causing headaches due to the fact that it meant the codebase for bootstrapping the dev engine had to be completely separate from the rest of the ci codebase, which would result in a bunch of hard-to-maintain duplication.

Overall, I don't love it but I think 1. above might be the best. If we put in the effort to make it easier for non-released SDKs automatically use the correct CLI+runner image, that will make it easier and technically benefit users too since it'll be easier for them to use the Go SDK from unreleased versions rather than always waiting for a new release.

@gerhard

gerhard commented Jan 12, 2023

Copy link
Copy Markdown
Contributor

2. seems to me that is easiest to understand: we always run against the current engine, the one that corresponds to a specific SHA in the CI, or local state in dev (including any uncommitted changes).

I cannot help thinking that having a stable engine to build a dev engine seems similar to having a single tool and using it for everything. Since we were able to build the first engine without using an existing engine, could we do the same for the dev engine?

gerhard added a commit that referenced this pull request Jan 12, 2023
WithDevEngine implies that the wrapped container will use the dev
engine. This is misleading and results in surprising behaviour, as
described in #4300 (comment)

AdvertiseDevEngine is more accurate: the dev engine is being advertised
for any component that is interested in using it, but nothing is
enforced. As we discovered, some components will continue using the
engine in which they already run (this used to be the stable engine).
The link above goes into more detail - it includes screenshots &
diagrams that explain the state better than text alone.

Signed-off-by: Gerhard Lazu <[email protected]>
@gerhard

gerhard commented Jan 12, 2023 •

Copy link
Copy Markdown
Contributor

Having talked through my above comment with @sipsma, the cleanest & easiest to understand approach requires us to move the dev engine building code into a separate directory with its own go.mod since we need to reference a stable Go SDK. We will use this stable Go SDK to auto-provision a stable engine which will be used to build a dev engine (like we do now in the context of internal/mage dir).

Once we have build the dev engine, all commands that run through ./hack/make will run inside this dev engine (which is exactly what we want). The only concern is that we will be duplicating code between these two directories (the new one, and the existing internal/mage). It's worth attempting to solve this again - things were more complicated when we first tried this out.

@aluzzardi

Copy link
Copy Markdown
Contributor Author

#3755 has a bunch of context on this.

AFAIK there were a bunch of trade-offs in complexity for small gains, that's why we binned the initiative

@gerhard gerhard mentioned this pull request Jan 27, 2023
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