From 2060af409e394757efb49662a0e06d7990b13e45 Mon Sep 17 00:00:00 2001 From: Hamsajj <118748983+Hamsajj@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:38:54 +0100 Subject: [PATCH] feat: add timeout for running actions (#496) --- act/act_helpers_test.go | 51 ++++++++++++++ act/registry.go | 94 ++++++++++++++++--------- act/registry_test.go | 122 +++++++++++++++++++++++++++------ api/api_test.go | 7 +- cmd/run.go | 2 +- config/config.go | 1 + config/constants.go | 1 + config/types.go | 1 + errors/errors.go | 2 + network/proxy_test.go | 12 ++-- network/server_test.go | 2 +- plugin/plugin_registry_test.go | 4 +- plugin/utils_test.go | 2 +- 13 files changed, 235 insertions(+), 66 deletions(-) create mode 100644 act/act_helpers_test.go diff --git a/act/act_helpers_test.go b/act/act_helpers_test.go new file mode 100644 index 00000000..bdcd9f42 --- /dev/null +++ b/act/act_helpers_test.go @@ -0,0 +1,51 @@ +package act + +import ( + "time" + + sdkAct "github.com/gatewayd-io/gatewayd-plugin-sdk/act" +) + +func createWaitActEntities(async bool) ( + string, + map[string]*sdkAct.Action, + map[string]*sdkAct.Signal, + map[string]*sdkAct.Policy, +) { + name := "waitSync" + if async { + name = "waitAsync" + } + actions := map[string]*sdkAct.Action{ + name: { + Name: name, + Metadata: nil, + Sync: !async, + Terminal: false, + Run: func(_ map[string]any, _ ...sdkAct.Parameter) (any, error) { + time.Sleep(1 * time.Second) + return true, nil + }, + }, + } + signals := map[string]*sdkAct.Signal{ + name: { + Name: name, + Metadata: map[string]any{ + "log": true, + "level": "info", + "message": "test", + "async": async, + }, + }, + } + policy := map[string]*sdkAct.Policy{ + name: sdkAct.MustNewPolicy( + name, + `true`, + map[string]any{"log": "enabled"}, + ), + } + + return name, actions, signals, policy +} diff --git a/act/registry.go b/act/registry.go index 397bdb93..45db0f78 100644 --- a/act/registry.go +++ b/act/registry.go @@ -23,6 +23,8 @@ type Registry struct { logger zerolog.Logger // Timeout for policy evaluation. policyTimeout time.Duration + // Default timeout for running actions + defaultActionTimeout time.Duration Signals map[string]*sdkAct.Signal Policies map[string]*sdkAct.Policy @@ -41,6 +43,7 @@ func NewActRegistry( builtinActions map[string]*sdkAct.Action, defaultPolicy string, policyTimeout time.Duration, + defaultActionTimeout time.Duration, logger zerolog.Logger, ) *Registry { if builtinSignals == nil || builtinsPolicies == nil || builtinActions == nil { @@ -82,13 +85,14 @@ func NewActRegistry( logger.Debug().Str("name", defaultPolicy).Msg("Using default policy") return &Registry{ - logger: logger, - policyTimeout: policyTimeout, - Signals: builtinSignals, - Policies: builtinsPolicies, - Actions: builtinActions, - DefaultPolicy: builtinsPolicies[defaultPolicy], - DefaultSignal: builtinSignals[defaultPolicy], + logger: logger, + policyTimeout: policyTimeout, + defaultActionTimeout: defaultActionTimeout, + Signals: builtinSignals, + Policies: builtinsPolicies, + Actions: builtinActions, + DefaultPolicy: builtinsPolicies[defaultPolicy], + DefaultSignal: builtinSignals[defaultPolicy], } } @@ -229,41 +233,67 @@ func (r *Registry) Run( // Prepend the logger to the parameters. params = append([]sdkAct.Parameter{WithLogger(r.logger)}, params...) + timeout := r.defaultActionTimeout + if action.Timeout > 0 { + timeout = time.Duration(action.Timeout) * time.Second + } + var ctx context.Context + var cancel context.CancelFunc + // if timeout is zero, then the context should not have timeout + if timeout > 0 { + ctx, cancel = context.WithTimeout(context.Background(), timeout) + } else { + ctx, cancel = context.WithCancel(context.Background()) + } // If the action is synchronous, run it and return the result immediately. if action.Sync { - r.logger.Debug().Fields(map[string]interface{}{ - "executionMode": "sync", - "action": action.Name, - }).Msgf("Running action") - - output, err := action.Run(output.Metadata, params...) - if err != nil { - r.logger.Error().Err(err).Str("action", action.Name).Msg("Error running action") - return nil, gerr.ErrRunningAction.Wrap(err) - } - return output, nil + defer cancel() + return runActionWithTimeout(ctx, action, output, params, r.logger) } - r.logger.Debug().Fields(map[string]interface{}{ - "executionMode": "async", + // Run the action asynchronously. + go func() { + defer cancel() + _, _ = runActionWithTimeout(ctx, action, output, params, r.logger) + }() + return nil, gerr.ErrAsyncAction +} + +func runActionWithTimeout( + ctx context.Context, + action *sdkAct.Action, + output *sdkAct.Output, + params []sdkAct.Parameter, + logger zerolog.Logger, +) (any, *gerr.GatewayDError) { + execMode := "sync" + if !action.Sync { + execMode = "async" + } + logger.Debug().Fields(map[string]interface{}{ + "executionMode": execMode, "action": action.Name, }).Msgf("Running action") + outputChan := make(chan any) + errChan := make(chan *gerr.GatewayDError) - // Run the action asynchronously. - // TODO: Add a way to cancel the action. - go func( - action *sdkAct.Action, - output *sdkAct.Output, - params []sdkAct.Parameter, - logger zerolog.Logger, - ) { - _, err := action.Run(output.Metadata, params...) + go func() { + actionOutput, err := action.Run(output.Metadata, params...) if err != nil { logger.Error().Err(err).Str("action", action.Name).Msg("Error running action") + errChan <- gerr.ErrRunningAction.Wrap(err) } - }(action, output, params, r.logger) - - return nil, gerr.ErrAsyncAction + outputChan <- actionOutput + }() + select { + case <-ctx.Done(): + logger.Error().Str("action", action.Name).Msg("Action timed out") + return nil, gerr.ErrRunningActionTimeout + case actionOutput := <-outputChan: + return actionOutput, nil + case err := <-errChan: + return nil, err + } } // WithLogger returns a parameter with the logger to be used by the action. diff --git a/act/registry_test.go b/act/registry_test.go index eb06e90c..b4442593 100644 --- a/act/registry_test.go +++ b/act/registry_test.go @@ -11,6 +11,7 @@ import ( "github.com/rs/zerolog" "github.com/spf13/cast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // Test_NewRegistry tests the NewRegistry function. @@ -19,7 +20,7 @@ func Test_NewRegistry(t *testing.T) { actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) assert.NotNil(t, actRegistry.Signals) assert.NotNil(t, actRegistry.Policies) @@ -34,7 +35,7 @@ func Test_NewRegistry_NilBuiltins(t *testing.T) { buf := bytes.Buffer{} logger := zerolog.New(&buf) actRegistry := NewActRegistry( - nil, nil, nil, config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + nil, nil, nil, config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.Nil(t, actRegistry) assert.Contains(t, buf.String(), "Builtin signals, policies, or actions are nil, not adding") } @@ -49,7 +50,7 @@ func Test_NewRegistry_NilSignal(t *testing.T) { "bad": nil, }, BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.Nil(t, actRegistry) assert.Contains(t, buf.String(), "Signal is nil, not adding") } @@ -65,7 +66,7 @@ func Test_NewRegistry_NilPolicy(t *testing.T) { "bad": nil, }, BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.Nil(t, actRegistry) assert.Contains(t, buf.String(), "Policy is nil, not adding") } @@ -80,7 +81,7 @@ func Test_NewRegistry_NilAction(t *testing.T) { map[string]*sdkAct.Action{ "bad": nil, }, - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.Nil(t, actRegistry) assert.Contains(t, buf.String(), "Action is nil, not adding") } @@ -89,7 +90,7 @@ func Test_NewRegistry_NilAction(t *testing.T) { func Test_Add(t *testing.T) { actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, zerolog.Logger{}) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, zerolog.Logger{}) assert.NotNil(t, actRegistry) assert.Len(t, actRegistry.Policies, len(BuiltinPolicies())) @@ -107,7 +108,7 @@ func Test_Add_NilPolicy(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), map[string]*sdkAct.Policy{}, BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) assert.Len(t, actRegistry.Policies, 0) @@ -122,7 +123,7 @@ func Test_Add_ExistentPolicy(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) assert.Len(t, actRegistry.Policies, len(BuiltinPolicies())) @@ -135,7 +136,7 @@ func Test_Add_ExistentPolicy(t *testing.T) { func Test_Apply(t *testing.T) { actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, zerolog.Logger{}) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, zerolog.Logger{}) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -157,7 +158,7 @@ func Test_Apply_NoSignals(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{}) @@ -196,7 +197,7 @@ func Test_Apply_ContradictorySignals(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) for _, s := range signals { @@ -234,7 +235,7 @@ func Test_Apply_ActionNotMatched(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -262,7 +263,7 @@ func Test_Apply_PolicyNotMatched(t *testing.T) { "passthrough": BuiltinPolicies()["passthrough"], }, BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -305,7 +306,7 @@ func Test_Apply_NonBoolPolicy(t *testing.T) { BuiltinSignals(), policies, BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -348,7 +349,7 @@ func Test_Apply_BadPolicy(t *testing.T) { BuiltinSignals(), policies, BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.Nil(t, actRegistry) } } @@ -358,7 +359,7 @@ func Test_Run(t *testing.T) { logger := zerolog.Logger{} actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -376,7 +377,7 @@ func Test_Run_Terminate(t *testing.T) { logger := zerolog.Logger{} actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -402,7 +403,7 @@ func Test_Run_Async(t *testing.T) { logger := zerolog.New(&out) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) outputs := actRegistry.Apply([]sdkAct.Signal{ @@ -441,7 +442,7 @@ func Test_Run_NilOutput(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) result, err := actRegistry.Run(nil, WithLogger(logger)) @@ -456,7 +457,7 @@ func Test_Run_ActionNotExist(t *testing.T) { logger := zerolog.New(&buf) actRegistry := NewActRegistry( BuiltinSignals(), BuiltinPolicies(), BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) assert.NotNil(t, actRegistry) result, err := actRegistry.Run(&sdkAct.Output{}, WithLogger(logger)) @@ -464,3 +465,84 @@ func Test_Run_ActionNotExist(t *testing.T) { assert.Equal(t, err, gerr.ErrActionNotExist) assert.Contains(t, buf.String(), "Action does not exist, run aborted") } + +// Test_Run_Timeout tests the Run function of the action with a timeout. +func Test_Run_Timeout(t *testing.T) { + tests := []struct { + name string + isAsync bool + expectedErr error + expectedLog string + expectedResult any + timeout time.Duration + }{ + { + name: "sync action", + isAsync: false, + expectedErr: gerr.ErrRunningActionTimeout, + expectedLog: "", + timeout: 1 * time.Millisecond, + expectedResult: nil, + }, + { + name: "async action", + isAsync: true, + expectedErr: gerr.ErrAsyncAction, + expectedLog: "{\"level\":\"error\",\"action\":\"waitAsync\",\"message\":\"Action timed out\"}", + timeout: 1 * time.Millisecond, + expectedResult: nil, + }, + { + name: "action with no timeout", + isAsync: false, + expectedErr: nil, + expectedLog: "", + timeout: 0, + expectedResult: true, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + isAsync := test.isAsync + name, actions, signals, policies := createWaitActEntities(isAsync) + out := bytes.Buffer{} + logger := zerolog.New(&out) + actRegistry := NewActRegistry( + signals, policies, actions, + config.DefaultPolicy, config.DefaultPolicyTimeout, test.timeout, logger) + assert.NotNil(t, actRegistry) + + outputs := actRegistry.Apply([]sdkAct.Signal{*signals[name]}) + assert.NotNil(t, outputs) + assert.Equal(t, name, outputs[0].MatchedPolicy) + assert.Equal(t, + map[string]interface{}{ + "async": isAsync, + "level": "info", + "log": true, + "message": "test", + }, + outputs[0].Metadata, + ) + assert.Equal(t, !isAsync, outputs[0].Sync) + assert.True(t, cast.ToBool(outputs[0].Verdict)) + assert.False(t, outputs[0].Terminal) + + result, err := actRegistry.Run(outputs[0], WithResult(map[string]any{})) + if test.expectedErr != nil { + require.NotNil(t, err) + assert.ErrorIs(t, err, test.expectedErr) + } else { + require.Nil(t, err) + } + assert.Equal(t, test.expectedResult, result) + + if isAsync { + time.Sleep(3 * time.Millisecond) + } + if test.expectedLog != "" { + assert.Contains(t, out.String(), test.expectedLog) + } + }) + } +} diff --git a/api/api_test.go b/api/api_test.go index 158ce6cb..5ca35371 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -108,7 +108,7 @@ func TestGetPluginConfig(t *testing.T) { func TestGetPlugins(t *testing.T) { actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, zerolog.Logger{}) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, zerolog.Logger{}) pluginRegistry := plugin.NewRegistry( context.TODO(), actRegistry, @@ -137,7 +137,7 @@ func TestGetPlugins(t *testing.T) { func TestGetPluginsWithEmptyPluginRegistry(t *testing.T) { actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, zerolog.Logger{}) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, zerolog.Logger{}) pluginRegistry := plugin.NewRegistry( context.TODO(), actRegistry, @@ -229,6 +229,7 @@ func TestGetServers(t *testing.T) { } client := network.NewClient(context.TODO(), clientConfig, zerolog.Logger{}, nil) newPool := pool.NewPool(context.TODO(), 1) + require.NotNil(t, newPool) assert.Nil(t, newPool.Put(client.ID, client)) proxy := network.NewProxy( @@ -246,7 +247,7 @@ func TestGetServers(t *testing.T) { actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, zerolog.Logger{}) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, zerolog.Logger{}) pluginRegistry := plugin.NewRegistry( context.TODO(), diff --git a/cmd/run.go b/cmd/run.go index e5bcd3f0..1b1601bc 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -285,7 +285,7 @@ var runCmd = &cobra.Command{ // Create a new act registry given the built-in signals, policies, and actions. actRegistry = act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - conf.Plugin.DefaultPolicy, conf.Plugin.PolicyTimeout, logger, + conf.Plugin.DefaultPolicy, conf.Plugin.PolicyTimeout, conf.Plugin.ActionTimeout, logger, ) if actRegistry == nil { diff --git a/config/config.go b/config/config.go index b0389259..e38c4fbe 100644 --- a/config/config.go +++ b/config/config.go @@ -214,6 +214,7 @@ func (c *Config) LoadDefaults(ctx context.Context) { StartTimeout: DefaultPluginStartTimeout, DefaultPolicy: DefaultPolicy, PolicyTimeout: DefaultPolicyTimeout, + ActionTimeout: DefaultActionTimeout, Policies: []Policy{}, } diff --git a/config/constants.go b/config/constants.go index 3fe9d5d5..917240a4 100644 --- a/config/constants.go +++ b/config/constants.go @@ -125,4 +125,5 @@ const ( // Act. DefaultPolicy = "passthrough" DefaultPolicyTimeout = 30 * time.Second + DefaultActionTimeout = 30 * time.Second ) diff --git a/config/types.go b/config/types.go index fd7ceecd..cbefed70 100644 --- a/config/types.go +++ b/config/types.go @@ -32,6 +32,7 @@ type PluginConfig struct { Plugins []Plugin `json:"plugins"` DefaultPolicy string `json:"defaultPolicy" jsonschema:"enum=passthrough,enum=terminate"` // TODO: Add more policies. PolicyTimeout time.Duration `json:"policyTimeout" jsonschema:"oneof_type=string;integer"` + ActionTimeout time.Duration `json:"actionTimeout" jsonschema:"oneof_type=string;integer"` Policies []Policy `json:"policies"` } diff --git a/errors/errors.go b/errors/errors.go index f68124e4..70d9e975 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -148,6 +148,8 @@ var ( ErrCodeRunError, "error running action", nil) ErrAsyncAction = NewGatewayDError( ErrCodeAsyncAction, "async action", nil) + ErrRunningActionTimeout = NewGatewayDError( + ErrCodeRunError, "timeout running action", nil) ErrActionNotMatched = NewGatewayDError( ErrCodeKeyNotFound, "no matching action", nil) ErrPolicyNotMatched = NewGatewayDError( diff --git a/network/proxy_test.go b/network/proxy_test.go index e340fae2..c4f6afe0 100644 --- a/network/proxy_test.go +++ b/network/proxy_test.go @@ -47,7 +47,7 @@ func TestNewProxy(t *testing.T) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool proxy := NewProxy( @@ -93,7 +93,7 @@ func BenchmarkNewProxy(b *testing.B) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool for i := 0; i < b.N; i++ { @@ -142,7 +142,7 @@ func BenchmarkProxyConnectDisconnect(b *testing.B) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool proxy := NewProxy( @@ -197,7 +197,7 @@ func BenchmarkProxyPassThrough(b *testing.B) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool proxy := NewProxy( @@ -257,7 +257,7 @@ func BenchmarkProxyIsHealthyAndIsExhausted(b *testing.B) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool proxy := NewProxy( @@ -315,7 +315,7 @@ func BenchmarkProxyAvailableAndBusyConnections(b *testing.B) { // Create a new act registry actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) // Create a proxy with a fixed buffer newPool proxy := NewProxy( diff --git a/network/server_test.go b/network/server_test.go index 95658778..9cc55731 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -41,7 +41,7 @@ func TestRunServer(t *testing.T) { actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) pluginRegistry := plugin.NewRegistry( context.Background(), actRegistry, diff --git a/plugin/plugin_registry_test.go b/plugin/plugin_registry_test.go index ff8b911b..385745c5 100644 --- a/plugin/plugin_registry_test.go +++ b/plugin/plugin_registry_test.go @@ -28,7 +28,7 @@ func NewPluginRegistry(t *testing.T) *Registry { logger := logging.NewLogger(context.Background(), cfg) actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) reg := NewRegistry( context.Background(), actRegistry, @@ -130,7 +130,7 @@ func BenchmarkHookRun(b *testing.B) { logger := logging.NewLogger(context.Background(), cfg) actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger) + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger) reg := NewRegistry( context.Background(), actRegistry, diff --git a/plugin/utils_test.go b/plugin/utils_test.go index e123c8ad..46dadddb 100644 --- a/plugin/utils_test.go +++ b/plugin/utils_test.go @@ -92,7 +92,7 @@ func Test_applyPolicies(t *testing.T) { logger := zerolog.Logger{} actRegistry := act.NewActRegistry( act.BuiltinSignals(), act.BuiltinPolicies(), act.BuiltinActions(), - config.DefaultPolicy, config.DefaultPolicyTimeout, logger, + config.DefaultPolicy, config.DefaultPolicyTimeout, config.DefaultActionTimeout, logger, ) output := applyPolicies(