Skip to content

Commit

Permalink
add NonBlockingPhases mark to plugins
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Dec 2, 2024
1 parent 40c942c commit cd7d94a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
18 changes: 13 additions & 5 deletions types/plugins/demo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ func (p *Plugin) Order() plugins.PluginOrder {
}

// NonBlockingPhases returns the phases of the plugin which can be run non-blockingly, default to 0.
// If the plugin's filter doesn't contain any blocking operation, it should return true.
// If a phase except OnLog only contains non-blocking plugins, it will be executed synchorously, which is
// more effective.
// Phase OnLog is always be executed synchorously so we don't need to specify it here.
//
// If the plugin's filter in a specific phase doesn't contain any blocking operation, we can mark this phase
// as non-blocking phase.
// A blocking operation can be:
// 1. I/O operation
// 2. Sleep
// 3. Blocking syscall
// 4. Context switch like waiting on a channel
// and more.
//
// If a phase only contains non-blocking plugins, it will be executed synchorously, which is
// more effective.
// Marking phases with blocking operations as non-blocking can lead to unexpected delays in worker scope.
// We recommend marking as conservatively as possible, i.e.,
// only marking phases with simple code logic. For example, in HTNN we only marks
//
// Phase OnLog is always be executed synchorously so we don't need to specify it here.
// * PhaseDecodeData
// * PhaseEncodeHeaders
// * PhaseEncodeData
func (p *Plugin) NonBlockingPhases() api.Phase {
return api.PhaseDecodeHeaders | api.PhaseEncodeHeaders
return api.PhaseEncodeHeaders
}

// Config returns api.PluginConfig's implementation used during configuration processing
Expand Down
4 changes: 4 additions & 0 deletions types/plugins/limitcountredis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (p *Plugin) Order() plugins.PluginOrder {
}
}

func (p *Plugin) NonBlockingPhases() api.Phase {
return api.PhaseEncodeHeaders
}

func (p *Plugin) Config() api.PluginConfig {
return &CustomConfig{}
}
Expand Down
4 changes: 4 additions & 0 deletions types/plugins/oidc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (p *Plugin) Order() plugins.PluginOrder {
}
}

func (p *Plugin) NonBlockingPhases() api.Phase {
return api.PhaseEncodeHeaders
}

func (p *Plugin) Config() api.PluginConfig {
return &Config{}
}

0 comments on commit cd7d94a

Please sign in to comment.