Documentation
¶
Overview ¶
Package plugin provides dynamic plugin loading using Yaegi.
Package plugin provides dynamic plugin loading using Yaegi.
Package plugin provides dynamic plugin loading using Yaegi.
Package plugin provides dynamic plugin loading using Yaegi.
Index ¶
- Constants
- func GeneratePluginYAML(name, buildTime, gitVersion string) ([]byte, error)
- type LoadedPlugin
- func (p *LoadedPlugin) AddRunning()
- func (p *LoadedPlugin) AddScenario(name string)
- func (p *LoadedPlugin) CanCleanup() bool
- func (p *LoadedPlugin) GetDescription() string
- func (p *LoadedPlugin) GetName() string
- func (p *LoadedPlugin) GetRunningCount() int32
- func (p *LoadedPlugin) GetScenarioCount() int
- func (p *LoadedPlugin) IsCleanedUp() bool
- func (p *LoadedPlugin) MarkCleanedUp()
- func (p *LoadedPlugin) RemoveRunning()
- func (p *LoadedPlugin) RemoveScenario(name string)
- type PluginLoader
- func (l *PluginLoader) CleanupPlugin(plugin *LoadedPlugin) error
- func (l *PluginLoader) GetPluginRegistry() *PluginRegistry
- func (l *PluginLoader) GetScenarioRegistry() *scenario.Registry
- func (l *PluginLoader) LoadFromBytes(data []byte, compressed bool) (*LoadedPlugin, error)
- func (l *PluginLoader) LoadFromFile(filePath string) (*LoadedPlugin, error)
- func (l *PluginLoader) LoadFromLocalPath(localPath string) (*LoadedPlugin, error)
- func (l *PluginLoader) LoadFromReader(data io.Reader, compressed bool) (*LoadedPlugin, error)
- func (l *PluginLoader) LoadFromURL(url string) (*LoadedPlugin, error)
- func (l *PluginLoader) RegisterPluginScenarios(loaded *LoadedPlugin) error
- func (l *PluginLoader) SetCleanupCallback(fn func(*LoadedPlugin))
- func (l *PluginLoader) Shutdown()
- func (l *PluginLoader) UnregisterPluginScenarios(pluginName string) error
- type PluginMetadata
- type PluginRegistry
- func (r *PluginRegistry) Get(name string) *LoadedPlugin
- func (r *PluginRegistry) GetAll() []*LoadedPlugin
- func (r *PluginRegistry) GetDeprecated() []*LoadedPlugin
- func (r *PluginRegistry) Register(plugin *LoadedPlugin) *LoadedPlugin
- func (r *PluginRegistry) Remove(name string) *LoadedPlugin
- func (r *PluginRegistry) RemoveDeprecated(plugin *LoadedPlugin)
- type PluginSourceType
- type SymlinkFS
Constants ¶
const (
// PluginBasePath is the base path where plugins are mounted in the virtual GOPATH.
PluginBasePath = "src/github.com/ethpandaops/spamoor/plugins"
)
const (
// PluginMetadataFile is the name of the metadata file in plugin archives.
PluginMetadataFile = "plugin.yaml"
)
Variables ¶
This section is empty.
Functions ¶
func GeneratePluginYAML ¶
GeneratePluginYAML generates the content for a plugin.yaml file.
Types ¶
type LoadedPlugin ¶
type LoadedPlugin struct {
Descriptor *scenario.PluginDescriptor
Metadata *PluginMetadata // Metadata from plugin.yaml
TempDir string // Base temp directory
PluginPath string // Path to plugin source (for scenario Options.PluginPath)
SourceType PluginSourceType // How the plugin was loaded
// contains filtered or unexported fields
}
LoadedPlugin tracks a loaded plugin with its temp directory and reference counting. It implements scenario.ScenarioPlugin interface to allow use in the scenario registry.
func NewLoadedPlugin ¶
func NewLoadedPlugin( descriptor *scenario.PluginDescriptor, metadata *PluginMetadata, tempDir, pluginPath string, sourceType PluginSourceType, ) *LoadedPlugin
NewLoadedPlugin creates a new LoadedPlugin instance.
func (*LoadedPlugin) AddRunning ¶
func (p *LoadedPlugin) AddRunning()
AddRunning increments the running spammer count (implements scenario.ScenarioPlugin).
func (*LoadedPlugin) AddScenario ¶
func (p *LoadedPlugin) AddScenario(name string)
AddScenario marks a scenario name as registered from this plugin.
func (*LoadedPlugin) CanCleanup ¶
func (p *LoadedPlugin) CanCleanup() bool
CanCleanup returns true if the plugin can be cleaned up: all descriptors from this plugin have been replaced AND no running spammer uses them.
func (*LoadedPlugin) GetDescription ¶
func (p *LoadedPlugin) GetDescription() string
GetDescription returns the plugin description (implements scenario.ScenarioPlugin).
func (*LoadedPlugin) GetName ¶
func (p *LoadedPlugin) GetName() string
GetName returns the plugin name (implements scenario.ScenarioPlugin).
func (*LoadedPlugin) GetRunningCount ¶
func (p *LoadedPlugin) GetRunningCount() int32
GetRunningCount returns the number of running spammers using this plugin.
func (*LoadedPlugin) GetScenarioCount ¶
func (p *LoadedPlugin) GetScenarioCount() int
GetScenarioCount returns the number of scenarios still registered from this plugin.
func (*LoadedPlugin) IsCleanedUp ¶
func (p *LoadedPlugin) IsCleanedUp() bool
IsCleanedUp returns true if the plugin has already been cleaned up.
func (*LoadedPlugin) MarkCleanedUp ¶
func (p *LoadedPlugin) MarkCleanedUp()
MarkCleanedUp marks the plugin as cleaned up.
func (*LoadedPlugin) RemoveRunning ¶
func (p *LoadedPlugin) RemoveRunning()
RemoveRunning decrements the running spammer count (implements scenario.ScenarioPlugin).
func (*LoadedPlugin) RemoveScenario ¶
func (p *LoadedPlugin) RemoveScenario(name string)
RemoveScenario removes a scenario name from this plugin's tracking.
type PluginLoader ¶
type PluginLoader struct {
// contains filtered or unexported fields
}
PluginLoader handles loading plugins from various sources at runtime.
func NewPluginLoader ¶
func NewPluginLoader( logger logrus.FieldLogger, pluginRegistry *PluginRegistry, scenarioRegistry *scenario.Registry, ) *PluginLoader
NewPluginLoader creates a new plugin loader with the given registries.
func (*PluginLoader) CleanupPlugin ¶
func (l *PluginLoader) CleanupPlugin(plugin *LoadedPlugin) error
CleanupPlugin removes the temp directory for a plugin and removes it from the deprecated list.
func (*PluginLoader) GetPluginRegistry ¶
func (l *PluginLoader) GetPluginRegistry() *PluginRegistry
GetPluginRegistry returns the plugin registry.
func (*PluginLoader) GetScenarioRegistry ¶
func (l *PluginLoader) GetScenarioRegistry() *scenario.Registry
GetScenarioRegistry returns the scenario registry.
func (*PluginLoader) LoadFromBytes ¶
func (l *PluginLoader) LoadFromBytes(data []byte, compressed bool) (*LoadedPlugin, error)
LoadFromBytes loads a plugin from tar(.gz) bytes. The plugin name is determined from plugin.yaml inside the archive. If compressed is true, the data is treated as gzip-compressed.
func (*PluginLoader) LoadFromFile ¶
func (l *PluginLoader) LoadFromFile(filePath string) (*LoadedPlugin, error)
LoadFromFile loads a plugin from a tar(.gz) file path. The plugin name is determined from plugin.yaml inside the archive. Compression is auto-detected based on the .gz extension.
func (*PluginLoader) LoadFromLocalPath ¶
func (l *PluginLoader) LoadFromLocalPath(localPath string) (*LoadedPlugin, error)
LoadFromLocalPath loads a plugin from a local directory path. This creates a symlink in the temp directory to the local path. Local path plugins use the directory name as plugin name and spamoor's build info for version metadata (no plugin.yaml required).
func (*PluginLoader) LoadFromReader ¶
func (l *PluginLoader) LoadFromReader(data io.Reader, compressed bool) (*LoadedPlugin, error)
LoadFromReader loads a plugin from a tar(.gz) stream. It first extracts and parses plugin.yaml to get the plugin name, then extracts the full archive to the appropriate directory structure. If compressed is true, the stream is treated as gzip-compressed.
func (*PluginLoader) LoadFromURL ¶
func (l *PluginLoader) LoadFromURL(url string) (*LoadedPlugin, error)
LoadFromURL loads a plugin from a remote URL (tar.gz). The plugin name is determined from plugin.yaml inside the archive.
func (*PluginLoader) RegisterPluginScenarios ¶
func (l *PluginLoader) RegisterPluginScenarios(loaded *LoadedPlugin) error
RegisterPluginScenarios registers all scenarios from a loaded plugin.
func (*PluginLoader) SetCleanupCallback ¶
func (l *PluginLoader) SetCleanupCallback(fn func(*LoadedPlugin))
SetCleanupCallback sets a callback function to be called when a plugin may be ready for cleanup (e.g., when a scenario is replaced or unregistered).
func (*PluginLoader) Shutdown ¶
func (l *PluginLoader) Shutdown()
Shutdown cleans up all loaded plugins.
func (*PluginLoader) UnregisterPluginScenarios ¶
func (l *PluginLoader) UnregisterPluginScenarios(pluginName string) error
UnregisterPluginScenarios removes all scenarios from a plugin.
type PluginMetadata ¶
type PluginMetadata struct {
Name string `yaml:"name"`
BuildTime string `yaml:"build_time"`
GitVersion string `yaml:"git_version"`
}
PluginMetadata contains metadata about a plugin from plugin.yaml.
func NewLocalPluginMetadata ¶
func NewLocalPluginMetadata(dirName string) *PluginMetadata
NewLocalPluginMetadata creates metadata for a local path plugin using the directory name and spamoor's build info.
func ParsePluginMetadata ¶
func ParsePluginMetadata(data []byte) (*PluginMetadata, error)
ParsePluginMetadata parses plugin metadata from YAML bytes.
type PluginRegistry ¶
type PluginRegistry struct {
// contains filtered or unexported fields
}
PluginRegistry tracks all loaded plugins.
func NewPluginRegistry ¶
func NewPluginRegistry() *PluginRegistry
NewPluginRegistry creates a new PluginRegistry.
func (*PluginRegistry) Get ¶
func (r *PluginRegistry) Get(name string) *LoadedPlugin
Get retrieves a plugin by name.
func (*PluginRegistry) GetAll ¶
func (r *PluginRegistry) GetAll() []*LoadedPlugin
GetAll returns all loaded plugins.
func (*PluginRegistry) GetDeprecated ¶
func (r *PluginRegistry) GetDeprecated() []*LoadedPlugin
GetDeprecated returns all deprecated plugins still in use by running spammers.
func (*PluginRegistry) Register ¶
func (r *PluginRegistry) Register(plugin *LoadedPlugin) *LoadedPlugin
Register adds or replaces a plugin in the registry. Returns the old plugin if one was replaced. If the old plugin still has running spammers, it is tracked as deprecated.
func (*PluginRegistry) Remove ¶
func (r *PluginRegistry) Remove(name string) *LoadedPlugin
Remove removes a plugin from the registry and returns it.
func (*PluginRegistry) RemoveDeprecated ¶
func (r *PluginRegistry) RemoveDeprecated(plugin *LoadedPlugin)
RemoveDeprecated removes a plugin from the deprecated list.
type PluginSourceType ¶
type PluginSourceType int
PluginSourceType indicates how a plugin was loaded.
const ( // PluginSourceBytes indicates the plugin was loaded from raw bytes (e.g., tar.gz data). PluginSourceBytes PluginSourceType = iota // PluginSourceFile indicates the plugin was loaded from a tar.gz file path. PluginSourceFile // PluginSourceURL indicates the plugin was loaded from a remote URL. PluginSourceURL // PluginSourceLocal indicates the plugin was loaded from a local directory path. PluginSourceLocal )
func (PluginSourceType) String ¶
func (p PluginSourceType) String() string
String returns a string representation of the PluginSourceType.
type SymlinkFS ¶
type SymlinkFS struct {
// contains filtered or unexported fields
}
SymlinkFS implements fs.FS and fs.ReadDirFS while following symlinks. This is used for local plugin paths that may be symlinked.
func NewSymlinkFS ¶
NewSymlinkFS creates a new SymlinkFS rooted at the given base path.