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
10 changes: 10 additions & 0 deletions pkg/workflows/wasm/host/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type ModuleConfig struct {
// Labeler is used to emit messages from the module.
Labeler custmsg.MessageEmitter

// SdkLabeler is called with the discovered v2 import name after module creation.
// If nil, it defaults to a no-op. Used to add metrics labels (e.g. sdk=name).
SdkLabeler func(string)

// If Determinism is set, the module will override the random_get function in the WASI API with
// the provided seed to ensure deterministic behavior.
Determinism *DeterminismConfig
Expand Down Expand Up @@ -174,6 +178,10 @@ func NewModule(ctx context.Context, modCfg *ModuleConfig, binary []byte, opts ..
modCfg.Labeler = &unimplementedMessageEmitter{}
}

if modCfg.SdkLabeler == nil {
modCfg.SdkLabeler = func(string) {}
}

if modCfg.TickInterval == 0 {
modCfg.TickInterval = defaultTickInterval
}
Expand Down Expand Up @@ -307,6 +315,8 @@ func newModule(modCfg *ModuleConfig, binary []byte) (*module, error) {
}
}

modCfg.SdkLabeler(v2ImportName)

return &module{
engine: engine,
module: mod,
Expand Down
30 changes: 30 additions & 0 deletions pkg/workflows/wasm/host/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package host
import (
"context"
"encoding/binary"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -587,6 +588,35 @@ func Test_toEmissible(t *testing.T) {
})
}

func Test_SdkLabeler(t *testing.T) {
t.Run("defaults to no-op when nil", func(t *testing.T) {
// ModuleConfig with nil SdkLabeler should not panic when creating a module
binary := createTestBinary(successBinaryCmd, successBinaryLocation, true, t)
mc := &ModuleConfig{
Logger: logger.Test(t),
IsUncompressed: true,
Fetch: func(context.Context, *FetchRequest) (*FetchResponse, error) { return &FetchResponse{}, nil },
}
_, err := NewModule(t.Context(), mc, binary)
require.NoError(t, err)
require.NotNil(t, mc.SdkLabeler, "SdkLabeler should be set to no-op")
})

t.Run("is called with v2ImportName after discovery", func(t *testing.T) {
binary := createTestBinary(nodagRandomBinaryCmd, nodagRandomBinaryLocation, true, t)
var capturedName string
mc := defaultNoDAGModCfg(t)
mc.SdkLabeler = func(name string) {
capturedName = name
}
m, err := NewModule(t.Context(), mc, binary)
require.NoError(t, err)
require.False(t, m.IsLegacyDAG(), "expected NoDAG module")
require.NotEmpty(t, capturedName, "SdkLabeler should have been called with v2 import name")
require.True(t, strings.HasPrefix(capturedName, v2ImportPrefix), "captured name should have v2 prefix")
})
}

// CallAwaitRace validates that every call can be awaited.
func Test_CallAwaitRace(t *testing.T) {
ctx := t.Context()
Expand Down
Loading