Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion kurtosis-devnet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"os"
"path/filepath"

"github.com/ethereum-optimism/optimism/devnet-sdk/telemetry"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/deploy"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
autofixTypes "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/types"
"github.com/honeycombio/otel-config-go/otelconfig"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -80,6 +82,18 @@ func printWelcomeMessage() {
}

func mainAction(c *cli.Context) error {
ctx := c.Context

ctx, shutdown, err := telemetry.SetupOpenTelemetry(
ctx,
otelconfig.WithServiceName(c.App.Name),
otelconfig.WithServiceVersion(c.App.Version),
)
if err != nil {
return fmt.Errorf("error setting up OpenTelemetry: %w", err)
}
defer shutdown()

// Only show welcome message if not showing help or version
if !c.Bool("help") && !c.Bool("version") && c.NArg() == 0 {
printWelcomeMessage()
Expand Down Expand Up @@ -115,7 +129,7 @@ func mainAction(c *cli.Context) error {
return fmt.Errorf("error creating deployer: %w", err)
}

env, err := deployer.Deploy(c.Context, nil)
env, err := deployer.Deploy(ctx, nil)
if err != nil {
if autofixMode == autofixTypes.AutofixModeDisabled {
printAutofixMessage()
Expand Down
6 changes: 5 additions & 1 deletion kurtosis-devnet/pkg/build/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ktfs "github.com/ethereum-optimism/optimism/devnet-sdk/kt/fs"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/enclave"
"github.com/spf13/afero"
"go.opentelemetry.io/otel"
)

// ContractBuilder handles building smart contracts using just commands
Expand Down Expand Up @@ -107,7 +108,10 @@ func NewContractBuilder(opts ...ContractBuilderOptions) *ContractBuilder {
}

// Build executes the contract build command
func (b *ContractBuilder) Build(_ string) (string, error) {
func (b *ContractBuilder) Build(ctx context.Context, _ string) (string, error) {
_, span := otel.Tracer("contract-builder").Start(ctx, "build contracts")
defer span.End()

// since we ignore layer for now, we can skip the build if the file already
// exists: it'll be the same file!
if url, ok := b.builtContracts[""]; ok {
Expand Down
2 changes: 1 addition & 1 deletion kurtosis-devnet/pkg/build/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestContractBuilder_Build(t *testing.T) {
builder.enclaveManager = enclaveManager

// Execute build
output, err := builder.Build("")
output, err := builder.Build(context.Background(), "")

// Verify results
if tt.expectError {
Expand Down
10 changes: 6 additions & 4 deletions kurtosis-devnet/pkg/build/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"go.opentelemetry.io/otel"
"golang.org/x/sync/semaphore"
)

Expand Down Expand Up @@ -228,7 +229,7 @@ type templateData struct {

// Build ensures the docker image for the given project is built, respecting concurrency limits.
// It blocks until the specific requested build is complete. Other builds may run concurrently.
func (b *DockerBuilder) Build(projectName, imageTag string) (string, error) {
func (b *DockerBuilder) Build(ctx context.Context, projectName, imageTag string) (string, error) {
b.mu.Lock()
state, exists := b.buildStates[projectName]
if !exists {
Expand All @@ -241,7 +242,7 @@ func (b *DockerBuilder) Build(projectName, imageTag string) (string, error) {

if !exists {
state.once.Do(func() {
err := b.executeBuild(projectName, imageTag, state)
err := b.executeBuild(ctx, projectName, imageTag, state)
if err != nil {
state.err = err
state.result = ""
Expand All @@ -255,8 +256,9 @@ func (b *DockerBuilder) Build(projectName, imageTag string) (string, error) {
return state.result, state.err
}

func (b *DockerBuilder) executeBuild(projectName, initialImageTag string, state *buildState) error {
ctx := context.Background()
func (b *DockerBuilder) executeBuild(ctx context.Context, projectName, initialImageTag string, state *buildState) error {
ctx, span := otel.Tracer("docker-builder").Start(ctx, fmt.Sprintf("build %s", projectName))
defer span.End()

log.Printf("Build started for project: %s (tag: %s)", projectName, initialImageTag)

Expand Down
11 changes: 6 additions & 5 deletions kurtosis-devnet/pkg/build/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package build

import (
"bytes"
"context"
"fmt"
"log"
"sync"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestDockerBuilder_Build_Success(t *testing.T) {
)

// Execute build
resultTag, err := builder.Build(projectName, initialTag)
resultTag, err := builder.Build(context.Background(), projectName, initialTag)

// Verify results
require.NoError(t, err)
Expand All @@ -59,7 +60,7 @@ func TestDockerBuilder_Build_CommandFailure(t *testing.T) {
)

// Try to build a project
result, err := builder.Build("test-project", "test-tag")
result, err := builder.Build(context.Background(), "test-project", "test-tag")

// Verify the result
require.NoError(t, err)
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestDockerBuilder_Build_ConcurrencyLimit(t *testing.T) {
defer wg.Done()
projectName := fmt.Sprintf("concurrent-project-%d", idx)
initialTag := fmt.Sprintf("%s:enclave1", projectName)
_, err := builder.Build(projectName, initialTag)
_, err := builder.Build(context.Background(), projectName, initialTag)
assert.NoError(t, err, "Build %d failed", idx)
}(i)
}
Expand Down Expand Up @@ -123,7 +124,7 @@ func TestDockerBuilder_Build_DryRun(t *testing.T) {
)

// Execute build
resultTag, err := builder.Build(projectName, initialTag)
resultTag, err := builder.Build(context.Background(), projectName, initialTag)

// Verify results
require.NoError(t, err)
Expand Down Expand Up @@ -161,7 +162,7 @@ func TestDockerBuilder_Build_DuplicateCalls(t *testing.T) {
for i := 0; i < numCalls; i++ {
go func(idx int) {
defer wg.Done()
results[idx], errors[idx] = builder.Build(projectName, initialTag)
results[idx], errors[idx] = builder.Build(context.Background(), projectName, initialTag)
}(i)
}

Expand Down
8 changes: 7 additions & 1 deletion kurtosis-devnet/pkg/build/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package build

import (
"bytes"
"context"
"fmt"
"log"
"os/exec"
"text/template"

"go.opentelemetry.io/otel"
)

// PrestateBuilder handles building prestates using just commands
Expand Down Expand Up @@ -69,7 +72,10 @@ type prestateTemplateData struct {
}

// Build executes the prestate build command
func (b *PrestateBuilder) Build(path string) error {
func (b *PrestateBuilder) Build(ctx context.Context, path string) error {
_, span := otel.Tracer("prestate-builder").Start(ctx, "build prestate")
defer span.End()

if _, ok := b.builtPrestates[path]; ok {
return nil
}
Expand Down
18 changes: 15 additions & 3 deletions kurtosis-devnet/pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/engine"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
autofixTypes "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

type EngineManager interface {
Expand Down Expand Up @@ -43,6 +45,7 @@ type Deployer struct {
newEnclaveFS func(ctx context.Context, enclave string, opts ...ktfs.EnclaveFSOption) (*ktfs.EnclaveFS, error)
enclaveManager *enclave.KurtosisEnclaveManager
autofixMode autofixTypes.AutofixMode
tracer trace.Tracer
}

func WithKurtosisDeployer(ktDeployer DeployerFunc) DeployerOption {
Expand Down Expand Up @@ -118,6 +121,7 @@ func NewDeployer(opts ...DeployerOption) (*Deployer, error) {
return kurtosis.NewKurtosisDeployer(opts...)
},
newEnclaveFS: ktfs.NewEnclaveFS,
tracer: otel.Tracer("deployer"),
}
for _, opt := range opts {
opt(d)
Expand Down Expand Up @@ -160,6 +164,9 @@ func NewDeployer(opts ...DeployerOption) (*Deployer, error) {
}

func (d *Deployer) deployEnvironment(ctx context.Context, r io.Reader) (*kurtosis.KurtosisEnvironment, error) {
ctx, span := d.tracer.Start(ctx, "deploy environment")
defer span.End()

// Create a multi reader to output deployment input to stdout
buf := bytes.NewBuffer(nil)
tee := io.TeeReader(r, buf)
Expand Down Expand Up @@ -206,7 +213,10 @@ func (d *Deployer) deployEnvironment(ctx context.Context, r io.Reader) (*kurtosi
return info, nil
}

func (d *Deployer) renderTemplate(buildDir string, urlBuilder func(path ...string) string) (*bytes.Buffer, error) {
func (d *Deployer) renderTemplate(ctx context.Context, buildDir string, urlBuilder func(path ...string) string) (*bytes.Buffer, error) {
ctx, span := d.tracer.Start(ctx, "render template")
defer span.End()

t := &Templater{
baseDir: d.baseDir,
dryRun: d.dryRun,
Expand All @@ -218,10 +228,12 @@ func (d *Deployer) renderTemplate(buildDir string, urlBuilder func(path ...strin
urlBuilder: urlBuilder,
}

return t.Render()
return t.Render(ctx)
}

func (d *Deployer) Deploy(ctx context.Context, r io.Reader) (*kurtosis.KurtosisEnvironment, error) {
ctx, span := d.tracer.Start(ctx, "deploy devnet")
defer span.End()

// Clean up the enclave before deploying
if d.autofixMode == autofixTypes.AutofixModeNuke {
Expand Down Expand Up @@ -263,7 +275,7 @@ func (d *Deployer) Deploy(ctx context.Context, r io.Reader) (*kurtosis.KurtosisE

ch := srv.getState(ctx)

buf, err := d.renderTemplate(tmpDir, srv.URL)
buf, err := d.renderTemplate(ctx, tmpDir, srv.URL)
if err != nil {
return nil, fmt.Errorf("error rendering template: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions kurtosis-devnet/pkg/deploy/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/util"
"github.com/spf13/afero"
"go.opentelemetry.io/otel"
)

const FILESERVER_PACKAGE = "fileserver"
Expand All @@ -34,6 +35,9 @@ func (f *FileServer) URL(path ...string) string {
}

func (f *FileServer) Deploy(ctx context.Context, sourceDir string, stateCh <-chan *fileserverState) (retErr error) {
ctx, span := otel.Tracer("fileserver").Start(ctx, "deploy fileserver")
defer span.End()

if f.fs == nil {
f.fs = afero.NewOsFs()
}
Expand Down
5 changes: 3 additions & 2 deletions kurtosis-devnet/pkg/deploy/prestate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deploy

import (
"context"
"encoding/json"
"fmt"
"log"
Expand All @@ -25,7 +26,7 @@ type localPrestateHolder struct {
urlBuilder func(path ...string) string
}

func (h *localPrestateHolder) GetPrestateInfo() (*PrestateInfo, error) {
func (h *localPrestateHolder) GetPrestateInfo(ctx context.Context) (*PrestateInfo, error) {
if h.info != nil {
return h.info, nil
}
Expand Down Expand Up @@ -59,7 +60,7 @@ func (h *localPrestateHolder) GetPrestateInfo() (*PrestateInfo, error) {
}

// Build all prestate files directly in the target directory
if err := h.builder.Build(buildDir); err != nil {
if err := h.builder.Build(ctx, buildDir); err != nil {
return nil, fmt.Errorf("failed to build prestates: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion kurtosis-devnet/pkg/deploy/prestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deploy

import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -56,7 +57,7 @@ _prestate-build target:

buildWg := &sync.WaitGroup{}
// Create template context with just the prestate function
tmplCtx := tmpl.NewTemplateContext(templater.localPrestateOption(buildWg))
tmplCtx := tmpl.NewTemplateContext(templater.localPrestateOption(context.Background(), buildWg))

// Test template with multiple calls to localPrestate
template := `first:
Expand Down
Loading