Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update k6foundry v0.4.0 #129

Merged
merged 1 commit into from
Feb 4, 2025
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.2
github.com/docker/go-connections v0.5.0
github.com/grafana/clireadme v0.1.0
github.com/grafana/k6foundry v0.3.1
github.com/grafana/k6foundry v0.4.0
github.com/spf13/cobra v1.8.1
github.com/testcontainers/testcontainers-go/modules/localstack v0.35.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/clireadme v0.1.0 h1:KYEYSnYdSzmHf3bufaK6fQZ5j4dzvM/T+G6Ba+qNnAM=
github.com/grafana/clireadme v0.1.0/go.mod h1:Wy4KIG2ZBGMYAYyF9l7qAy+yoJVasqk/txsRgoRI3gc=
github.com/grafana/k6foundry v0.3.1 h1:nv4BqlJfNXrVMk7ps7mlGiPgegR73ogTvisn1y0bYJ8=
github.com/grafana/k6foundry v0.3.1/go.mod h1:4Hw0ll6ZsKN8f3cgp7I4N6EkhXafZ6CBC6fDJWkW7/Q=
github.com/grafana/k6foundry v0.4.0 h1:Gh8oMaW02VHWxrGBHKLq3fvGa5LKMI0Z2feK2Ukkzw0=
github.com/grafana/k6foundry v0.4.0/go.mod h1:4Hw0ll6ZsKN8f3cgp7I4N6EkhXafZ6CBC6fDJWkW7/Q=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down
29 changes: 16 additions & 13 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ var (
// GoOpts defines the options for the go build environment
type GoOpts = k6foundry.GoOpts

// Foundry is a function that creates a Foundry Builder
type Foundry interface {
NewBuilder(ctx context.Context, opts k6foundry.NativeBuilderOpts) (k6foundry.Builder, error)
// FoundryFactory is a function that creates a FoundryFactory
type FoundryFactory interface {
NewFoundry(ctx context.Context, opts k6foundry.NativeFoundryOpts) (k6foundry.Foundry, error)
}

// FoundryFunction defines a function that implements the Foundry interface
type FoundryFunction func(context.Context, k6foundry.NativeBuilderOpts) (k6foundry.Builder, error)
// FoundryFactoryFunction defines a function that implements the FoundryFactory interface
type FoundryFactoryFunction func(context.Context, k6foundry.NativeFoundryOpts) (k6foundry.Foundry, error)

// NewBuilder implements the Foundry interface
func (f FoundryFunction) NewBuilder(ctx context.Context, opts k6foundry.NativeBuilderOpts) (k6foundry.Builder, error) {
// NewFoundry implements the Foundry interface
func (f FoundryFactoryFunction) NewFoundry(
ctx context.Context,
opts k6foundry.NativeFoundryOpts,
) (k6foundry.Foundry, error) {
return f(ctx, opts)
}

Expand All @@ -70,7 +73,7 @@ type Config struct {
Opts Opts
Catalog catalog.Catalog
Store store.ObjectStore
Foundry Foundry
Foundry FoundryFactory
Registerer prometheus.Registerer
}

Expand All @@ -80,7 +83,7 @@ type Builder struct {
catalog catalog.Catalog
store store.ObjectStore
mutexes sync.Map
foundry Foundry
foundry FoundryFactory
metrics *metrics
}

Expand All @@ -96,7 +99,7 @@ func New(_ context.Context, config Config) (*Builder, error) {

foundry := config.Foundry
if foundry == nil {
foundry = FoundryFunction(k6foundry.NewNativeBuilder)
foundry = FoundryFactoryFunction(k6foundry.NewNativeFoundry)
}

metrics := newMetrics()
Expand Down Expand Up @@ -215,7 +218,7 @@ func (b *Builder) Build( //nolint:funlen
env["CGO_ENABLED"] = "1"
}

builderOpts := k6foundry.NativeBuilderOpts{
builderOpts := k6foundry.NativeFoundryOpts{
GoOpts: k6foundry.GoOpts{
Env: env,
CopyGoEnv: b.opts.CopyGoEnv,
Expand All @@ -226,15 +229,15 @@ func (b *Builder) Build( //nolint:funlen
builderOpts.Stderr = os.Stderr
}

builder, err := b.foundry.NewBuilder(ctx, builderOpts)
builder, err := b.foundry.NewFoundry(ctx, builderOpts)
if err != nil {
return k6build.Artifact{}, k6build.NewWrappedError(ErrInitializingBuilder, err)
}
b.metrics.buildCounter.Inc()
buildTimer := prometheus.NewTimer(b.metrics.buildTimeHistogram)

artifactBuffer := &bytes.Buffer{}
buildInfo, err := builder.Build(ctx, buildPlatform, k6Mod.Version, mods, []string{}, artifactBuffer)
buildInfo, err := builder.Build(ctx, buildPlatform, k6Mod.Version, mods, nil, []string{}, artifactBuffer)
if err != nil {
b.metrics.buildsFailedCounter.Inc()
return k6build.Artifact{}, k6build.NewWrappedError(ErrAccessingArtifact, err)
Expand Down
15 changes: 8 additions & 7 deletions pkg/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ import (
// DependencyComp compares two dependencies for ordering
func DependencyComp(a, b catalog.Module) bool { return a.Path < b.Path }

type mockBuilder struct {
opts k6foundry.NativeBuilderOpts
type mockFoundry struct {
opts k6foundry.NativeFoundryOpts
}

// Mocks the Faundry's Build method
// Returns the build info for the given platform, k6 version and modules
func (m *mockBuilder) Build(
func (m *mockFoundry) Build(
_ context.Context,
platform k6foundry.Platform,
k6Version string,
mods []k6foundry.Module,
reps []k6foundry.Module,
buildOpts []string,
out io.Writer,
) (*k6foundry.BuildInfo, error) {
Expand All @@ -47,8 +48,8 @@ func (m *mockBuilder) Build(
}, nil
}

func MockFoundryFactory(_ context.Context, opts k6foundry.NativeBuilderOpts) (k6foundry.Builder, error) {
return &mockBuilder{
func MockFoundryFactory(_ context.Context, opts k6foundry.NativeFoundryOpts) (k6foundry.Foundry, error) {
return &mockFoundry{
opts: opts,
}, nil
}
Expand Down Expand Up @@ -77,7 +78,7 @@ func SetupTestBuilder(t *testing.T) (*Builder, error) {
Opts: Opts{},
Catalog: catalog,
Store: store,
Foundry: FoundryFunction(MockFoundryFactory),
Foundry: FoundryFactoryFunction(MockFoundryFactory),
})
}

Expand Down Expand Up @@ -466,7 +467,7 @@ func TestMetrics(t *testing.T) {
Opts: Opts{},
Catalog: catalog,
Store: store,
Foundry: FoundryFunction(MockFoundryFactory),
Foundry: FoundryFactoryFunction(MockFoundryFactory),
Registerer: register,
})
if err != nil {
Expand Down
Loading