Skip to content

Commit

Permalink
Remove acceptance policy (#445)
Browse files Browse the repository at this point in the history
* Remove acceptance policy
* Remove comment
  • Loading branch information
mostafa authored Feb 18, 2024
1 parent 78c7c7b commit a37fa63
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 263 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
export SHA256SUM=$(sha256sum ptg | awk '{print $1}')
cat <<EOF > gatewayd_plugins.yaml
compatibilityPolicy: "strict"
acceptancePolicy: "accept"
terminationPolicy: "stop"
metricsMergerPeriod: 1s
healthCheckPeriod: 1s
Expand Down
3 changes: 0 additions & 3 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func TestGetPlugins(t *testing.T) {
pluginRegistry := plugin.NewRegistry(
context.TODO(),
config.Loose,
config.Accept,
config.Stop,
zerolog.Logger{},
true,
Expand All @@ -135,7 +134,6 @@ func TestGetPluginsWithEmptyPluginRegistry(t *testing.T) {
pluginRegistry := plugin.NewRegistry(
context.TODO(),
config.Loose,
config.Accept,
config.Stop,
zerolog.Logger{},
true,
Expand Down Expand Up @@ -241,7 +239,6 @@ func TestGetServers(t *testing.T) {
pluginRegistry := plugin.NewRegistry(
context.TODO(),
config.Loose,
config.Accept,
config.Stop,
zerolog.Logger{},
true,
Expand Down
401 changes: 200 additions & 201 deletions api/v1/api.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/v1/api.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/v1/api.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ var runCmd = &cobra.Command{
config.CompatibilityPolicies, conf.Plugin.CompatibilityPolicy),
config.CompatibilityPolicies[conf.Plugin.CompatibilityPolicy],
config.DefaultCompatibilityPolicy),
config.If[config.AcceptancePolicy](
config.Exists[string, config.AcceptancePolicy](
config.AcceptancePolicies, conf.Plugin.AcceptancePolicy),
config.AcceptancePolicies[conf.Plugin.AcceptancePolicy],
config.DefaultAcceptancePolicy),
config.If[config.TerminationPolicy](
config.Exists[string, config.TerminationPolicy](
config.TerminationPolicies, conf.Plugin.TerminationPolicy),
Expand Down
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func (c *Config) LoadDefaults(ctx context.Context) {

c.pluginDefaults = PluginConfig{
CompatibilityPolicy: string(Strict),
AcceptancePolicy: string(Accept),
TerminationPolicy: string(Stop),
EnableMetricsMerger: true,
MetricsMergerPeriod: DefaultMetricsMergerPeriod,
Expand Down
8 changes: 0 additions & 8 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
type (
Status uint
CompatibilityPolicy string
AcceptancePolicy string
TerminationPolicy string
LogOutput uint
)
Expand All @@ -24,12 +23,6 @@ const (
Loose CompatibilityPolicy = "loose" // Load the plugin, even if the requirements are not met
)

// AcceptancePolicy is the acceptance policy for custom hooks.
const (
Accept AcceptancePolicy = "accept" // Accept all custom hooks
Reject AcceptancePolicy = "reject" // Reject all custom hooks
)

// TerminationPolicy is the termination policy for
// the functions registered to the OnTrafficFromClient hook.
const (
Expand Down Expand Up @@ -136,6 +129,5 @@ const (

// Policies.
DefaultCompatibilityPolicy = Strict
DefaultAcceptancePolicy = Accept
DefaultTerminationPolicy = Stop
)
4 changes: 0 additions & 4 deletions config/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ var (
"strict": Strict,
"loose": Loose,
}
AcceptancePolicies = map[string]AcceptancePolicy{
"accept": Accept,
"reject": Reject,
}
TerminationPolicies = map[string]TerminationPolicy{
"continue": Continue,
"stop": Stop,
Expand Down
1 change: 0 additions & 1 deletion config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Plugin struct {

type PluginConfig struct {
CompatibilityPolicy string `json:"compatibilityPolicy" jsonschema:"enum=strict,enum=loose"`
AcceptancePolicy string `json:"acceptancePolicy" jsonschema:"enum=accept,enum=reject"`
TerminationPolicy string `json:"terminationPolicy" jsonschema:"enum=continue,enum=stop"`
EnableMetricsMerger bool `json:"enableMetricsMerger"`
MetricsMergerPeriod time.Duration `json:"metricsMergerPeriod" jsonschema:"oneof_type=string;integer"`
Expand Down
6 changes: 0 additions & 6 deletions gatewayd_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
# plugin and that version is not the one currently loaded.
compatibilityPolicy: "strict"

# The acceptance policy controls how new dynamic hooks are handled. If a plugin registers a
# new hook, the acceptance policy controls whether to accept or reject the new hook.
# - "accept" (default): the new hook is accepted and registered.
# - "reject": the new hook is rejected and not registered.
acceptancePolicy: "accept"

# The termination policy controls how to handle the termination of requests. If a plugin
# terminates a request, the termination policy controls whether to stop executing the
# remaining plugins or not. If the termination policy is set to "stop", the remaining plugins
Expand Down
6 changes: 0 additions & 6 deletions network/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestNewProxy(t *testing.T) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -93,7 +92,6 @@ func BenchmarkNewProxy(b *testing.B) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -137,7 +135,6 @@ func BenchmarkProxyConnectDisconnect(b *testing.B) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -188,7 +185,6 @@ func BenchmarkProxyPassThrough(b *testing.B) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -244,7 +240,6 @@ func BenchmarkProxyIsHealthyAndIsExhausted(b *testing.B) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -298,7 +293,6 @@ func BenchmarkProxyAvailableAndBusyConnections(b *testing.B) {
plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down
1 change: 0 additions & 1 deletion network/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestRunServer(t *testing.T) {
pluginRegistry := plugin.NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down
24 changes: 2 additions & 22 deletions plugin/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type Registry struct {

Logger zerolog.Logger
Compatibility config.CompatibilityPolicy
Acceptance config.AcceptancePolicy
Termination config.TerminationPolicy
StartTimeout time.Duration
}
Expand All @@ -71,7 +70,6 @@ var _ IRegistry = (*Registry)(nil)
func NewRegistry(
ctx context.Context,
compatibility config.CompatibilityPolicy,
acceptance config.AcceptancePolicy,
termination config.TerminationPolicy,
logger zerolog.Logger,
devMode bool,
Expand All @@ -86,7 +84,6 @@ func NewRegistry(
devMode: devMode,
Logger: logger,
Compatibility: compatibility,
Acceptance: acceptance,
Termination: termination,
}
}
Expand Down Expand Up @@ -663,26 +660,9 @@ func (reg *Registry) RegisterHooks(ctx context.Context, pluginID sdkPlugin.Ident
hookMethod = pluginV1.OnShutdown
case v1.HookName_HOOK_NAME_ON_TICK:
hookMethod = pluginV1.OnTick
case v1.HookName_HOOK_NAME_ON_HOOK: // fallthrough
case v1.HookName_HOOK_NAME_ON_HOOK:
hookMethod = pluginV1.OnHook
default:
switch reg.Acceptance {
case config.Reject:
reg.Logger.Warn().Fields(map[string]interface{}{
"hook": hookName.String(),
"priority": pluginImpl.Priority,
"name": pluginImpl.ID.Name,
}).Msg("Unknown hook, skipping")
case config.Accept: // fallthrough
default:
// Default is to accept custom hooks.
reg.Logger.Debug().Fields(map[string]interface{}{
"hook": hookName.String(),
"priority": pluginImpl.Priority,
"name": pluginImpl.ID.Name,
}).Msg("Registering a custom hook")
metrics.PluginHooksRegistered.Inc()
reg.AddHook(hookName, pluginImpl.Priority, pluginV1.OnHook)
}
continue
}

Expand Down
2 changes: 0 additions & 2 deletions plugin/plugin_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func NewPluginRegistry(t *testing.T) *Registry {
reg := NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down Expand Up @@ -128,7 +127,6 @@ func BenchmarkHookRun(b *testing.B) {
reg := NewRegistry(
context.Background(),
config.Loose,
config.Accept,
config.Stop,
logger,
false,
Expand Down

0 comments on commit a37fa63

Please sign in to comment.